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 1tV6Bm-005RCH-Uz for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Jan 2025 09:47:55 +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 1tV6Bm-001rNs-E8 for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Jan 2025 09:47:54 +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.94.2) (envelope-from ) id 1tV6Bm-001rNj-2e for pgsql-hackers@lists.postgresql.org; Tue, 07 Jan 2025 09:47:53 +0000 Received: from mailfr00.databene.net ([31.170.12.19]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tV6Bj-000JCX-04 for pgsql-hackers@postgresql.org; Tue, 07 Jan 2025 09:47:52 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mailfr00.databene.net (Postfix) with ESMTP id 5DF8C5F2CC; Tue, 7 Jan 2025 10:47:48 +0100 (CET) X-Virus-Scanned: by Amavis at mailfr00.databene.net Received: from mailfr00.databene.net ([127.0.0.1]) by localhost (databene-mailfr00.evolix.net [127.0.0.1]) (amavis, port 10024) with LMTP id qlEWgKgZb-T5; Tue, 7 Jan 2025 10:47:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=data-bene.io; s=2024; t=1736243263; bh=xy/D5u8VLb60JaxsM6nzOEbh0S+hEb/znsOoNgJZHns=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=zX79KVd1065kpJKDkUVF4fS0pzjWN6iLKEP96UdkrxUKCm/rs/kGNHhLVR5ylqaRQ CEf/rai39A3DW+2AsODDD6VhT/xkZnqRZHJN8urTsAvFChZCF9zn2zsY/PfqXgxrrE /Bc/rOnGvPyz4YKLlLi5rlLc5qr6r72bb1TyHq80K+xWEDN5EEdrE32NH7KhsZVmcl bmZkaGC0IqPLNEon/HPricn7VAcwP3ym9c+wHJ2BrzjCw4YXwDpTxgbMMpoOM3mfBj Ah6WumZ0lwHGzWqQiShAP5nOpxhaZZmzD6KBWo566R8stKyBmKzNtEYlr3CNV2oREx gYCzQ+UPhpiqcT2nad79qpGJwVp5Ue7xKKvcT0bqCNNgmG7khhePac8eIqYkUnnK24 LkS49FZQYUOFyUY3O/S3mLn65231oTLzpz1jbRzHPKBYc/Bpdymov+Yl2xjFHYNnIa vm3qU7Yx2d3ZVAw0O5LFsGDAK8p9avtYg3uy/yi3pfi9VWHP2yv1/sALjc4KmQHaUR dPSSPv9eJ74Dh2woDIwKlNIiWw2DFR5RFuEShHtd0AqiN0enXCs1Pa6n0g3uqlGevJ pJOyD8Cuv+5pqYbRVNEjGUnVXcV5b3JXU9B2uIO/e+3gy2NGo0e1JwouXXSJbhMuvc ifh9z/UPn3oTRbgyQG+XOj60= Received: from [192.168.10.108] (257400053.box.freepro.com [95.178.90.96]) by mailfr00.databene.net (Postfix) with ESMTPSA id BF17E5F28D; Tue, 7 Jan 2025 10:47:43 +0100 (CET) Message-ID: Date: Tue, 7 Jan 2025 10:47:42 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: PoC: history of recent vacuum/checkpoint runs (using new hooks) To: Tomas Vondra , Michael Paquier Cc: wenhui qiu , Robert Treat , PostgreSQL Hackers References: <8df7cee1-31aa-4db3-bbb7-83157ca139da@vondra.me> <00d42567-22bd-4ed2-b190-188e9c151e28@vondra.me> <7be212d2-6212-4878-b439-b141ecba2acb@vondra.me> Content-Language: en-US From: =?UTF-8?Q?C=C3=A9dric_Villemain?= Organization: Data Bene In-Reply-To: <7be212d2-6212-4878-b439-b141ecba2acb@vondra.me> 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 31/12/2024 16:06, Tomas Vondra wrote: > On 12/31/24 02:06, Michael Paquier wrote: >> On Sat, Dec 28, 2024 at 02:25:16AM +0100, Tomas Vondra wrote: >>> And the more I think about it the more I'm convinced we don't need to >>> keep the data about past runs in memory, a file should be enough (except >>> maybe for a small buffer). That would mean we don't need to worry about >>> dynamic shared memory, etc. I initially rejected this because it seemed >>> like a regression to how pgstat worked initially (sharing data through >>> files), but I don't think that's actually true - this data is different >>> (almost append-only), etc. >> Right, I was looking a bit at 0003 that introduces the extension. I >> am wondering if we are not repeating the errors of pgss by using a >> different file, and if we should not just use pgstats and its single >> file instead to store this data through an extension. You are right >> that as an append-only pattern using the dshash of pgstat does not fit >> well into this picture. How about the second type of stats kinds: >> the fixed-numbered stats kind? These allocate a fixed amount of >> shared memory, meaning that you could allocate N entries of history >> and just manage a queue of them, then do a memcpy() of the whole set >> if adding new history at the head of the queue, or just append new >> ones at the tail of the queue in shmem, memcpy() once the queue is >> full. The extension gets simpler: >> - No need to manage a new file, flush of the stats is controlled by >> pgstats itself. >> - The extension could register a fixed-numbered custom stats kind. > > I'm not against leveraging some of the existing pstat infrastructure, > but as I explained earlier I don't like the "fixed amount of shmem" > approach. It's either wasteful (on machines with few vacuum runs) or > difficult to configure to keep enough history. A bit late on this topic, I wrote StatsMgr which run stats snapshots based on interval, it covers only fixed stats at the moment though, it's ring buffer too, not perfect but does the job. It has many similarities and I though it'll be interesting to share what I was looking at to improve further. I think it'll be interesting to have 2 hooks in PgStat_KindInfo functions call back: * "flush_fixed_cb()": a hook inside to be able to execute other action while flushing, like generating aggregates ("counter summary") * a new member to do the snapshot directly (or whatever action relevant when the stats are in an interesting state), maybe snapshot_fixed_cb(), with a hook inside. This way, with 2 hooks we can cover both usages, for all stats (fixed here, but probably the same hooks for variable stats), and have actions on events instead of only on time interval. I don't have strict opinion about files management but having a facility from PostgreSQL to store *metrics* (as opposed to "stats" which are required for PostgreSQL) will be very convenient. Maybe like SLRU or similar (the thing used to keep commits timestamp) ? I didn't checked all already available options in this area. [1] https://codeberg.org/Data-Bene/StatsMgr --- Cédric Villemain +33 6 20 30 22 52 https://www.Data-Bene.io PostgreSQL Support, Expertise, Training, R&D