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 1uM8N6-003N7i-80 for pgsql-hackers@arkaria.postgresql.org; Mon, 02 Jun 2025 16:50:49 +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 1uM8N4-00BMka-Nq for pgsql-hackers@arkaria.postgresql.org; Mon, 02 Jun 2025 16:50:46 +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 1uM8N4-00BMkS-AR for pgsql-hackers@lists.postgresql.org; Mon, 02 Jun 2025 16:50:46 +0000 Received: from mail.postgrespro.ru ([93.174.132.70]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uM8N1-00049v-0Q for pgsql-hackers@postgresql.org; Mon, 02 Jun 2025 16:50:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1748883042; bh=+3CFevEoC6xP709+P9ISYjite6jhqnXLVG2ssl8BWrg=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=YMs0e8S1lX+dYkBi+s3TvbqogRCg+AnDcCUKCIFchWbsveQyTEX+gNK4PAebrQLw1 whRR4QQqQ6G2ZSKDBS1IF4MkBadMzjmJUaAlnmaOngEGLjtxI6Mexdncp+1TVDXdSb 7anhwgRJ6Y2iaWf4YefbWYUwaP9H3flvroAng8vWEiGjoRwTjkwftWCmvD25HXa5Wx 2rYaXX/nDaLBPYc+A52Qs6uUfAw1bgxmKOXKXsh0h0RGPmoCneWK3gM+qsRzz9YXak sKbZzi+WM/918x8ZMvV+fnv0ZSxo3Yt0udeP/tWb5Kdd1rtS2H7E018S0eGllCinvC FRJneR62f9Esg== Received: from [10.4.12.74] (unknown [93.174.131.141]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: a.rybakina@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id 7BA016067B; Mon, 2 Jun 2025 19:50:42 +0300 (MSK) Message-ID: <9a94f2a0-4698-40e3-9010-2567d3b8ba55@postgrespro.ru> Date: Mon, 2 Jun 2025 19:50:42 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Vacuum statistics To: Alexander Korotkov Cc: Amit Kapila , pgsql-hackers , Jim Nasby , Bertrand Drouvot , Ilia Evdokimov , Kirill Reshke , Andrei Zubkov , Masahiko Sawada , Melanie Plageman , jian he , a.lepikhov@postgrespro.ru, Sami Imseih , vignesh C References: <86f76aa5-1ab5-4e2e-9b15-405051852a2a@postgrespro.ru> <1e81a0a1-a63b-48fb-905a-d6495f89ab73@postgrespro.ru> <0b4eefc7-4c38-4caa-b2ca-a4c75dd7dd12@postgrespro.ru> <333c2306-c401-4959-9f0c-a44c670a11a9@postgrespro.ru> <513f0188-b093-4cc8-98cf-4c324570d525@postgrespro.ru> <47a7b784-5218-43f2-96e3-65f9a729c5a5@tantorlabs.com> <5583261b-eede-4341-b3b1-91650fefc1cf@postgrespro.ru> <2a04ad18-5572-4633-848b-eb57209e7ac0@postgrespro.ru> <2f48399f-2959-4483-938f-64edb863ca76@postgrespro.ru> Content-Language: en-US From: Alena Rybakina In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-KSMG-AntiPhishing: NotDetected X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.1.0.7854, bases: 2025/06/02 15:24:00 #27532712 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: not scanned, disabled by settings X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 02.06.2025 19:25, Alexander Korotkov wrote: > On Tue, May 13, 2025 at 12:49 PM Alena Rybakina > wrote: >> On 12.05.2025 08:30, Amit Kapila wrote: >>> On Fri, May 9, 2025 at 5:34 PM Alena Rybakina wrote: >>>> I did a rebase and finished the part with storing statistics separately from the relation statistics - now it is possible to disable the collection of statistics for relationsh using gucs and >>>> this allows us to solve the problem with the memory consumed. >>>> >>> I think this patch is trying to collect data similar to what we do for >>> pg_stat_statements for SQL statements. So, can't we follow a similar >>> idea such that these additional statistics will be collected once some >>> external module like pg_stat_statements is enabled? That module should >>> be responsible for accumulating and resetting the data, so we won't >>> have this memory consumption issue. >> The idea is good, it will require one hook for the pgstat_report_vacuum >> function, the extvac_stats_start and extvac_stats_end functions can be >> run if the extension is loaded, so as not to add more hooks. > +1 > Nice idea of a hook. Given the volume of the patch, it might be a > good idea to keep this as an extension. Okay, I'll realize it and apply the patch) > >> But I see a problem here with tracking deleted objects for which >> statistics are no longer needed. There are two solutions to this and I >> don't like both of them, to be honest. >> The first way is to add a background process that will go through the >> table with saved statistics and check whether the relation or the >> database are relevant now or not and if not, then >> delete the vacuum statistics information for it. This may be >> resource-intensive. The second way is to add hooks for deleting the >> database and relationships (functions dropdb, index_drop, >> heap_drop_with_catalog). > Can we workaround this with object_access_hook? I think this could fix the problem. For the OAT-DROP access type, we can call a function to reset the vacuum statistics for relations that are about to be dropped. At the moment, I don’t see any limitations to using this approach. -- Regards, Alena Rybakina Postgres Professional