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 1waucI-0029bA-02 for pgsql-bugs@arkaria.postgresql.org; Sat, 20 Jun 2026 12:16:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1waucG-001aUl-1j for pgsql-bugs@arkaria.postgresql.org; Sat, 20 Jun 2026 12:16:04 +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 1waucF-001aUL-1k for pgsql-bugs@lists.postgresql.org; Sat, 20 Jun 2026 12:16:04 +0000 Received: from fout-a5-smtp.messagingengine.com ([103.168.172.148]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1waucD-00000001I1Z-226u for pgsql-bugs@lists.postgresql.org; Sat, 20 Jun 2026 12:16:02 +0000 Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfout.phl.internal (Postfix) with ESMTP id 6D933EC0259; Sat, 20 Jun 2026 08:15:59 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Sat, 20 Jun 2026 08:15:59 -0400 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=1781957759; x=1782044159; bh=EYPU7CtnEl IOFUJw7tpuag+v/Ws23ICl2O4WIaeYG0o=; b=HlmAIe/bjK8CnRluYALeyV4DXP wQIUEvwlbI0Sfmx+m7gJn3KqBEgRi6W+E4jYP3gqld3ofJo8V+2kfUVfXvq9nzAN vWD36QIi+1VdcTLjE9Qyfn4Hrl7i+miFLGGnyc9EUGHY+RalMFjEfcTNVA9ygjVg 2kqAu5JWrPomgDW38VSfvoaD2403Ic8BIPYmTmIve1++b0hDCAvCdmdvOO0MwD6G F/dKk+h7bhSz2GQitzPLZKrriyLvci2y7XstYi7u3ma2S8kDM7hDnLk4CL0RsMq4 MUHKU3Yi0A2tjn2vxR0wLmC1TF0+IzrYve78TVNMJUewqd4w0VomO0/5paLQ== 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= 1781957759; x=1782044159; bh=EYPU7CtnElIOFUJw7tpuag+v/Ws23ICl2O4 WIaeYG0o=; b=EeOUZiKh+fQlDDiNsgJ/lluDDabW6XGGN6fOavmTOk4g9jIBgyR rJKas3gfhU8m+vXNiIXtcbo2zEteURy5rt7EHVMN+bPAY8uQzSBMTx90gXu7xqA6 4VdDJxdsjzc2+Dcanz+u++UslBpGT2mKbFBLcWmOzDA3Dn9oVhNx2SCUO6gBNxgW y2LZv9coVLmrUlN3PcgT53RBBNiRS4bCmueCr6ULfymqvFF1SkN88HQIMWcSa8aK frG4lxhX4PYXA1uRq855RlZcQRE1mRdlAxxFXMXdXiUQiYzRLxX3HqQLDy3s0Fpe 6QZh1YiNxBnEan1ViyfbpQn3A5KwK0ozzMg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTEtntA5zopc6f7fGsox4uTy1ZUNAhY6xSR/pNMWCuMdd22MKA6LZH7/0VrES6us8M LNHE41pTff4ES/yj4Riacw8p1fWRcj2qX/h1F46eWsLsi/ApkdTBeUH/+sPc7Q8cOXS1BY nHXI56aLGfUR3L8jdDnVvAjNvMXbni9HTdAOFBBwHlSd6Q/FBThytO85ruoR1HLITX4f8x ruioEIGool9dqg4sDxDTuclA8Q7ignmvpBu0bnPuRGazopgVE+hlJxyyVzpMuQNWpZBoo5 SEZ/I33KWjuwmWzTR1Cr83WGcye471eOcLYvjbSqRyQe0FuIn8w6Je2V6nDOW5cMSMqYBz AuTi4EqoLJmddPUSuJ9YFr+X1ERM3dSF69iLOBoi5U23Bqwj6kIByhM3PMj38hPTvqJKz9 w0k4typ9wJD8vm1cSksCOqIkyS1nsV4nL6/iqoN97KmHMWtklUywIzz7Q4d+Utoa3TKYrp xhzDO+w+NQpTFhst0wZ1eVqtDqBjIIQHhfGcXcyejvfEbg6xYtAOdodbvyEEFuNhUKdhyK d7ZoDlE8l/ptzmQouaGL6aMxBlAWIVSrDh0f54lY1zOwMDcfmMMH/okBv9RZDBUdO+0hmG vLxoum2MscpAoTWIZ3t7+Xr3YA9wcJ47B6aQVxxkguYQkzmH6LpmbXuL4Z6A X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 20 Jun 2026 08:15:55 -0400 (EDT) Date: Sat, 20 Jun 2026 21:15:50 +0900 From: Michael Paquier To: =?iso-8859-1?Q?=C1lvaro?= Herrera Cc: Ayush Tiwari , Sami Imseih , zlh21343@163.com, pgsql-bugs@lists.postgresql.org, Andres Freund , Kyotaro Horiguchi Subject: Re: BUG #19520: PANIC when concurrently manipulating stored procedures with pg_stat_statements and track_functions = Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="3rmhOftpbxKOhE4o" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --3rmhOftpbxKOhE4o Content-Type: multipart/mixed; boundary="+81Q/ZCHRGvd2gbI" Content-Disposition: inline --+81Q/ZCHRGvd2gbI Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sat, Jun 20, 2026 at 01:09:59PM +0200, Alvaro Herrera wrote: > I think a better answer is to just not introduce the ABI change in > stable branches. That is, I think we should add a shim function so that > the third-party extensions can continue to use the original ABI; and > only in master you clean that up with a different API, whereby the > extension will be forced to have an #ifdef block for the 19 version or > the older versions, but that's fine because the extension has to be > recompiled for the new major version anyway so the end-user won't be > affected on a minor upgrade. If you feel strongly about it, we could just do something like the attached in the v15-v18 range. This introduces a new routine called pgstat_drop_entry_ext() that gains the new argument "missing_ok", and pgstat_drop_entry() would be an ABI-compatible wrapper calling it. What do you think? -- Michael --+81Q/ZCHRGvd2gbI Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=0001-Re-introduce-pgstat_drop_entry-keeping-ABI-compatibi.patch Content-Transfer-Encoding: quoted-printable =46rom 03e073d2f1d22e777baf62ea2fa8293df76465c4 Mon Sep 17 00:00:00 2001 =46rom: Michael Paquier Date: Sat, 20 Jun 2026 21:11:05 +0900 Subject: [PATCH] Re-introduce pgstat_drop_entry(), keeping ABI compatibility This routine acts as a wrapper of a new pgstat_drop_entry_ext(), used in the core code with the new missing_ok argument. Backpatch-through: 15-18 --- src/include/utils/pgstat_internal.h | 5 +++-- src/backend/utils/activity/pgstat.c | 2 +- src/backend/utils/activity/pgstat_function.c | 4 ++-- src/backend/utils/activity/pgstat_replslot.c | 4 ++-- src/backend/utils/activity/pgstat_shmem.c | 17 ++++++++++++++--- src/backend/utils/activity/pgstat_xact.c | 8 ++++---- .../modules/injection_points/injection_stats.c | 4 ++-- .abi-compliance-history | 2 +- 8 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/include/utils/pgstat_internal.h b/src/include/utils/pgstat= _internal.h index 4f840c38f072..c09eda3a84d9 100644 --- a/src/include/utils/pgstat_internal.h +++ b/src/include/utils/pgstat_internal.h @@ -708,8 +708,9 @@ extern PgStat_EntryRef *pgstat_get_entry_ref(PgStat_Kin= d kind, Oid dboid, uint64 extern bool pgstat_lock_entry(PgStat_EntryRef *entry_ref, bool nowait); extern bool pgstat_lock_entry_shared(PgStat_EntryRef *entry_ref, bool nowa= it); extern void pgstat_unlock_entry(PgStat_EntryRef *entry_ref); -extern bool pgstat_drop_entry(PgStat_Kind kind, Oid dboid, uint64 objid, - bool missing_ok); +extern bool pgstat_drop_entry(PgStat_Kind kind, Oid dboid, uint64 objid); +extern bool pgstat_drop_entry_ext(PgStat_Kind kind, Oid dboid, uint64 obji= d, + bool missing_ok); extern void pgstat_drop_all_entries(void); extern void pgstat_drop_matching_entries(bool (*do_drop) (PgStatShared_Has= hEntry *, Datum), Datum match_data); diff --git a/src/backend/utils/activity/pgstat.c b/src/backend/utils/activi= ty/pgstat.c index d997be2e1d93..99e537bc886a 100644 --- a/src/backend/utils/activity/pgstat.c +++ b/src/backend/utils/activity/pgstat.c @@ -620,7 +620,7 @@ pgstat_shutdown_hook(int code, Datum arg) dlist_init(&pgStatPending); =20 /* drop the backend stats entry */ - if (!pgstat_drop_entry(PGSTAT_KIND_BACKEND, InvalidOid, MyProcNumber, fal= se)) + if (!pgstat_drop_entry_ext(PGSTAT_KIND_BACKEND, InvalidOid, MyProcNumber,= false)) pgstat_request_entry_refs_gc(); =20 pgstat_detach_shmem(); diff --git a/src/backend/utils/activity/pgstat_function.c b/src/backend/uti= ls/activity/pgstat_function.c index f763a0d6f5ba..eaeb0dcb1def 100644 --- a/src/backend/utils/activity/pgstat_function.c +++ b/src/backend/utils/activity/pgstat_function.c @@ -112,8 +112,8 @@ pgstat_init_function_usage(FunctionCallInfo fcinfo, AcceptInvalidationMessages(); if (!SearchSysCacheExists1(PROCOID, ObjectIdGetDatum(fcinfo->flinfo->fn_= oid))) { - pgstat_drop_entry(PGSTAT_KIND_FUNCTION, MyDatabaseId, - fcinfo->flinfo->fn_oid, true); + pgstat_drop_entry_ext(PGSTAT_KIND_FUNCTION, MyDatabaseId, + fcinfo->flinfo->fn_oid, true); ereport(ERROR, errcode(ERRCODE_UNDEFINED_FUNCTION), errmsg("function call to dropped function")); } diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/uti= ls/activity/pgstat_replslot.c index 746b97a0b5af..675c535266c0 100644 --- a/src/backend/utils/activity/pgstat_replslot.c +++ b/src/backend/utils/activity/pgstat_replslot.c @@ -157,8 +157,8 @@ pgstat_drop_replslot(ReplicationSlot *slot) { Assert(LWLockHeldByMeInMode(ReplicationSlotAllocationLock, LW_EXCLUSIVE)); =20 - if (!pgstat_drop_entry(PGSTAT_KIND_REPLSLOT, InvalidOid, - ReplicationSlotIndex(slot), false)) + if (!pgstat_drop_entry_ext(PGSTAT_KIND_REPLSLOT, InvalidOid, + ReplicationSlotIndex(slot), false)) pgstat_request_entry_refs_gc(); } =20 diff --git a/src/backend/utils/activity/pgstat_shmem.c b/src/backend/utils/= activity/pgstat_shmem.c index 414b66be2dc4..056c24c6ee1b 100644 --- a/src/backend/utils/activity/pgstat_shmem.c +++ b/src/backend/utils/activity/pgstat_shmem.c @@ -880,7 +880,7 @@ pgstat_free_entry(PgStatShared_HashEntry *shent, dshash= _seq_status *hstat) =20 /* * Helper for both pgstat_drop_database_and_contents() and - * pgstat_drop_entry(). If hstat is non-null delete the shared entry using + * pgstat_drop_entry_ext(). If hstat is non-null delete the shared entry u= sing * dshash_delete_current(), otherwise use dshash_delete_entry(). In either * case the entry needs to be already locked. */ @@ -968,6 +968,17 @@ pgstat_drop_database_and_contents(Oid dboid) pgstat_request_entry_refs_gc(); } =20 +/* + * ABI-preserving wrapper around pgstat_drop_entry_ext(). + * + * The original routine introduced in v15 did not include "missing_ok". + */ +bool +pgstat_drop_entry(PgStat_Kind kind, Oid dboid, uint64 objid) +{ + return pgstat_drop_entry_ext(kind, dboid, objid, false); +} + /* * Drop a single stats entry. * @@ -982,8 +993,8 @@ pgstat_drop_database_and_contents(Oid dboid) * pgstat_gc_entry_refs(). */ bool -pgstat_drop_entry(PgStat_Kind kind, Oid dboid, uint64 objid, - bool missing_ok) +pgstat_drop_entry_ext(PgStat_Kind kind, Oid dboid, uint64 objid, + bool missing_ok) { PgStat_HashKey key; PgStatShared_HashEntry *shent; diff --git a/src/backend/utils/activity/pgstat_xact.c b/src/backend/utils/a= ctivity/pgstat_xact.c index b058c978dcf3..fbbf2844a58f 100644 --- a/src/backend/utils/activity/pgstat_xact.c +++ b/src/backend/utils/activity/pgstat_xact.c @@ -85,7 +85,7 @@ AtEOXact_PgStat_DroppedStats(PgStat_SubXactStatus *xact_s= tate, bool isCommit) * Transaction that dropped an object committed. Drop the stats * too. */ - if (!pgstat_drop_entry(it->kind, it->dboid, objid, true)) + if (!pgstat_drop_entry_ext(it->kind, it->dboid, objid, true)) not_freed_count++; } else if (!isCommit && pending->is_create) @@ -94,7 +94,7 @@ AtEOXact_PgStat_DroppedStats(PgStat_SubXactStatus *xact_s= tate, bool isCommit) * Transaction that created an object aborted. Drop the stats * associated with the object. */ - if (!pgstat_drop_entry(it->kind, it->dboid, objid, true)) + if (!pgstat_drop_entry_ext(it->kind, it->dboid, objid, true)) not_freed_count++; } =20 @@ -160,7 +160,7 @@ AtEOSubXact_PgStat_DroppedStats(PgStat_SubXactStatus *x= act_state, * Subtransaction creating a new stats object aborted. Drop the * stats object. */ - if (!pgstat_drop_entry(it->kind, it->dboid, objid, true)) + if (!pgstat_drop_entry_ext(it->kind, it->dboid, objid, true)) not_freed_count++; pfree(pending); } @@ -323,7 +323,7 @@ pgstat_execute_transactional_drops(int ndrops, struct x= l_xact_stats_item *items, xl_xact_stats_item *it =3D &items[i]; uint64 objid =3D ((uint64) it->objid_hi) << 32 | it->objid_lo; =20 - if (!pgstat_drop_entry(it->kind, it->dboid, objid, true)) + if (!pgstat_drop_entry_ext(it->kind, it->dboid, objid, true)) not_freed_count++; } =20 diff --git a/src/test/modules/injection_points/injection_stats.c b/src/test= /modules/injection_points/injection_stats.c index 435a0484a4ba..c659b2660d4f 100644 --- a/src/test/modules/injection_points/injection_stats.c +++ b/src/test/modules/injection_points/injection_stats.c @@ -149,8 +149,8 @@ pgstat_drop_inj(const char *name) if (!inj_stats_loaded || !inj_stats_enabled) return; =20 - if (!pgstat_drop_entry(PGSTAT_KIND_INJECTION, InvalidOid, - PGSTAT_INJ_IDX(name), false)) + if (!pgstat_drop_entry_ext(PGSTAT_KIND_INJECTION, InvalidOid, + PGSTAT_INJ_IDX(name), false)) pgstat_request_entry_refs_gc(); } =20 diff --git a/.abi-compliance-history b/.abi-compliance-history index 6ba3e7519b70..bff1286f9ddd 100644 --- a/.abi-compliance-history +++ b/.abi-compliance-history @@ -23,7 +23,7 @@ # Fix PANIC with track_functions due to concurrent drop of pgstats entries # 2026-06-18 11:49:34 +0900 # -# This commit has added a "missing_ok" argument to pgstat_drop_entry(). A= ll +# This commit has added a "missing_ok" argument to pgstat_drop_entry_ext()= =2E All # the callers of this routine are in core for v15-v17. One custom stats k= inds # available in the public since v18 is impacted (maintainer informed). =20 --=20 2.54.0 --+81Q/ZCHRGvd2gbI-- --3rmhOftpbxKOhE4o Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmo2hHYACgkQnvQgOdby QH3/Yg/+Mj7ZXOLbPsul+D84S/pf2lFoDsspEMVSeHxiVTg5KlV3qMiiMzZDI+oZ tLMCiA0IJqWvX3q3z8dgbgStjKoE6zfeP7P9TzP/4p4vYX1p257vsNuwb/U58zTu AGmTbH1ZcXJUkyCK3Lz2nSyKEacsYrLKGnE2f9bwK49s9eZP8sXFNhqXEKHWVjV3 +CWOXq2BRyWTHX7cFFgHNxycYOaCCXd4+b1o7bU208DDlYLyrKsTD6B6VtqDVBAy eAY2TjBTtwc8z8tPeIYbioi0VN5Z3BENcl6RMhkKh/RoRY23HjoTR2LVnR5tMqRl y/n7aXTTaI31Yrra5F0hqq0Gr/Sn3+L3Lz8yuktctwGKU2FMmftPr0UcOyglLlcE Aj6o/47GVhTvvGlJpKoCofcUxpiERsIIHUPO0xTcbG/bbWdU+z44GnLQAOBVKU9J cmVxmJg96KX7zkGa5mJogXfIUZt49zS8RgmynUYIKMA7wnVuHH6gP2NLQQcjN5uZ lPgQVvMlQrBjvuvkrT6DqOA9MNqKkMA41zLWuYsJJun4yAOsDKS2yo36/rpwsS5b AvxIME2O4dKDDog+Uz9zWPRE2/Fr1u8uvSWIBqOzvAkECfGvF3/b08IW3dKsfndV At3Xy32hknuYur2zeRnX0ARpl3gqWYeqToTb6SOQiOpkzkxTnSc= =GeEH -----END PGP SIGNATURE----- --3rmhOftpbxKOhE4o--