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 1vQfdF-00EeTD-0z for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Dec 2025 05:42:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vQfdD-00BQYv-3A for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Dec 2025 05:42:28 +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 1vQfdD-00BQYm-1r for pgsql-hackers@lists.postgresql.org; Wed, 03 Dec 2025 05:42:28 +0000 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vQfdA-002s9r-1p for pgsql-hackers@lists.postgresql.org; Wed, 03 Dec 2025 05:42:26 +0000 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-29812589890so75484805ad.3 for ; Tue, 02 Dec 2025 21:42:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764740544; x=1765345344; 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=i1XHNOVZDl7EHwsc5T1J03/galWDTXRBBOe7ZwfTbM0=; b=Sc1SpA3BxrMWl82AIuKoAAoC+E9Az8r2kdf5LNb3YB94cN5inYfgMvdzHzy30huOK5 7krn6InT4YmsYipixGtWoDfDBbF4dNeP79ZrYT1F+Pk33G39ZLhjHhQGLOe3mopXFCJ2 P5u/rmo1uhmyiLRWzs+aGkjAAlEwPNdMKRutZFIFq5v6Y4JhP7bjESn6v+0cjrGEm0rK T8Dcl9ydBk2s5Y6I8E0OymqE3/H61kmtyAfK/fl50C+9T6loLWX19ZKYPvG+eGVL8pl5 IeJMD4L9c4e1sJuzR2RaZASbs/ocG7/h0g3lfG5FmxKMVmOFJyrT0XGA3r7Lk00uzfip 6RMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764740544; x=1765345344; 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=i1XHNOVZDl7EHwsc5T1J03/galWDTXRBBOe7ZwfTbM0=; b=LdqKY79dJCBuzC0rr3uphxyCVit9XdWOcYFW4ga3QbXKaqOR0jHgneca9fYOaOq7AG 772QlxHvpu9vjYm0aIOqpJKMZFRxR93aB9t4hAdLCJjEbKGbxkG648uBwGm1+cJNYJQT uSOtfNIgyBpfSm+fwk6Dnp0mCEbMKPMUxtjP5iTS1yj4MPpXrGNcFNNNoqE47Lmb3UCP DRHu7jIV5//A1grlf/RpKmUIa9Gc3tY7gbE43xJuYKWMI43MSSeLzjSrmbEZtQTrtyCm q0JZ0wUOJNYqTAKLYqUXZtgcx8iKT8A0ISrLdO1nF6D8yS9ttEUzMuoMku7CM9Gcqmpw 9p4A== X-Forwarded-Encrypted: i=1; AJvYcCXRRyStq3LpYeSRDdc9kYIdYuj8UZN65+urIL5xyYPDCPMIHsDD9Q2OeVNCh1XXhxMv262IwVMkuRejC8Rv@lists.postgresql.org X-Gm-Message-State: AOJu0YwR69Tg75j6K5cMRAXzPbkqp5NqPtviEeRRbeiG/2+8palBN3DU VxxKFrke7Mj4b1F17vvje7HWuiDvgYcsexz2bdDOLm9+6vSJne/TUQXh X-Gm-Gg: ASbGncuWYDoQo9SsGUVh37Qg4JIVgoTKDwekJBBQ9sE9kXAGRElUkx92d1zsbSrGpOm QYUpKu2Ahcyr7vlwLn0P6d0WhtDR05BB7WSNDktCzjpKP0aw4r/EHUP+Xx3E4//n+eBpCYlqDgO b+j4gwFGZ75wqbRhV6vGiz4vT1YuzYWZdBMZHCcRVaEXT2/XlYUgfOALzyogCa+d/hQ5Nu+bYb+ B3RbQaAPcNPzBSNkNvL31am9x1u6rgEU9N0lAXK72TxzwA/7wLgl8BlIIuPvDhZEEO4mPfakxmB w/+AsuM2KmVqfoCwaJ+KnMBClU8qRRBxtNvY3PcmleUWV0WKHqh5U4KXMqDDljEu1FtMspGJWcV s3JqLeOvHQ4U3lsGG1PrT67NgnrTk1G9QY2DxsD9nLumgPr/2YnR6RJj+OVkWusUOq/561SbgcM ydBI5haV1HviSzT3GT46LOW1IwqSVBHw== X-Google-Smtp-Source: AGHT+IE40SF2R0rIxLpqU8Sq/mA78YZwZKiqFG7kqen2v899vmS8UnyJnsxbhD+Irq3wbxMnrzNMtg== X-Received: by 2002:a17:903:13c7:b0:298:4ee2:19f3 with SMTP id d9443c01a7336-29d68482cdamr15951335ad.49.1764740544192; Tue, 02 Dec 2025 21:42:24 -0800 (PST) Received: from smtpclient.apple ([45.32.121.103]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-34912ce3f5fsm443228a91.3.2025.12.02.21.42.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Dec 2025 21:42:23 -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 13:41:44 +0800 Cc: Michael Paquier , PostgreSQL Hackers Content-Transfer-Encoding: quoted-printable Message-Id: <4FEEC2B8-D9CF-4BD0-AA7E-44CE3E27ADD8@gmail.com> References: To: Sami Imseih 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 04:58, Sami Imseih wrote: >=20 >>> Also, I am now leaning towards creating a separate test module = rather than >>> trying to do too much unrelated testing in injection points. It is = definitely >>> convenient to use injection points, but I think we can do better = testing with >>> a separate module. This module can also serve as an example for = extension >>> developers. >>=20 >> You are right that it may be cleaner this way. Do you think that it >> could make sense to move some of the existing "template" code of >> injection_points there? >=20 > By "template" code, do you mean Something like? >=20 > include/utils/custom_statkinds.h > backend/utils/misc/custom_statkinds.c >=20 > Where the template code here is PgStat_kind definition, callbacks, = etc. for > injection_points or the new test module that is using a custom kind. >=20 > A few benefits I see for this is we can point extension developers to > this as an example in [0] and we are also maintaining the kind ids in > a single place. These may not be strong points, but may be worth = while. >=20 > v2 attached is something that may be closer to what we've been = discussing >=20 > v2-0001 are much simplified changes to pgstat.c that simply invoke the = callbacks > and all the work is on the extension to implement what it needs to do. > This includes > a callback at the end of WRITE, READ, DISCARD with a flag passed to = the caller > so they can perform the necessary clean-up actions. >=20 > v2-0002 implements a new test module that tests mainly that the = recovery, > clean and crash, are working as expected. >=20 > I created a new tap test for this which performs a test similar to = what is > done in recovery/029_stats_restart.pl. I could merge the new test = there, but > I am reluctant to add a dependency on a new module to recovery. What > do you think? >=20 > [0] = https://www.postgresql.org/docs/current/xfunc-c.html#XFUNC-ADDIN-CUSTOM-CU= MULATIVE-STATISTICS >=20 >=20 > -- > Sami Imseih > Amazon Web Services (AWS) > = Thanks for the patch, I do think the feature will be useful. After = reading the patch, I got a concern on the design: 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: * 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? * 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? * 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? * 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? 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. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/