Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tIYUm-00F2vu-Tr for pgsql-general@arkaria.postgresql.org; Tue, 03 Dec 2024 19:23:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tIYUk-00CMMg-AA for pgsql-general@arkaria.postgresql.org; Tue, 03 Dec 2024 19:23:39 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tIYUi-00CMMY-K6 for pgsql-general@lists.postgresql.org; Tue, 03 Dec 2024 19:23:39 +0000 Received: from fout-b7-smtp.messagingengine.com ([202.12.124.150]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tIYUb-000sb0-30 for pgsql-general@lists.postgresql.org; Tue, 03 Dec 2024 19:23:37 +0000 Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfout.stl.internal (Postfix) with ESMTP id A360F1140145; Tue, 3 Dec 2024 14:23:26 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Tue, 03 Dec 2024 14:23:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1733253806; x=1733340206; bh=oiNiynEo7vKnfLAPcpuNIJBWamRLF38Z21hDp7PoumA=; b= kqDuX5IVq1XGrnIcEc8AkbB9GuzysDSIEKNH58KQ1TIlocSLp4VLgHT0MzH1pTBN Xnhn94W55tXwk4Wt96OzoXhyEMZtEZJTqE0Q/vxzaXUnPGI2sGP5AO4/Xr5ug5OX b/c/iEmdnjnqpr29F5KlWbsWPZKZJmaTe0lY1adf0YRDMrByfQFqRo/AEfgpcOPQ GsP7pRFgjYaOv5NYKwjdDjDURtM7S7zFOnJA4If6xaFNvtODWQzj5G9woGZJQxH9 06VR0BynrruURMzPhYp9VgWM2N80lF82FKTgCQY+JD0Gpk5UOHlI/BpwrSTT9QME H1wU4OJWkLW/rcQt32e6Eg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1733253806; x=1733340206; bh=o iNiynEo7vKnfLAPcpuNIJBWamRLF38Z21hDp7PoumA=; b=GjE3V97rDv/ih3+iK MgPeMEzyuOQpNarNQpYp8PVvMWAhkYw6b3Ut6A0235KMTs8UatENZEj7bZUFkxBF P5adfXDNGQClLHIM7PHBHYRkOLQi3tHkGJflEjNOPy+nySgcmvilYgBc4Fs/GQVM aMKjsTgXEM6T9wUzVPoTBlhfrjeKMDL2ZCakMpKdM5QqzFIFLsLxo5j0bBxa3FhR DrOuVHjNDiM1wFkGUAx5FZaxEotEpgql4LexzZ6Ymcw2oCKCgs420bmzA9J0G5SP o45qu5WhALS0etsCo9AGjSaZ6spqmh95Ppe2DBvPar6+xFiYVsiAvlhXHe37LlaA hJvDw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrieefgdelhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpefkffggfgfuvfhfhfgjtgfgsehtkeertddtvdejnecu hfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrg hklhgrvhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepteduvdelfeetueehvdekteet ieetieduhffhhedtheehlefftdeugeduteduvedvnecuffhomhgrihhnpehpohhsthhgrh gvshhqlhdrohhrghdpuhhrlhguvghfvghnshgvrdgtohhmnecuvehluhhsthgvrhfuihii vgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrg hklhgrvhgvrhdrtghomhdpnhgspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhht pdhrtghpthhtohepmhhitghhrggvlhdrjhdrthgvfhhfthesshhnrghpohhnrdgtohhmpd hrtghpthhtohepphhgshhqlhdqghgvnhgvrhgrlheslhhishhtshdrphhoshhtghhrvghs qhhlrdhorhhg X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 3 Dec 2024 14:23:24 -0500 (EST) Message-ID: <80f60c4c-aeec-46f0-9b8e-81a5aace1ffa@aklaver.com> Date: Tue, 3 Dec 2024 11:23:22 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Autovacuum and visibility maps To: "Tefft, Michael J" , "pgsql-general@lists.postgresql.org" References: <341dd184-9096-4d1f-a74c-7db02cd1004c@aklaver.com> Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 12/3/24 10:11 AM, Tefft, Michael J wrote: > Thanks for the point about truncates versus deletes. > > But most of these partitions have over 100k rows, all inserted at once. > We have the default setting: > > #autovacuum_vacuum_insert_threshold = 1000      # min number of row inserts > > So I thought we should be triggering by inserts. From your OP I took the following literally: "... a single insert-select". Take a look at the stat table below: https://www.postgresql.org/docs/current/monitoring-stats.html#MONITORING-PG-STAT-ALL-TABLES-VIEW pg_stat_all_tables For given table and see what the *autovacuum* fields return. You can use the function below to see if there are per table settings that are overriding the postgresql.conf settings. https://www.postgresql.org/docs/current/functions-info.html pg_options_to_table() Something like: select pg_options_to_table(reloptions) from pg_class where relname = 'some_table'; > > Mike > > *From:*Adrian Klaver > *Sent:* Tuesday, December 3, 2024 11:57 AM > *To:* Tefft, Michael J ; > pgsql-general@lists.postgresql.org > *Subject:* Re: Autovacuum and visibility maps > > On 12/3/24 08: 32, Tefft, Michael J wrote: > We have some batch queries > that had occasionally having degraded > runtimes: from 2 hours degrading > to 16 hours, etc. > > Comparing plans from good and bad runs, we saw > that the good plans > > On 12/3/24 08:32, Tefft, Michael J wrote: > >> We have some batch queries that had occasionally having degraded > >> runtimes: from 2 hours degrading to 16 hours, etc. > >> > >> Comparing plans from good and bad runs, we saw that the good plans used > >> index-only scans on table “x”, while the bad plans used index scans. > >> > >> Using the pg_visibility utility, we found that all of the 83 partitions > >> of table “x” were showing zero blocks where all tuples were visible. We > >> ran a VACUUM on the table; the visibility maps are now clean and the > >> good plans came back. > >> > >> Our question is: why did autovacuum not spare us from this? > >> > >> We are using default autovacuum parameters for all except > >> log_autovacuum_min_duration=5000. These partitions are populated by > >> processes that do a truncate + a single insert-select. > >> > >> We see autovacuum failure (failed to get lock) messages, followed by a > >> success message, in the log for one of these partitions (the biggest > >> one) but even that partition showed zero blocks with all tuples visible. > >> > >> Are we wrong to expect autovacuum to clean up the visibility map? > > I have to believe it is due to this: > > https://urldefense.com/v3/__https://www.postgresql.org/docs/current/routine-vacuuming.html*VACUUM-FOR-SPACE-RECOVERY__;Iw!!Lf_9VycLqA!mGufXaOdGX6PdXSpHcIUnIF1pe8evFpE7r-l4vJVUcoY--jp8LtF-jWv8YicvFWegi1-_jyxJnNx3YBvbxQOracZSxzvbw$ > > "If you have a table whose entire contents are deleted on a periodic > > basis, consider doing it with TRUNCATE rather than using DELETE followed > > by VACUUM. TRUNCATE removes the entire content of the table immediately, > > without requiring a subsequent VACUUM or VACUUM FULL to reclaim the > > now-unused disk space. The disadvantage is that strict MVCC semantics > > are violated." > > Combined with this: > > https://urldefense.com/v3/__https://www.postgresql.org/docs/current/runtime-config-autovacuum.html*GUC-AUTOVACUUM-VACUUM-INSERT-THRESHOLD__;Iw!!Lf_9VycLqA!mGufXaOdGX6PdXSpHcIUnIF1pe8evFpE7r-l4vJVUcoY--jp8LtF-jWv8YicvFWegi1-_jyxJnNx3YBvbxQOraeerEd0yw$ > > "autovacuum_vacuum_threshold > > Specifies the minimum number of updated or deleted tuples needed to > > trigger a VACUUM in any one table. ... > > " > > I'm going to say the TRUNCATE itself does not trigger an autovacuum. I > > would suggest throwing a manual VACUUM in the table population script. > >> > >> postgres=# select version(); > >> > >>                                                   version > >> > >> ---------------------------------------------------------------------------------------------------------- > >> > >> PostgreSQL 14.13 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0 > >> 20210514 (Red Hat 8.5.0-22), 64-bit > >> > >> Thank you, > >> > >> Mike Tefft > >> > > -- > > Adrian Klaver > > adrian.klaver@aklaver.com > -- Adrian Klaver adrian.klaver@aklaver.com