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 1tIWDP-00EqBb-OP for pgsql-general@arkaria.postgresql.org; Tue, 03 Dec 2024 16:57:36 +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 1tIWDN-00BJNu-7p for pgsql-general@arkaria.postgresql.org; Tue, 03 Dec 2024 16:57:34 +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 1tIWDM-00BJNm-AF for pgsql-general@lists.postgresql.org; Tue, 03 Dec 2024 16:57:34 +0000 Received: from fout-a2-smtp.messagingengine.com ([103.168.172.145]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tIWDJ-000rQv-E6 for pgsql-general@lists.postgresql.org; Tue, 03 Dec 2024 16:57:32 +0000 Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfout.phl.internal (Postfix) with ESMTP id 3A1A91380733; Tue, 3 Dec 2024 11:57:28 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-12.internal (MEProxy); Tue, 03 Dec 2024 11:57:28 -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=1733245048; x=1733331448; bh=UsQM4h3vvGsPJ9bIyxzZ38lyDVNI0t9Uy/kd1zdnIQI=; b= SrpzkW2D/rRHY+ziYyB32/0qFeTfjxP4xwiSIudiGec7tZDGk41vQFY+TJIorj1w Qy+T8BW/Yay5hrlJlaT0TkQ+c0mEjBdP7bI721Fx/SXWP3bDtTuUMb0pGxxakeS5 yQUn+Ij9g2ARFVuOdtWiM5sB/YHuaQ3JgVmAA4JQ1L64weBMqtQuxORZDSZfk2c8 z0K66V5Peiqcc2SHSPONvUKk1mqdoE5ACG1gdNNCvfhnyom9opbadahCC4m/ps3G gHP/vPoVKyF3O46s82amaseM5SB9ZV577FxNDsNqoLrp5GKyTSOIe7GkgQI9rAT8 NJOdCE0qwpz+uChPvNHPXA== 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=1733245048; x=1733331448; bh=U sQM4h3vvGsPJ9bIyxzZ38lyDVNI0t9Uy/kd1zdnIQI=; b=1kJiGRaeElTwCCplc IknuUq35dPPLlaApfP7XsifFJ7CpGzlZ6284lTDSwd3AQCjz9EpMp5W/8lF7a23D LxHsbABAddBZsNMGWqH+u+6XljCqpc25/75iX3/jr8ktzUU1XaKzIq8UBRGHWjS3 Xx19yco+aNTYdJ0Ci0g3adIWZS9lqijxL7ttFnyjdqqZCXTO3kPrhFF46ZalzfJ1 4c0U+XUCBpgRM/YS4IdOqQQ0ViNXixf0qo69uCTXpZSneitBMFEcxH2W1U2ON0dR MgmpaXr0fgcnRk1KsligPkoYU+BPqcJXRLMH/n3ftsLMO+tcg0MDX1zwpXjDTjV+ 92OUA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrieefgdeihecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpefkffggfgfuvfhfhfgjtgfgsehtkeertddtvdejnecu hfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrg hklhgrvhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepleegveekkeekueeigfdtveei leeuhfefudefteekjeffkeejueejheegheegkedtnecuffhomhgrihhnpehpohhsthhgrh gvshhqlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhl fhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmpdhnsggprh gtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehmihgthhgrvghl rdhjrdhtvghffhhtsehsnhgrphhonhdrtghomhdprhgtphhtthhopehpghhsqhhlqdhgvg hnvghrrghlsehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 3 Dec 2024 11:57:27 -0500 (EST) Message-ID: <341dd184-9096-4d1f-a74c-7db02cd1004c@aklaver.com> Date: Tue, 3 Dec 2024 08:57:26 -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: 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 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://www.postgresql.org/docs/current/routine-vacuuming.html#VACUUM-FOR-SPACE-RECOVERY "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://www.postgresql.org/docs/current/runtime-config-autovacuum.html#GUC-AUTOVACUUM-VACUUM-INSERT-THRESHOLD "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