From: Michael Paquier Date: Mon, 22 Jun 2026 22:59:03 +0000 (+0900) Subject: Re-introduce pgstat_drop_entry(), keeping ABI compatibility X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9e47718250d8a57576843d1991e21c932c07c7d9;p=thirdparty%2Fpostgresql.git 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 a missing_ok argument. This includes an update of .abi-compliance-history, removing the latest entry that has documented the change of pgstat_drop_entry(). This change is applied across v15~v18. HEAD keeps pgstat_drop_entry() as single entry point, with the new missing_ok. Per discussion with Álvaro Herrera and Lukas Fittl. This is a follow-up of 850b9218c8e4. Discussion: https://postgr.es/m/ajZz_sVJVX7pmPHo@alvherre.pgsql Backpatch-through: 15-18 --- diff --git a/.abi-compliance-history b/.abi-compliance-history index 6bc719dcc16..e4a7770611a 100644 --- a/.abi-compliance-history +++ b/.abi-compliance-history @@ -18,15 +18,6 @@ # Be sure to replace "" with details of your change and # why it is deemed acceptable. -1e9e62193c3fa66e39b50163f225388fcf6eb7d5 -# -# Fix PANIC with track_functions due to concurrent drop of pgstats entries -# 2026-06-18 11:49:41 +0900 -# -# This commit has added a "missing_ok" argument to pgstat_drop_entry(). All -# the callers of this routine are in core for v15-v17. One custom stats kinds -# available in the public since v18 is impacted (maintainer informed). - c5824536e7ca3c5ef5a9db59bd36c4e6beb23f51 # # Fix trigger transition table capture for MERGE in CTE queries. diff --git a/src/backend/utils/activity/pgstat_function.c b/src/backend/utils/activity/pgstat_function.c index d1853f33753..0a975c04f91 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/utils/activity/pgstat_replslot.c index 44047747056..cb61e3e5594 100644 --- a/src/backend/utils/activity/pgstat_replslot.c +++ b/src/backend/utils/activity/pgstat_replslot.c @@ -153,8 +153,8 @@ pgstat_acquire_replslot(ReplicationSlot *slot) void pgstat_drop_replslot(ReplicationSlot *slot) { - 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(); } diff --git a/src/backend/utils/activity/pgstat_shmem.c b/src/backend/utils/activity/pgstat_shmem.c index 5a4657ed42b..332c88eed62 100644 --- a/src/backend/utils/activity/pgstat_shmem.c +++ b/src/backend/utils/activity/pgstat_shmem.c @@ -839,7 +839,7 @@ pgstat_free_entry(PgStatShared_HashEntry *shent, dshash_seq_status *hstat) /* * 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 using * dshash_delete_current(), otherwise use dshash_delete_entry(). In either * case the entry needs to be already locked. */ @@ -927,6 +927,17 @@ pgstat_drop_database_and_contents(Oid dboid) pgstat_request_entry_refs_gc(); } +/* + * 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, Oid objoid) +{ + return pgstat_drop_entry_ext(kind, dboid, objoid, false); +} + /* * Drop a single stats entry. * @@ -941,8 +952,8 @@ pgstat_drop_database_and_contents(Oid dboid) * pgstat_gc_entry_refs(). */ bool -pgstat_drop_entry(PgStat_Kind kind, Oid dboid, Oid objoid, - bool missing_ok) +pgstat_drop_entry_ext(PgStat_Kind kind, Oid dboid, Oid objoid, + bool missing_ok) { PgStat_HashKey key; PgStatShared_HashEntry *shent; diff --git a/src/backend/utils/activity/pgstat_xact.c b/src/backend/utils/activity/pgstat_xact.c index 31a73d83865..afa686d28e5 100644 --- a/src/backend/utils/activity/pgstat_xact.c +++ b/src/backend/utils/activity/pgstat_xact.c @@ -88,7 +88,7 @@ AtEOXact_PgStat_DroppedStats(PgStat_SubXactStatus *xact_state, bool isCommit) * Transaction that dropped an object committed. Drop the stats * too. */ - if (!pgstat_drop_entry(it->kind, it->dboid, it->objoid, true)) + if (!pgstat_drop_entry_ext(it->kind, it->dboid, it->objoid, true)) not_freed_count++; } else if (!isCommit && pending->is_create) @@ -97,7 +97,7 @@ AtEOXact_PgStat_DroppedStats(PgStat_SubXactStatus *xact_state, bool isCommit) * Transaction that created an object aborted. Drop the stats * associated with the object. */ - if (!pgstat_drop_entry(it->kind, it->dboid, it->objoid, true)) + if (!pgstat_drop_entry_ext(it->kind, it->dboid, it->objoid, true)) not_freed_count++; } @@ -164,7 +164,7 @@ AtEOSubXact_PgStat_DroppedStats(PgStat_SubXactStatus *xact_state, * Subtransaction creating a new stats object aborted. Drop the * stats object. */ - if (!pgstat_drop_entry(it->kind, it->dboid, it->objoid, true)) + if (!pgstat_drop_entry_ext(it->kind, it->dboid, it->objoid, true)) not_freed_count++; pfree(pending); } @@ -328,7 +328,7 @@ pgstat_execute_transactional_drops(int ndrops, struct xl_xact_stats_item *items, { xl_xact_stats_item *it = &items[i]; - if (!pgstat_drop_entry(it->kind, it->dboid, it->objoid, true)) + if (!pgstat_drop_entry_ext(it->kind, it->dboid, it->objoid, true)) not_freed_count++; } diff --git a/src/include/utils/pgstat_internal.h b/src/include/utils/pgstat_internal.h index ec9fa891670..28bb1aff2df 100644 --- a/src/include/utils/pgstat_internal.h +++ b/src/include/utils/pgstat_internal.h @@ -603,8 +603,9 @@ extern PgStat_EntryRef *pgstat_get_entry_ref(PgStat_Kind kind, Oid dboid, Oid ob extern bool pgstat_lock_entry(PgStat_EntryRef *entry_ref, bool nowait); extern bool pgstat_lock_entry_shared(PgStat_EntryRef *entry_ref, bool nowait); extern void pgstat_unlock_entry(PgStat_EntryRef *entry_ref); -extern bool pgstat_drop_entry(PgStat_Kind kind, Oid dboid, Oid objoid, - bool missing_ok); +extern bool pgstat_drop_entry(PgStat_Kind kind, Oid dboid, Oid objoid); +extern bool pgstat_drop_entry_ext(PgStat_Kind kind, Oid dboid, Oid objoid, + bool missing_ok); extern void pgstat_drop_all_entries(void); extern PgStat_EntryRef *pgstat_get_entry_ref_locked(PgStat_Kind kind, Oid dboid, Oid objoid, bool nowait);