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 1vQfpi-00EhnV-19 for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Dec 2025 05:55:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vQfpg-00BWXx-35 for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Dec 2025 05:55:21 +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 1vQfpg-00BWXo-0I for pgsql-hackers@lists.postgresql.org; Wed, 03 Dec 2025 05:55:20 +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.96) (envelope-from ) id 1vQfpd-002sHq-2C for pgsql-hackers@lists.postgresql.org; Wed, 03 Dec 2025 05:55:19 +0000 Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfhigh.phl.internal (Postfix) with ESMTP id 8A13B14001EB; Wed, 3 Dec 2025 00:55:17 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Wed, 03 Dec 2025 00:55:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc: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=fm1; t=1764741317; x=1764827717; bh=7naphzot/W aM90GeyUVx4Ooo8qZ+rqRQ6LtpIwYHULg=; b=Atow/cCm/YEGjrMwUrKH9r/AIM /ejbT99g+YDgAFIUijOklKYZT+o9phNpaYS0o83SkJrf+b65MEYgsp6Dw5BdB2D/ AjAyqWmhdWRz6Lmb+2od81EW2+7ooSytKXIbiYLQK/A191NRW6UJIYDqtFNO6J8I usNz1IWnkmB701DIVrN/pOLhF7pjQ+lazWRfKxDbHTOS/47zOxM4Jsdn3RA0rB1a HOt7QfhkO7hlnvjtxD/sF0lyvj63HNzREB0uxvUZzNY7Xrz8RymCTCvI+KH57UZD /NKVcFl20YJA0i4yh8y3V1yKDhGv+9Ukx0p9xvCb7KsrQPXpsd5DDj6hCMEQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc: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=fm1; t= 1764741317; x=1764827717; bh=7naphzot/WaM90GeyUVx4Ooo8qZ+rqRQ6Lt pIwYHULg=; b=gkDBwWMYvLM7RTGLJQXIAuuKVVDwp47BCJmQaondj6xQ3zbmz/v yU2r2hVcOfKgCZvs9HxEJiCDG+FMOSfmwMQK+lJFr2yzOh3tsLOd1SQp5wGeos4w 3/s1FUl4RhTnzDGAceR6V32b+GwSvFfMvzH5ZCVlHoUMiStedrMZqT0HyFYI6YP4 vlxmAmo05b5UknwRhu1iUlnGU2i4WSi/laYCo4Yu5q4VkZwKKYPk1t/w/2MV/Nj4 B7wxlx4SY/m6rZuKggxxdtB+mR4v6khccsO/jSzAXJ/bPhPCq1kvg1oiHjTdbBJb cyHNcnowFMbe2vhdvYqm/hy+9HUKDTK2KcA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvtdelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceurghi lhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnegfrhhluc fvnfffucdljedtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttdejnecu hfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesphgrqhhuih gvrhdrgiihiieqnecuggftrfgrthhtvghrnhepveetjefgjeevgedukeehieeuieeuieev ueeiudegheevuefggfduueelgeelieetnecuvehluhhsthgvrhfuihiivgeptdenucfrrg hrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihiidpnhgs pghrtghpthhtohepfedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheplhhirdgvvh grnhdrtghhrghosehgmhgrihhlrdgtohhmpdhrtghpthhtohepshgrmhhimhhsvghihhes ghhmrghilhdrtghomhdprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehlihhsth hsrdhpohhsthhgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 3 Dec 2025 00:55:15 -0500 (EST) Date: Wed, 3 Dec 2025 14:54:52 +0900 From: Michael Paquier To: Chao Li Cc: Sami Imseih , PostgreSQL Hackers Subject: Re: [Proposal] Adding callback support for custom statistics kinds Message-ID: References: <4FEEC2B8-D9CF-4BD0-AA7E-44CE3E27ADD8@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="uxSbyhfrPmVKHRC6" Content-Disposition: inline In-Reply-To: <4FEEC2B8-D9CF-4BD0-AA7E-44CE3E27ADD8@gmail.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --uxSbyhfrPmVKHRC6 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 readin= g 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? 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. > * 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? Extension code would be responsible for ensuring that. > * 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? 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. 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? > * 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. > 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 --uxSbyhfrPmVKHRC6 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmkv0KwACgkQnvQgOdby QH077Q//ZXF+Pvj2K1UsmoIpdEAV3iWPJIiFT+bd3C52JydO04ked1XMhsTYdOWj AVqHqAnii+jfmtF8kZvTr3Cyjk+Y0tAz+1KaZ4HywVK1V07Isqojh93VsB5f3ggL 7HQjL8VvaGH8k3FBIO3QOWEcARGe5g7wNHRTmfHUUZfrhg46A0eLFAVoID56mP3d XUWDJWTNKfzsM5qqXbu1F6KyduqFubUphU12W5VmmtkmHJiOhjn+X9LXimtxXuRQ Kh0j8xrm7jRH+HFeV5/jZrThnZNBPpBzAtpAkHo2omVIKiTZyNLGuqGJquoLn0qI gTjtvEgcu/WPwrxcdOhI82pGHV7wDFqObjyv0mTmtZ79NbcUXbD9sAA5mFtV4o9J mS6PsPSRFnfq1O7SsNmqoJfdDHrV6EyUr+Nntm+QdS8/ptiVsYeoWP1kNl6Sr00C IeK3ibKFTTqi2zXUU4Sddnk10pqtctM3TtvDvG+2hfSypdFD4SMyG+EsYXM3ZPjX KuvdIgpcFh9L4xizRY4brzApFvMk+mmMeh3Pd+GTz0+eU4WCCNK0HBKAye5NaLBv ZeHAhvl7jM3VrztJ+bGv/cy7YVbUNrlz0gSPA7GUUNuMQXX0HZV097eAOc6dDnDB NsEbVG0J38CHEKtTVcZ8r4tRKLLyJhF4Ce0+h4Wze6uT11KupAk= =nyYU -----END PGP SIGNATURE----- --uxSbyhfrPmVKHRC6--