pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Masahiko Sawada <msawada@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix standby logical slot creation while enabling logical decodin
Date: Tue, 24 Nov 2026 22:23:53 +0000
Message-ID: <E1xVyvZ-00000000BlX-0Te7@gemulon.postgresql.org> (raw)

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@gmail.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Discussion: https://postgr.es/m/11c3987c-0be9-4212-8347-9aba81f36580@gmail.com
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(-)



view thread (2+ messages)  latest in thread

Message-ID: <E1xVyvZ-00000000BlX-0Te7@gemulon.postgresql.org>
Permalink:  ../E1xVyvZ-00000000BlX-0Te7@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xVyvZ-00000000BlX-0Te7@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: msawada@postgresql.org
  Subject: Re: pgsql: Fix standby logical slot creation while enabling logical decodin
  In-Reply-To: <E1xVyvZ-00000000BlX-0Te7@gemulon.postgresql.org>
  References: <E1xVyvZ-00000000BlX-0Te7@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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