| From: | Masahiko Sawada <msawada(at)postgresql(dot)org> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Fix standby logical slot creation while enabling logical decodin |
| Date: | 2026-11-24 22:23:57 |
| Message-ID: | E1xVyvd-00000000BmE-04CQ@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
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 <houzhijie22(at)gmail(dot)com>
Reviewed-by: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
Discussion: https://postgr.es/m/11c3987c-0be9-4212-8347-9aba81f36580@gmail.com
Backpatch-through: 19
Branch
------
REL_19_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/4c1329da8f36aa92867dc1c20b7c6dff44f19e00
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(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tomas Vondra | 2026-11-24 23:27:20 | pgsql: Correct the parallel GIN merge comment |
| Previous Message | Masahiko Sawada | 2026-11-24 22:23:53 | pgsql: Fix standby logical slot creation while enabling logical decodin |