Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eMEPA-0006YG-8U for pgsql-performance@arkaria.postgresql.org; Tue, 05 Dec 2017 14:41:04 +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 1eMEP9-0008OM-9s for pgsql-performance@arkaria.postgresql.org; Tue, 05 Dec 2017 14:41:03 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eMEP9-0008OB-35 for pgsql-performance@lists.postgresql.org; Tue, 05 Dec 2017 14:41:03 +0000 Received: from mx2.mailbox.org ([80.241.60.215]) by magus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eMEP5-0002R9-Ia for pgsql-performance@postgresql.org; Tue, 05 Dec 2017 14:41:02 +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 mx2.mailbox.org (Postfix) with ESMTPS id 5B3804C99B; Tue, 5 Dec 2017 15:40:57 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter02.heinlein-hosting.de (spamfilter02.heinlein-hosting.de [80.241.56.116]) (amavisd-new, port 10030) with ESMTP id XDtwv-rCEElT; Tue, 5 Dec 2017 15:40:56 +0100 (CET) Message-ID: <1512484854.2706.3.camel@cybertec.at> Subject: Re: vacuum after truncate From: Laurenz Albe To: Mariel Cherkassky , PostgreSQL mailing lists Date: Tue, 05 Dec 2017 15:40:54 +0100 In-Reply-To: References: Organization: Cybertec Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Mariel Cherkassky wrote: > Hi, > I have a big function that includes many truncates on different tables. > In the documentation is is written that truncates creates a new file > and resign the old filenode to the new filenode and the old file > (old data of the table) is deleted in commit. > > In order to execute my function I run psql -d 'aa' -U 'bb' -C "select function()"; > > I have a few questions about it ? > > 1.When I start the function, it means that the whole function is one big transaction right ? Right. > 2..Because the truncates I preform are part of a transaction it means that only at the end > of the transaction that space will be freed ? Which mean only when the function is finished? Exactly. The old file has to be retained, because there could be a ROLLBACK. > 3..Does running vacuum at the end of the function on the tables that were truncated and > then populated with data will have any impact or is it better just to analyze them ? For up-to-date statistics, ANALYZE is enough. If you want to set hint bits so that the first reader doesn't have to do it, VACUUM will help. But that is not necessary. Yours, Laurenz Albe