pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix slotsync when logical decoding is disabled and re-enabled.
2+ messages / 1 participants
[nested] [flat]

* pgsql: Fix slotsync when logical decoding is disabled and re-enabled.
@ 2026-10-07 18:56 Masahiko Sawada <msawada@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Masahiko Sawada @ 2026-10-07 18:56 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix slotsync when logical decoding is disabled and re-enabled.

Commit 6aba42c660c made slot synchronization skip persisting a new
slot if logical decoding got disabled after the remote slot
information was fetched. As noted in its XXX comment, the check
missed the case where the last logical slot on the primary is dropped
and re-created with the same name in the meantime. If the standby had
replayed both the deactivation and the re-activation by then, the
slot was persisted with a restart_lsn preceding the deactivation.
Subsequent synchronization cycles failed with "unexpected logical
decoding status change" when advancing the slot, which also stopped
the synchronization of all other failover slots, and the slot could
not be decoded after promotion.

Fix this by remembering the end LSN of the last replayed
XLOG_LOGICAL_DECODING_STATUS_CHANGE record that enables logical
decoding, and by requiring the remote restart_lsn to be at or after it
right after creating the local slot. The check is skipped until replay
reaches the remote restart_lsn, as we can't tell anything about WAL that
hasn't been replayed yet. Once the slot exists, a later deactivation
invalidates it, so remove the check before persisting the slot. We
compare the remote restart_lsn rather than the local one, so we may drop
a slot that would have been usable, but the retry in the next
synchronization cycle fetches fresh information.

Backpatch to v19, where commit 67c20979ce7 made logical decoding toggle
dynamically.

Reported-by: Nikolay Samokhvalov <nik@postgres.ai>
Reviewed-by: shveta malik <shveta.malik@gmail.com>
Reviewed-by: Nisha Moond <nisha.moond412@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Zhijie Hou <houzhijie22@gmail.com>
Discussion: https://postgr.es/m/CAM527d_eV_BAYFiQnfZLSPfHoihye=nOi-OnAM_57pdH+F+gfA@mail.gmail.com
Backpatch-through: 19

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/1f2245371e31f0def347546f5ad250552a4eb8a4

Modified Files
--------------
src/backend/access/transam/xlog.c              |  2 +-
src/backend/replication/logical/logicalctl.c   | 62 ++++++++++++++++-
src/backend/replication/logical/slotsync.c     | 93 ++++++++++++++++----------
src/include/replication/logicalctl.h           |  5 +-
src/test/recovery/t/051_effective_wal_level.pl | 80 ++++++++++++++++++++++
5 files changed, 203 insertions(+), 39 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* pgsql: Fix slotsync when logical decoding is disabled and re-enabled.
@ 2026-10-07 18:56 Masahiko Sawada <msawada@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Masahiko Sawada @ 2026-10-07 18:56 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix slotsync when logical decoding is disabled and re-enabled.

Commit 6aba42c660c made slot synchronization skip persisting a new
slot if logical decoding got disabled after the remote slot
information was fetched. As noted in its XXX comment, the check
missed the case where the last logical slot on the primary is dropped
and re-created with the same name in the meantime. If the standby had
replayed both the deactivation and the re-activation by then, the
slot was persisted with a restart_lsn preceding the deactivation.
Subsequent synchronization cycles failed with "unexpected logical
decoding status change" when advancing the slot, which also stopped
the synchronization of all other failover slots, and the slot could
not be decoded after promotion.

Fix this by remembering the end LSN of the last replayed
XLOG_LOGICAL_DECODING_STATUS_CHANGE record that enables logical
decoding, and by requiring the remote restart_lsn to be at or after it
right after creating the local slot. The check is skipped until replay
reaches the remote restart_lsn, as we can't tell anything about WAL that
hasn't been replayed yet. Once the slot exists, a later deactivation
invalidates it, so remove the check before persisting the slot. We
compare the remote restart_lsn rather than the local one, so we may drop
a slot that would have been usable, but the retry in the next
synchronization cycle fetches fresh information.

Backpatch to v19, where commit 67c20979ce7 made logical decoding toggle
dynamically.

Reported-by: Nikolay Samokhvalov <nik@postgres.ai>
Reviewed-by: shveta malik <shveta.malik@gmail.com>
Reviewed-by: Nisha Moond <nisha.moond412@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Zhijie Hou <houzhijie22@gmail.com>
Discussion: https://postgr.es/m/CAM527d_eV_BAYFiQnfZLSPfHoihye=nOi-OnAM_57pdH+F+gfA@mail.gmail.com
Backpatch-through: 19

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/3f5bfbce4c471aaffc8711090483460316728344

Modified Files
--------------
src/backend/access/transam/xlog.c              |  2 +-
src/backend/replication/logical/logicalctl.c   | 62 ++++++++++++++++-
src/backend/replication/logical/slotsync.c     | 93 ++++++++++++++++----------
src/include/replication/logicalctl.h           |  5 +-
src/test/recovery/t/051_effective_wal_level.pl | 80 ++++++++++++++++++++++
5 files changed, 203 insertions(+), 39 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2026-10-07 18:56 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-10-07 18:56 pgsql: Fix slotsync when logical decoding is disabled and re-enabled. Masahiko Sawada <msawada@postgresql.org>
2026-10-07 18:56 pgsql: Fix slotsync when logical decoding is disabled and re-enabled. Masahiko Sawada <msawada@postgresql.org>

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