pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix cleanup of reused pgstats entries in pgstat_release_entry_re 6+ messages / 1 participants [nested] [flat]
* pgsql: Fix cleanup of reused pgstats entries in pgstat_release_entry_re @ 2026-10-21 01:56 Michael Paquier <michael@paquier.xyz> 0 siblings, 0 replies; 6+ messages in thread From: Michael Paquier @ 2026-10-21 01:56 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix cleanup of reused pgstats entries in pgstat_release_entry_ref() When a stats entry is reinitialized and dropped again while a backend still holds a reference from an older generation, the backend releasing the last reference found a generation mismatch and left behind an entry marked as dropped with a refcount of 0. Nothing would free it, and the checkpointer would trigger an assertion at shutdown when flushing the stats. Looking more at the issue, using some hardcoded sleeps before the dshash_find() that takes an exclusive lock when releasing an entry with some concurrent activity, there was more going on: - A missing entry could be reported as an error at backend exit, error that should not be hit even if the entry was reinitialized and dropped concurrently. - The generation check was not correct for the case of 0 due to the first issue. A generation of 0 refers to an entry that has been freshly created. This commit reworks the entry release to be safer concurrent-wise when an entry targetted for release is found as already existing: - If marked as dropped without refount at 0, free it. - In other cases, ignore it. The entry has been reinitialized or created again with the same key, and is still in use. Sami has posted a basic test case (equivalent added in this commit) that gives a way to reproduce the assertion failure on backend exit, which is a consequence of the incorrect handling of entry releases. Reported-by: Sami Imseih <samimseih.pg@gmail.com> Reviewed-by: Sami Imseih <samimseih.pg@gmail.com> Discussion: https://postgr.es/m/CAN12+YJXE+rEOVo74uM5Ofbj_t_m0DHvd_Mo4ppeHV=aDvvXoQ@mail.gmail.com Backpatch-through: 15 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/e9d0600aba5467b352eb67aaf6ad92a9a4776b0a Modified Files -------------- contrib/test_decoding/t/001_repl_stats.pl | 38 ++++++++++++++++++++++++++ src/backend/utils/activity/pgstat_shmem.c | 45 +++++++++++-------------------- 2 files changed, 54 insertions(+), 29 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix cleanup of reused pgstats entries in pgstat_release_entry_re @ 2026-10-21 01:56 Michael Paquier <michael@paquier.xyz> 0 siblings, 0 replies; 6+ messages in thread From: Michael Paquier @ 2026-10-21 01:56 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix cleanup of reused pgstats entries in pgstat_release_entry_ref() When a stats entry is reinitialized and dropped again while a backend still holds a reference from an older generation, the backend releasing the last reference found a generation mismatch and left behind an entry marked as dropped with a refcount of 0. Nothing would free it, and the checkpointer would trigger an assertion at shutdown when flushing the stats. Looking more at the issue, using some hardcoded sleeps before the dshash_find() that takes an exclusive lock when releasing an entry with some concurrent activity, there was more going on: - A missing entry could be reported as an error at backend exit, error that should not be hit even if the entry was reinitialized and dropped concurrently. - The generation check was not correct for the case of 0 due to the first issue. A generation of 0 refers to an entry that has been freshly created. This commit reworks the entry release to be safer concurrent-wise when an entry targetted for release is found as already existing: - If marked as dropped without refount at 0, free it. - In other cases, ignore it. The entry has been reinitialized or created again with the same key, and is still in use. Sami has posted a basic test case (equivalent added in this commit) that gives a way to reproduce the assertion failure on backend exit, which is a consequence of the incorrect handling of entry releases. Reported-by: Sami Imseih <samimseih.pg@gmail.com> Reviewed-by: Sami Imseih <samimseih.pg@gmail.com> Discussion: https://postgr.es/m/CAN12+YJXE+rEOVo74uM5Ofbj_t_m0DHvd_Mo4ppeHV=aDvvXoQ@mail.gmail.com Backpatch-through: 15 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/8de33427062187903528737bce880324d547feea Modified Files -------------- contrib/test_decoding/t/001_repl_stats.pl | 38 +++++++++++++++++++++++++ src/backend/utils/activity/pgstat_shmem.c | 46 +++++++++++-------------------- 2 files changed, 54 insertions(+), 30 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix cleanup of reused pgstats entries in pgstat_release_entry_re @ 2026-10-21 01:56 Michael Paquier <michael@paquier.xyz> 0 siblings, 0 replies; 6+ messages in thread From: Michael Paquier @ 2026-10-21 01:56 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix cleanup of reused pgstats entries in pgstat_release_entry_ref() When a stats entry is reinitialized and dropped again while a backend still holds a reference from an older generation, the backend releasing the last reference found a generation mismatch and left behind an entry marked as dropped with a refcount of 0. Nothing would free it, and the checkpointer would trigger an assertion at shutdown when flushing the stats. Looking more at the issue, using some hardcoded sleeps before the dshash_find() that takes an exclusive lock when releasing an entry with some concurrent activity, there was more going on: - A missing entry could be reported as an error at backend exit, error that should not be hit even if the entry was reinitialized and dropped concurrently. - The generation check was not correct for the case of 0 due to the first issue. A generation of 0 refers to an entry that has been freshly created. This commit reworks the entry release to be safer concurrent-wise when an entry targetted for release is found as already existing: - If marked as dropped without refount at 0, free it. - In other cases, ignore it. The entry has been reinitialized or created again with the same key, and is still in use. Sami has posted a basic test case (equivalent added in this commit) that gives a way to reproduce the assertion failure on backend exit, which is a consequence of the incorrect handling of entry releases. Reported-by: Sami Imseih <samimseih.pg@gmail.com> Reviewed-by: Sami Imseih <samimseih.pg@gmail.com> Discussion: https://postgr.es/m/CAN12+YJXE+rEOVo74uM5Ofbj_t_m0DHvd_Mo4ppeHV=aDvvXoQ@mail.gmail.com Backpatch-through: 15 Branch ------ REL_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/2c056b37f993a5fb12df37cfc512a25524fb2762 Modified Files -------------- contrib/test_decoding/t/001_repl_stats.pl | 38 +++++++++++++++++++++++++ src/backend/utils/activity/pgstat_shmem.c | 46 +++++++++++-------------------- 2 files changed, 54 insertions(+), 30 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix cleanup of reused pgstats entries in pgstat_release_entry_re @ 2026-10-21 01:56 Michael Paquier <michael@paquier.xyz> 0 siblings, 0 replies; 6+ messages in thread From: Michael Paquier @ 2026-10-21 01:56 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix cleanup of reused pgstats entries in pgstat_release_entry_ref() When a stats entry is reinitialized and dropped again while a backend still holds a reference from an older generation, the backend releasing the last reference found a generation mismatch and left behind an entry marked as dropped with a refcount of 0. Nothing would free it, and the checkpointer would trigger an assertion at shutdown when flushing the stats. Looking more at the issue, using some hardcoded sleeps before the dshash_find() that takes an exclusive lock when releasing an entry with some concurrent activity, there was more going on: - A missing entry could be reported as an error at backend exit, error that should not be hit even if the entry was reinitialized and dropped concurrently. - The generation check was not correct for the case of 0 due to the first issue. A generation of 0 refers to an entry that has been freshly created. This commit reworks the entry release to be safer concurrent-wise when an entry targetted for release is found as already existing: - If marked as dropped without refount at 0, free it. - In other cases, ignore it. The entry has been reinitialized or created again with the same key, and is still in use. Sami has posted a basic test case (equivalent added in this commit) that gives a way to reproduce the assertion failure on backend exit, which is a consequence of the incorrect handling of entry releases. Reported-by: Sami Imseih <samimseih.pg@gmail.com> Reviewed-by: Sami Imseih <samimseih.pg@gmail.com> Discussion: https://postgr.es/m/CAN12+YJXE+rEOVo74uM5Ofbj_t_m0DHvd_Mo4ppeHV=aDvvXoQ@mail.gmail.com Backpatch-through: 15 Branch ------ REL_17_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/1613efa1a5eb2ef68104c64b9aff615887e8e015 Modified Files -------------- contrib/test_decoding/t/001_repl_stats.pl | 38 +++++++++++++++++++++++++ src/backend/utils/activity/pgstat_shmem.c | 46 +++++++++++-------------------- 2 files changed, 54 insertions(+), 30 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix cleanup of reused pgstats entries in pgstat_release_entry_re @ 2026-10-21 01:56 Michael Paquier <michael@paquier.xyz> 0 siblings, 0 replies; 6+ messages in thread From: Michael Paquier @ 2026-10-21 01:56 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix cleanup of reused pgstats entries in pgstat_release_entry_ref() When a stats entry is reinitialized and dropped again while a backend still holds a reference from an older generation, the backend releasing the last reference found a generation mismatch and left behind an entry marked as dropped with a refcount of 0. Nothing would free it, and the checkpointer would trigger an assertion at shutdown when flushing the stats. Looking more at the issue, using some hardcoded sleeps before the dshash_find() that takes an exclusive lock when releasing an entry with some concurrent activity, there was more going on: - A missing entry could be reported as an error at backend exit, error that should not be hit even if the entry was reinitialized and dropped concurrently. - The generation check was not correct for the case of 0 due to the first issue. A generation of 0 refers to an entry that has been freshly created. This commit reworks the entry release to be safer concurrent-wise when an entry targetted for release is found as already existing: - If marked as dropped without refount at 0, free it. - In other cases, ignore it. The entry has been reinitialized or created again with the same key, and is still in use. Sami has posted a basic test case (equivalent added in this commit) that gives a way to reproduce the assertion failure on backend exit, which is a consequence of the incorrect handling of entry releases. Reported-by: Sami Imseih <samimseih.pg@gmail.com> Reviewed-by: Sami Imseih <samimseih.pg@gmail.com> Discussion: https://postgr.es/m/CAN12+YJXE+rEOVo74uM5Ofbj_t_m0DHvd_Mo4ppeHV=aDvvXoQ@mail.gmail.com Backpatch-through: 15 Branch ------ REL_16_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/ae97ef28d8bd82e6af97cfefc3bac5769895de42 Modified Files -------------- contrib/test_decoding/t/001_repl_stats.pl | 38 +++++++++++++++++++++++++ src/backend/utils/activity/pgstat_shmem.c | 46 +++++++++++-------------------- 2 files changed, 54 insertions(+), 30 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix cleanup of reused pgstats entries in pgstat_release_entry_re @ 2026-10-21 01:56 Michael Paquier <michael@paquier.xyz> 0 siblings, 0 replies; 6+ messages in thread From: Michael Paquier @ 2026-10-21 01:56 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix cleanup of reused pgstats entries in pgstat_release_entry_ref() When a stats entry is reinitialized and dropped again while a backend still holds a reference from an older generation, the backend releasing the last reference found a generation mismatch and left behind an entry marked as dropped with a refcount of 0. Nothing would free it, and the checkpointer would trigger an assertion at shutdown when flushing the stats. Looking more at the issue, using some hardcoded sleeps before the dshash_find() that takes an exclusive lock when releasing an entry with some concurrent activity, there was more going on: - A missing entry could be reported as an error at backend exit, error that should not be hit even if the entry was reinitialized and dropped concurrently. - The generation check was not correct for the case of 0 due to the first issue. A generation of 0 refers to an entry that has been freshly created. This commit reworks the entry release to be safer concurrent-wise when an entry targetted for release is found as already existing: - If marked as dropped without refount at 0, free it. - In other cases, ignore it. The entry has been reinitialized or created again with the same key, and is still in use. Sami has posted a basic test case (equivalent added in this commit) that gives a way to reproduce the assertion failure on backend exit, which is a consequence of the incorrect handling of entry releases. Reported-by: Sami Imseih <samimseih.pg@gmail.com> Reviewed-by: Sami Imseih <samimseih.pg@gmail.com> Discussion: https://postgr.es/m/CAN12+YJXE+rEOVo74uM5Ofbj_t_m0DHvd_Mo4ppeHV=aDvvXoQ@mail.gmail.com Backpatch-through: 15 Branch ------ REL_15_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/7a405e5d7846999368dea8179085e6a96adf53a5 Modified Files -------------- contrib/test_decoding/t/001_repl_stats.pl | 38 +++++++++++++++++++++++++ src/backend/utils/activity/pgstat_shmem.c | 46 +++++++++++-------------------- 2 files changed, 54 insertions(+), 30 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2026-10-21 01:56 UTC | newest] Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-10-21 01:56 pgsql: Fix cleanup of reused pgstats entries in pgstat_release_entry_re Michael Paquier <michael@paquier.xyz> 2026-10-21 01:56 pgsql: Fix cleanup of reused pgstats entries in pgstat_release_entry_re Michael Paquier <michael@paquier.xyz> 2026-10-21 01:56 pgsql: Fix cleanup of reused pgstats entries in pgstat_release_entry_re Michael Paquier <michael@paquier.xyz> 2026-10-21 01:56 pgsql: Fix cleanup of reused pgstats entries in pgstat_release_entry_re Michael Paquier <michael@paquier.xyz> 2026-10-21 01:56 pgsql: Fix cleanup of reused pgstats entries in pgstat_release_entry_re Michael Paquier <michael@paquier.xyz> 2026-10-21 01:56 pgsql: Fix cleanup of reused pgstats entries in pgstat_release_entry_re Michael Paquier <michael@paquier.xyz>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox