Commit6aba42c660made 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 commit67c20979cemade 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
PostgreSQL Database Management System
This directory contains the source code distribution of the PostgreSQL database management system.
PostgreSQL is an advanced object-relational database management system that supports an extended subset of the SQL standard, including transactions, foreign keys, subqueries, triggers, user-defined types and functions. This distribution also contains C language bindings.
Copyright and license information can be found in the file COPYRIGHT.
General documentation about this version of PostgreSQL can be found at https://www.postgresql.org/docs/devel/. In particular, information about building PostgreSQL from the source code can be found at https://www.postgresql.org/docs/devel/installation.html.
The latest version of this software, and related software, may be obtained at https://www.postgresql.org/download/. For more information look at our web site located at https://www.postgresql.org/.