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 1vQgBG-00EmSs-1v for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Dec 2025 06:17: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 1vQgBF-00Balp-1s for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Dec 2025 06:17:37 +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.96) (envelope-from ) id 1vQgBF-00Balh-0u for pgsql-hackers@lists.postgresql.org; Wed, 03 Dec 2025 06:17:37 +0000 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vQgBD-002s2w-0H for pgsql-hackers@lists.postgresql.org; Wed, 03 Dec 2025 06:17:37 +0000 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-7b7828bf7bcso7331423b3a.2 for ; Tue, 02 Dec 2025 22:17:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764742652; x=1765347452; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=pqDNjOLDAL69UuDuZk9SjCNI+KkQ8Gv6EFCMfpJpUmg=; b=CD+AulpO98q2UdDEVTbbj/Vqxu/mHoyeP/blyjiCAE71D/vVuWKhrAqNWp0HX8EMp+ YtHZxgqqgG3Nxnoo75IAjVEYTGjHbuoIfe/kWL3m9mfi3D2RPJnyyEsyFvc6yjswY1lP e1vRyISKEm5xHpTyjpOu2xl6HpnYUza9Sfnotw9s9DfszfgW9+5lRMX6lI6Nypt+5Yn0 bvHNK6y8kFZRnuKGt69gx9jh+9nzQd4YpliQfnOdra/RALXychrdT8jKDw9MDJUJR2Qg YIDpF1RNGyzXyOUpeReEBLfKeu79DSdl+ARQZuwNEHnJxLepFRSRn5L47bCNPeqcl+je GnOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764742652; x=1765347452; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=pqDNjOLDAL69UuDuZk9SjCNI+KkQ8Gv6EFCMfpJpUmg=; b=eX98YHnugaZJpl+Fwt7vwuhb2iLJkDBSqqMlWKdWq3P5rNnhqXKwBhAJznxOTnFKh4 FPKu1ct8vD4umTFPKUTw6r4hqVn4PtdnfDdpIxjdClBTGxmQE2oJk+cezkRa2rVKtMCL tg29nDfKFX8bfwGtIU2MzFrwNWlWovfRv3s3o9P1iacob+bqrf5z6IMh4gzvercQiOjz fKCvjzMdEIMHJEQTHE8BPnmAyhwcPOtDXqK+jcEvkDet+8Ebl/fj1+rzq9fI4kMSRurA uk9fRoZ5LziaDTdXlODuVqWM/87BpzCV2XQLSXcDyYFoFvck10BexkS70cG43tat0pBc pxzg== X-Forwarded-Encrypted: i=1; AJvYcCXdo8Q9o0NU0Q2rvhmBVHz4Cqj78YprjbB3iG/9LU7is3aTOHXEcwPAWgLU3oDhfnJ+4M5VJMuIptSAMHBM@lists.postgresql.org X-Gm-Message-State: AOJu0YyzNOotdo5MmK8p+kPU92NueJlkKX0LxLKH2jWRTRngskEgBWX/ I1XqInwOsI55iz7PL5DpAFgjuUUl5vO9/Q/59Drfek5TY1iA4KuznCJe4xSrLEen X-Gm-Gg: ASbGnctYUr8BrpOZcVyU2t1MM+7JEae3Y6zvBBdtBWP/Kj7lrbeaGgooHDdLeTlEAfE nJ/uBlol7nbI/s4BWLpquC46q1rbOUhlfcBdHa8wO9F+LgC0Ia8jyX7ATdUdA/FDVVCfR1V+vlx Bx2Iz+NSWRRCU4NiZAZEk6+b1l65Xne0/RRyCr+DT2wwH2q4XMaf00I3TKx1XNgt1I1+xFT5ek6 rDD4SquJ4UnfmQz7yEBAuPpgEOZ5KQlA9iGQoSfzCTCFrPkq7xNwu2fXbpW6t4n7rN5Gh4ie7KI obnIB82L0F64NzrtUhDshpptesw99QoenCOmdpGE48d0gIvQJzY8/APfwpwfGNnalkO5mKzPmVd 0B7z9R1aArEwhQ7ZWI28Bdd7FpAB4GtJzKRe1xzvxm9GFKjUrNBPYSAnyfFm8LpQOo7E1xJ5jPR KEIwkGR+pJl/GgDPnsmS8= X-Google-Smtp-Source: AGHT+IE3eFlbsATng0bzfnBcUjlZczGVB0W9QSuvFD+biKJOyJEvcOSkT4XCg5xAw9x4s9YZ32umRg== X-Received: by 2002:a05:6a20:72a9:b0:34e:975:3bb9 with SMTP id adf61e73a8af0-363f5ec4514mr1713048637.49.1764742652262; Tue, 02 Dec 2025 22:17:32 -0800 (PST) Received: from smtpclient.apple ([45.32.121.103]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7d15fcfd0c4sm18799059b3a.68.2025.12.02.22.17.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Dec 2025 22:17:31 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: [Proposal] Adding callback support for custom statistics kinds From: Chao Li In-Reply-To: Date: Wed, 3 Dec 2025 14:16:54 +0800 Cc: Sami Imseih , PostgreSQL Hackers Content-Transfer-Encoding: quoted-printable Message-Id: <5EC13E39-B41E-464A-B382-0ACEB18A15BB@gmail.com> References: <4FEEC2B8-D9CF-4BD0-AA7E-44CE3E27ADD8@gmail.com> To: Michael Paquier X-Mailer: Apple Mail (2.3826.700.81) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Dec 3, 2025, at 13:54, Michael Paquier wrote: >=20 > On Wed, Dec 03, 2025 at 01:41:44PM +0800, Chao Li wrote: >> Thanks for the patch, I do think the feature will be useful. After = reading the patch, I got a concern on the design: >>=20 >> This patch provides callbacks that requests (also allows) custom >> extensions to write stat files on their own behalf, which I think >> it=E2=80=99s unsafe. The problems coming out to my head includes: >>=20 >> * An extension can write to any where on the storage, that what >> * about it writes to /tmp and the files are deleted by other process >> * or by a user manually incidentally? >=20 > I mean, just don't do that. It's up to the extension developer to > decide what is safe or not, within the scope of the data folder. >=20 >> * pgstat has a pattern of writing files like: writing to tmp file >> * first, then durable_rename(), how to ensure extensions to do the >> * same pattern? Without this pattern, how to ensure reliability of >> * stat files? >=20 > Extension code would be responsible for ensuring that. >=20 >> * In the current path, pgstat performs its own write, then call >> * callbacks. What about if a callback fails? Will that leave pgstat >> * in a stale state? >=20 > For the write state, end_extra_stats() would take care of that. It > depends on what kind of errors you would need to deal with, but as > proposed the patch would offer the same level of protection for the > writes of the stats, where we'd check for an error on the fd saved by > an extension for an extra file. >=20 > I think that you have a fair point about the stats read path though, > shouldn't we make the callback from_serialized_extra_stats() return a > state to be able to trigger a full-scale cleanup, at least? >=20 >> * As extensions own file creation and deletion, in some case, staled >> * file might be left on storage, who will be responsible for >> * cleaning up them? >=20 > The extension should be able to handle that, I guess. Yes, they of course can do, but that=E2=80=99s out of pgstat=E2=80=99s = control. How can we ensure that? >=20 >> Given the goal of the feature is to allow extensions to serialize >> custom data, the callback should just return serialized/deserialized >> data, maybe together with some metadata, then pgstat should be >> responsible for writing the data. In other words, IMO, pgstat should >> always own stat files. >=20 > That's where my view of the matter differs, actually, pushing down the > responsibility into the extension code itself. A key argument, > mentioned upthread, is that the file paths could depend on the stats > entry *keys*, which may not be known in advance when beginning the > flush of the stats. Think about per-database file stats, or just > some per-object file stats, for example, which is an option that would > matter so as we do not bloat the main pgstats file. > -- > Michael If we push down the responsibility into the extension code, then all = extensions that want to enjoy the callbacks have to handle the same = complexities of dealing with stat files, which sounds big duplicate = efforts. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/