From 8c3a68dfd65686a0c30019288475bc5d9c6bc8f6 Mon Sep 17 00:00:00 2001 From: Sami Imseih Date: Fri, 16 Oct 2026 14:39:39 +0000 Subject: [PATCH v1 1/1] pgstat: Don't assert on dropped entries when writing stats file A dropped stats entry can remain in the hash table if its stats key is reused while the old entry is still referenced, as can happen with replication slot stats when a slot index is reused. pgstat_write_statsfile() already skips dropped entries, so remove the assertion that treated them as impossible. --- src/backend/utils/activity/pgstat.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/backend/utils/activity/pgstat.c b/src/backend/utils/activity/pgstat.c index d31c0b48a1d..723542bf109 100644 --- a/src/backend/utils/activity/pgstat.c +++ b/src/backend/utils/activity/pgstat.c @@ -1763,15 +1763,12 @@ pgstat_write_statsfile(void) const PgStat_KindInfo *kind_info = NULL; /* - * We should not see any "dropped" entries when writing the stats - * file, as all backends and auxiliary processes should have - * cleaned up their references before they terminated. - * - * However, since we are already shutting down, it is not worth - * crashing the server over any potential cleanup issues, so we - * simply skip such entries if encountered. + * A "dropped" entry may survive in the hash table if it was + * reinitialized for a reused stats key while still being held by + * the original backend. This can happen with replication slot + * stats, where a new slot can reuse the same slot index. In that + * case, skip the dropped entry. */ - Assert(!ps->dropped); if (ps->dropped) continue; -- 2.50.1