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 1wAalL-00079w-12 for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Apr 2026 21:48:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wAalI-002MIJ-0P for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Apr 2026 21:48:37 +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 1wAalH-002MIB-2j for pgsql-hackers@lists.postgresql.org; Wed, 08 Apr 2026 21:48:36 +0000 Received: from mail-oo1-xc33.google.com ([2607:f8b0:4864:20::c33]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wAalG-000000003mX-3Vi9 for pgsql-hackers@postgresql.org; Wed, 08 Apr 2026 21:48:35 +0000 Received: by mail-oo1-xc33.google.com with SMTP id 006d021491bc7-688ae78999bso102468eaf.3 for ; Wed, 08 Apr 2026 14:48:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775684914; x=1776289714; darn=postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=7RGPJ1TMDyAvCpgg0LS66kAXic1UmhYV6GD87tSZ7xU=; b=EXlzM3Hc4hX0vVzLV3issUjq7qk5myYMInj5OT5g6+gzS4sNYOBVOieVUyBO5HfvYl QHeEcEpdZOTOmqPJCg+4Va3SUiUugJ48ttGESUAt3hAU8VBq/vDXGP9tMOmTa/lrsBbs irLuBbrsi+EATqRcqLv8SevB99HrQdDigKVrZEa0Tqni0fIQe8WY4bErDeq/br/fvgwh CGF8B3SJuFLc7mE+61/YfJoqVcm4UKSWNL32KE0FnkPKN+0iNhp585hpyQ8U5AtegcRC pEVJ2X5ai8Xp8W7HKGFZMqAqqR71jddwvf5JeLdtnFPra2X7nd/UwdfzFdOHrxA3E6RO 9hDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775684914; x=1776289714; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7RGPJ1TMDyAvCpgg0LS66kAXic1UmhYV6GD87tSZ7xU=; b=Zj2wT8rUq6sXSrhcCdQ96fsGO8X09a7wtbs+fm1xmQ1ebEtkskCXoULmI7nywU3xxF 59IKlEMfTfwcH/94t+VvhrNDLQ4GKsuuBDWE3FyvYnR++4NOlmApJk+6AN16GsUIM5/U ivgwNoNKpvkm76UdToZ/YgUuri3GGR3V5MhEBKrL5PVSSHdYaFkSJGa8iQqGhmz4vX0m NnYTCt81tx6THzbQXVgW4kVMEkAhWV6KgXarH/BoXO/q7Kgkm/CW1keqAh6cAD03f25t YbxvsYdkcNMtgFStvOtrb1c4hANXRkz6gL7bn3y/XPhdzb2qAevx468gqoHBcbyrrzSY UjFg== X-Forwarded-Encrypted: i=1; AJvYcCV7//m57BlQ58aTUbbyGs+pfpZo5059ms9ADJIPCMeVdo1naiYw8scT802POsuwYYP9gblK1PImJdM9c7Gc@postgresql.org X-Gm-Message-State: AOJu0YxVpyLum/o+saWy4dImWFVJH7zN1s3zf5j0JQUN3jLNe/np/As2 iu/DH3nRhJeAC+mUvpF89STRfb8C39C7DLuVJ0//F808MMzc38M/5qV7h3yY8A== X-Gm-Gg: AeBDievj+tss6N7JKPp4AKyPVkv2PLm6Gke0Qd9ZaYfG/HLxz5wD4lvhMyw+qj7BUVJ qMfwMhwjfdp1TpoiRiG2CRu8OEW4zju5q0mJIvJTM7SrDgUgF8pC5WqSIMObfsOeDlfnXr17YbM AMHTQQDBDbeoKqW+MqummV6tfQl6vyHYrcTwep0Vv1lUA8ghx3lHvbcZcsvH7z4k9aq9J5JEPKS QptrTrtsW4EobTWcy4v4bpz6mpHDd0qq5msotdOvWNpO5CgWQNdwYNC87GmLVQKBbjaDF1n6UVI LBPkMYZgIY9F1ekKvtR1STOkaQdrHE8VK6ffPz5iZoOHOae//PQA9rPPLJrfEhKw2vhF5qLYJ8X p3Pv9OkiZFzqgq6Zt8bXV3K3FIZDF1yjNYyyOD7xxEGG1WlwScIJH6vfqgBiCE4LsnAB1rzV6f3 DOxJJi+OvrD5qtTbcrSLnJytxFNKJbIPdZAby9lg+jyPs5KdT02GhnkbHZPxBw2QAXKUqCbBWmk gSjzcz6wc4E+5UuVW7RnA== X-Received: by 2002:a05:6820:2223:b0:682:cac0:1ad6 with SMTP id 006d021491bc7-682cacf98c4mr10695617eaf.14.1775684914618; Wed, 08 Apr 2026 14:48:34 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-68597f6c7bdsm6135598eaf.3.2026.04.08.14.48.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Apr 2026 14:48:33 -0700 (PDT) Date: Wed, 8 Apr 2026 16:48:31 -0500 From: Nathan Bossart To: Sami Imseih Cc: Andres Freund , Tom Lane , Alexander Lakhin , Bharath Rupireddy , Robert Treat , satyanarlapuram@gmail.com, pgsql-hackers , tndrwang@gmail.com Subject: Re: Add pg_stat_autovacuum_priority Message-ID: 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=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Apr 08, 2026 at 04:33:00PM -0500, Sami Imseih 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). What's interesting is that I cannot reproduce similar >> usage with views like pg_stat_all_tables. If memory was not a concern, I >> think the "bool *may_free" idea would be fine. > > Instead of may_free, which is invasive, what about pgstat_fetch_entry_nocache > which can be called by 2 new APIs pgstat_fetch_stat_tabentry_nocache() and > pgstat_fetch_stat_tabentry_nocache_ext(). This way a caller that uses > these will be required to pfree? This might help avoid memory usage within a snapshot, but as Andres notes, this gets released automatically at the end of the transaction. For a database with 100K tables, here's what I see before calling the view: name | used_bytes ------------------------+------------ PgStat Shared Ref Hash | 8576 PgStat Shared Ref | 2960 PgStat Pending | 4712 (3 rows) After calling the view but before committing the transaction, I see this: name | used_bytes ------------------------+------------ PgStat Snapshot | 4194688 PgStat Shared Ref Hash | 4194688 PgStat Shared Ref | 8048240 PgStat Pending | 3064 (4 rows) And after committing, I see: name | used_bytes ------------------------+------------ PgStat Shared Ref Hash | 4194688 PgStat Shared Ref | 8048240 PgStat Pending | 360 (3 rows) -- nathan