Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eI8j3-0001zj-9w for pgsql-general@arkaria.postgresql.org; Fri, 24 Nov 2017 07:48:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eI8j1-0002c0-0A for pgsql-general@arkaria.postgresql.org; Fri, 24 Nov 2017 07:48:39 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eI8j0-0002br-MR for pgsql-general@lists.postgresql.org; Fri, 24 Nov 2017 07:48:38 +0000 Received: from mx1.mailbox.org ([80.241.60.212]) by makus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eI8id-0001eB-Us for pgsql-general@lists.postgresql.org; Fri, 24 Nov 2017 07:48:37 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.mailbox.org (Postfix) with ESMTPS id 411274785B; Fri, 24 Nov 2017 08:48:12 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by hefe.heinlein-support.de (hefe.heinlein-support.de [91.198.250.172]) (amavisd-new, port 10030) with ESMTP id pxcCIvFkAjA9; Fri, 24 Nov 2017 08:48:10 +0100 (CET) Message-ID: <1511507701.2469.5.camel@cybertec.at> Subject: Re: pg_total_relation_size accuracy guarantee From: Laurenz Albe To: Nikita , pgsql-general@lists.postgresql.org In-Reply-To: References: Organization: Cybertec Content-Type: text/plain; charset="UTF-8" Date: Fri, 24 Nov 2017 08:15:01 +0100 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Nikita wrote: > 1. pg_total_relation_size return predictable approximately correct table size (apart from some preallocation) without subsequent VACUUM/ANALYZE/anything call as long as I don't DELETE/UPDATE rows; > > 2. DROP/TRUNCATE table reclaim disc space without subsequent VACUUM; > > These assumptions are correct? Is it fixed in doc if so? Sort of, if you consider the source as documentation. Ad pg_total_relation_size: See the function definition in backend/utils/adt/dbsize.c and the functions that it calls, especially "calculate_relation_size": PostgreSQL uses the stat(2) system call to determine the actual size of the files on disk. Ad TRUNCATE (from backend/commands/tablecmds.c): /* * Need the full transaction-safe pushups. * * Create a new empty storage file for the relation, and assign it * as the relfilenode value. The old storage file is scheduled for * deletion at commit. */ Yours, Laurenz Albe