Fix standby logical slot creation while enabling logical decoding. When creating a logical slot during recovery, we reserve WAL from the last replayed position. However, logical decoding can become enabled before the replay position moves past the XLOG_LOGICAL_DECODING_STATUS_CHANGE record that enables it. During replay, the status is changed before the replay position advances to the end of the record. At the end of recovery, the status is changed before the record is even written, and the replay position never moves past it. A logical slot created concurrently in either window could get a restart_lsn preceding the record, and then fail with "unexpected logical decoding status change 1" when decoding it.
Fix by making the restart_lsn of a logical slot created during recovery at least the end LSN of the last record that enabled logical decoding. For this, we now also remember the end LSN of the record written at the end of recovery, and write it while holding LogicalDecodingControlLock so that concurrent slot creation sees it. Oversight in commit 67c20979ce7. Author: Zhijie Hou <[email protected]> Reviewed-by: Masahiko Sawada <[email protected]> Discussion: https://postgr.es/m/[email protected] Backpatch-through: 19 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/4931dab89d35c13a5c2e3e1fe8b31b338a965c73 Modified Files -------------- src/backend/replication/logical/logicalctl.c | 65 +++++++++++++++++++------- src/backend/replication/slot.c | 13 +++++- src/include/replication/logicalctl.h | 1 + src/test/recovery/t/051_effective_wal_level.pl | 59 +++++++++++++++++++++++ 4 files changed, 121 insertions(+), 17 deletions(-)
