agora inbox for pgsql-committers@postgresql.orghelp / color / mirror / Atom feed
pgsql: Fix races between deactivation of logical decoding and slot crea 2+ messages / 1 participants [nested] [flat]
* pgsql: Fix races between deactivation of logical decoding and slot crea @ 2026-07-30 19:48 Masahiko Sawada <msawada@postgresql.org> 0 siblings, 0 replies; 2+ messages in thread From: Masahiko Sawada @ 2026-07-30 19:48 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix races between deactivation of logical decoding and slot creation. On standbys, logical decoding can be deactivated while a logical slot is being created: either by replaying an XLOG_LOGICAL_DECODING_STATUS_CHANGE record, or by the end-of-recovery transition upon promotion, which deactivates logical decoding if no valid logical slot exists. Both could interleave with a check of the logical decoding status performed before creating a new slot because the slot invalidation executed as part of the deactivation cannot find a slot being created. For regular slot creation on standbys, EnsureLogicalDecodingEnabled() assumed that logical decoding must still be enabled during recovery since the caller had already checked it, tripping an assertion failure if a concurrent deactivation interleaved. For slot synchronization, the local slot could be created and persisted based on the remote slot information fetched before the deactivation was replayed, leaving a valid slot whose restart_lsn precedes the deactivation. Fix both paths by re-checking the logical decoding status after the new slot has been created: regular slot creation raises an error, and slot synchronization skips persisting the slot. If the deactivation happens after the re-check instead, it is guaranteed to invalidate the newly created slot. Reviewed-by: Srinath Reddy Sadipiralla <srinath2133@gmail.com> Reviewed-by: Amit Kapila <amit.kapila16@gmail.com> Discussion: https://postgr.es/m/CAD21AoDEB99VtNbQdDrNd=1gQupJNGMfW_5kdnxq03Q82EK3ag@mail.gmail.com Backpatch-through: 19 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/6aba42c660cc6634c1c49197b0730f5343ff2589 Modified Files -------------- src/backend/replication/logical/logicalctl.c | 62 ++++++++-- src/backend/replication/logical/slotsync.c | 36 ++++++ src/backend/replication/slot.c | 2 + src/backend/replication/slotfuncs.c | 11 +- src/backend/replication/walsender.c | 4 +- src/test/recovery/t/051_effective_wal_level.pl | 161 +++++++++++++++++++++++++ 6 files changed, 261 insertions(+), 15 deletions(-) ^ permalink raw reply [nested|flat] 2+ messages in thread
* pgsql: Fix races between deactivation of logical decoding and slot crea @ 2026-07-30 19:48 Masahiko Sawada <msawada@postgresql.org> 0 siblings, 0 replies; 2+ messages in thread From: Masahiko Sawada @ 2026-07-30 19:48 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix races between deactivation of logical decoding and slot creation. On standbys, logical decoding can be deactivated while a logical slot is being created: either by replaying an XLOG_LOGICAL_DECODING_STATUS_CHANGE record, or by the end-of-recovery transition upon promotion, which deactivates logical decoding if no valid logical slot exists. Both could interleave with a check of the logical decoding status performed before creating a new slot because the slot invalidation executed as part of the deactivation cannot find a slot being created. For regular slot creation on standbys, EnsureLogicalDecodingEnabled() assumed that logical decoding must still be enabled during recovery since the caller had already checked it, tripping an assertion failure if a concurrent deactivation interleaved. For slot synchronization, the local slot could be created and persisted based on the remote slot information fetched before the deactivation was replayed, leaving a valid slot whose restart_lsn precedes the deactivation. Fix both paths by re-checking the logical decoding status after the new slot has been created: regular slot creation raises an error, and slot synchronization skips persisting the slot. If the deactivation happens after the re-check instead, it is guaranteed to invalidate the newly created slot. Reviewed-by: Srinath Reddy Sadipiralla <srinath2133@gmail.com> Reviewed-by: Amit Kapila <amit.kapila16@gmail.com> Discussion: https://postgr.es/m/CAD21AoDEB99VtNbQdDrNd=1gQupJNGMfW_5kdnxq03Q82EK3ag@mail.gmail.com Backpatch-through: 19 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/6a80179f6b09a6c71a48e864cc4e85f3ea2f4e3c Modified Files -------------- src/backend/replication/logical/logicalctl.c | 62 ++++++++-- src/backend/replication/logical/slotsync.c | 36 ++++++ src/backend/replication/slot.c | 2 + src/backend/replication/slotfuncs.c | 11 +- src/backend/replication/walsender.c | 4 +- src/test/recovery/t/051_effective_wal_level.pl | 161 +++++++++++++++++++++++++ 6 files changed, 261 insertions(+), 15 deletions(-) ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2026-07-30 19:48 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-07-30 19:48 pgsql: Fix races between deactivation of logical decoding and slot crea Masahiko Sawada <msawada@postgresql.org> 2026-07-30 19:48 pgsql: Fix races between deactivation of logical decoding and slot crea Masahiko Sawada <msawada@postgresql.org>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox