From 3fc4823142ee12f853247ccd1c96d896748170b5 Mon Sep 17 00:00:00 2001 From: Floris van Nee Date: Sun, 2 Jun 2024 22:35:44 +0200 Subject: [PATCH] Notify stats gc when dropping logical replication slot pgstat_drop_replslot calls pgstat_drop_entry without checking the result. If pgstat_drop_entry cannot free the entry from shared memory completely, the gc function must be called to flag it for other backends. This is similar to what AtEOXact_PgStat_DroppedStats and similar functions do. --- src/backend/utils/activity/pgstat_replslot.c | 5 +++-- src/backend/utils/activity/pgstat_shmem.c | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c index 889e86ac5a..da11b86744 100644 --- a/src/backend/utils/activity/pgstat_replslot.c +++ b/src/backend/utils/activity/pgstat_replslot.c @@ -157,8 +157,9 @@ pgstat_drop_replslot(ReplicationSlot *slot) { Assert(LWLockHeldByMeInMode(ReplicationSlotAllocationLock, LW_EXCLUSIVE)); - pgstat_drop_entry(PGSTAT_KIND_REPLSLOT, InvalidOid, - ReplicationSlotIndex(slot)); + if (!pgstat_drop_entry(PGSTAT_KIND_REPLSLOT, InvalidOid, + ReplicationSlotIndex(slot))) + pgstat_request_entry_refs_gc(); } /* diff --git a/src/backend/utils/activity/pgstat_shmem.c b/src/backend/utils/activity/pgstat_shmem.c index 91591da395..a44ac559b2 100644 --- a/src/backend/utils/activity/pgstat_shmem.c +++ b/src/backend/utils/activity/pgstat_shmem.c @@ -855,6 +855,13 @@ pgstat_drop_database_and_contents(Oid dboid) pgstat_request_entry_refs_gc(); } +/* + * This function expects callers to call pgstat_request_entry_refs_gc if necessary. + * Generally this must be called if the return value is false, when the object + * couldn't be freed. + * Note this is different behavior than other drop functions like pgstat_drop_all_entries + * which do call pgstat_request_entry_refs_gc + */ bool pgstat_drop_entry(PgStat_Kind kind, Oid dboid, Oid objoid) { -- 2.30.1