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.96) (envelope-from ) id 1wAaw3-0007HL-0B for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Apr 2026 21:59:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wAaw0-002OZ8-32 for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Apr 2026 21:59:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wAaw0-002OYx-0S for pgsql-hackers@lists.postgresql.org; Wed, 08 Apr 2026 21:59:41 +0000 Received: from fhigh-a3-smtp.messagingengine.com ([103.168.172.154]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wAavy-000000003qu-2jO2 for pgsql-hackers@postgresql.org; Wed, 08 Apr 2026 21:59:40 +0000 Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfhigh.phl.internal (Postfix) with ESMTP id A13241400154; Wed, 8 Apr 2026 17:59:37 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Wed, 08 Apr 2026 17:59:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc: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=fm2; t=1775685577; x=1775771977; bh=eqmyv+iVykL5wwphUd4ln2hDjD/eyZ36ug78l3zR7DI=; b= QsTLfj2Ud8Plt32aFzni1CthqdgWUU/ePnzhXAggRx0vfLn3lYR4vtZ1Pv4kn4gU nSh0y4CSIT6OB+YJiwv1leHEkvDuzYnK+2Cs4cfZCLpLRNjS3Z3fO9k1c/eLP4k5 9wzu+sHpgvKb2nJwlvRdu7dEOoN6wbLKB/dqZ6rn+Jaoh8DvkGelh+Kf8meZhm7D GbLS9P+50TLyOHdTMcGFDmtUUworj9NCdl4LPnro/3VTWDHqlENgxycHMpu2cX6P Y/On1PgwWmOuG44NDG0hm9OE3+iauJqlJXXjOUbH+kLOx+0j/5VxAGhxikiYno1D xHmMtGnmbHSH5mFMekd86w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=fm2; t=1775685577; x= 1775771977; bh=eqmyv+iVykL5wwphUd4ln2hDjD/eyZ36ug78l3zR7DI=; b=j 0V2VS8ZIqe8SSITki/N6gKz0dciZYRZL3VPtQ6Y5bLM5Enmvg/BK6HozhkorkzKk dosqDNCxrWPC1gYg5F3f6QUm7V3jHSw+lZAB+5vjmofM1XMmZq1bzq5QeqAosZcj MjCNq7shucSNNvXKALTj6if74e/HiNntYsrRnfOL1pRM+EQ8CrbOHN9IjCYguDGx mcWOfA5fIBJ406diQ6iF9oskx5ZtY1h+ZwXUSQoJLAWVqFdFcAVCbEIzNAD4nVtH 6H8oEgtKQSRwaKLFX48L2ZRBywRyh4d9/ASennFyDKYm9Rt+YF15NOFkjKWa40v1 I2oVYKp2ct6eBgUHAOIxQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgddvgeejudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpeffhffvvefukfhfgggtugfgjgestheksfdttddtjeenucfhrhhomheptehnughrvghs ucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrfgrth htvghrnheptdelledvgfejvdffieeukeefueelfffhgeffhffgffekveeuheeihefhiefg hfdvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprg hnughrvghssegrnhgrrhgriigvlhdruggvpdhnsggprhgtphhtthhopeelpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopegshhgrrhgrthhhrdhruhhpihhrvgguugihfhhorh hpohhsthhgrhgvshesghhmrghilhdrtghomhdprhgtphhtthhopegvgigtlhhushhiohhn sehgmhgrihhlrdgtohhmpdhrtghpthhtohepnhgrthhhrghnuggsohhsshgrrhhtsehgmh grihhlrdgtohhmpdhrtghpthhtohepshgrmhhimhhsvghihhesghhmrghilhdrtghomhdp rhgtphhtthhopehsrghthigrnhgrrhhlrghpuhhrrghmsehgmhgrihhlrdgtohhmpdhrtg hpthhtohepthhnughrfigrnhhgsehgmhgrihhlrdgtohhmpdhrtghpthhtohepphhgshhq lhdqhhgrtghkvghrshesphhoshhtghhrvghsqhhlrdhorhhgpdhrtghpthhtohepthhglh esshhsshdrphhghhdrphgrrdhushdprhgtphhtthhopehrohgsseigiihilhhlrgdrnhgv th X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 8 Apr 2026 17:59:37 -0400 (EDT) Date: Wed, 8 Apr 2026 17:59:36 -0400 From: Andres Freund To: Nathan Bossart Cc: Tom Lane , Alexander Lakhin , Sami Imseih , Bharath Rupireddy , Robert Treat , satyanarlapuram@gmail.com, pgsql-hackers , tndrwang@gmail.com Subject: Re: Add pg_stat_autovacuum_priority Message-ID: <3nob5fjwrar3shffl5yo7im4qlnxxa475pi6fohemodsvwpl5g@l5cbmz5dqtjm> References: <5684f479-858e-4c5d-b8f5-bcf05de1f909@gmail.com> <3077290.1775668665@sss.pgh.pa.us> <3097984.1775674400@sss.pgh.pa.us> <3101163.1775676098@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2026-04-08 16:23:45 -0500, Nathan Bossart wrote: > On Wed, Apr 08, 2026 at 04:40:03PM -0400, Andres Freund wrote: > > Note that the whole cached state does automatically get reset at the end of > > the transaction (AtEOXact_PgStat()->pgstat_clear_snapshot()), just like it did > > before the shmem stats stuff. > > I see a lot of memory used for the pgStatEntryRefHash table, too (e.g., ~16 > MB for 100K tables). That's not the stats snapshot data. That's basically a semi-permanent pin on the shared stats entry so that we don't continually need to do lookups in the shared stats hash table. Without that you'd have a *lot* of contention on the shared hash table and the DSA for the stats entries themselves. That's right now just the price you pay for accessing and generating stats. It was way more before shared memory stats (as in a factor of 10 or so, and it was happening way more often and it caused the full database's stats worth of memory usage even if you just accessed a portion of the stats). It's possible that we could more frequently clean out references, but when to precisely do that and to how much is not a trivial problem - we haven't tackled it for our catcache/relcaches either. I don't think it should be quite 16MB for 100k tables though? I see ┌────────────────────────┬────────────────┐ │ name │ pg_size_pretty │ ├────────────────────────┼────────────────┤ │ PgStat Shared Ref │ 8104 kB │ │ PgStat Shared Ref Hash │ 4097 kB │ │ CacheMemoryContext │ 1024 kB │ └────────────────────────┴────────────────┘ after doing SELECT sum(score) FROM pg_stat_autovacuum_scores; in this database: SELECT relkind, count(*) FROM pg_class GROUP BY relkind; ┌─────────┬────────┐ │ relkind │ count │ ├─────────┼────────┤ │ S │ 1 │ │ i │ 182 │ │ r │ 102292 │ │ t │ 43 │ │ v │ 167 │ └─────────┴────────┘ (5 rows) > What's interesting is that I cannot reproduce similar usage with views like > pg_stat_all_tables. Hm? That would be very surprising. Is it possible you used LIMIT 1 or such? The way the pg_stat_all_tables view works it only accesses stats data for returned rows (because it does all the stats lookups with individiual columns, which also makes it really slow, but avoids having to form datums for not returned columns). in a new session: postgres[3109075][1]=# SELECT sum(seq_tup_read) FROM pg_stat_all_tables LIMIT 10; ┌────────────┐ │ sum │ ├────────────┤ │ 3223043706 │ └────────────┘ (1 row) Time: 723.223 ms postgres[3109075][1]=# SELECT name, pg_size_pretty(total_bytes) FROM pg_backend_memory_contexts ORDER BY total_bytes DESC LIMIT 3; ┌────────────────────────┬────────────────┐ │ name │ pg_size_pretty │ ├────────────────────────┼────────────────┤ │ PgStat Shared Ref │ 8104 kB │ │ PgStat Shared Ref Hash │ 4097 kB │ │ CacheMemoryContext │ 1024 kB │ └────────────────────────┴────────────────┘ I.e. byte for byte identical to the av case. > If memory was not a concern, I think the "bool *may_free" idea would be > fine. But assuming it is, we will probably need to do something more > creative. I don't think you're going to be able to quickly do anything about this. I think this is a completely independent issue of the *may_free thing. Greetings, Andres Freund