pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Fujii Masao <fujii@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: pg_rewind: Fix recovery delays at WAL page boundaries
Date: Fri, 20 Nov 2026 11:44:58 +0000
Message-ID: <E1xUN33-00000000Vp4-2wH1@gemulon.postgresql.org> (raw)

pg_rewind: Fix recovery delays at WAL page boundaries

After pg_rewind, a server restarted as a standby could remain unable
to accept read-only connections until the source generated more WAL,
even after replaying all available records.

The cause was pg_rewind's use of pg_current_wal_insert_lsn() to set
the target's minimum recovery point. At a WAL page boundary, this
function could return a position just past the next page's header.
Without another record to replay, recovery could not reach that
position.

Fix this by using the result of pg_current_wal_flush_lsn(), obtained
after copying the files, as the target's minimum recovery point
instead of pg_current_wal_insert_lsn(). The write-ahead rule ensures
that this position covers all WAL needed to make the copied data
consistent. In particular, after a WAL segment switch, it avoids
requiring recovery to advance past the next segment's header.

Backpatch to all supported versions.

Author: ChangAo Chen <cca5507@qq.com>
Reviewed-by: Surya Poondla <suryapoondla4@gmail.com>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Reviewed-by: Solai V <solai.cdac@gmail.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Xuneng Zhou <xunengzhou@gmail.com>
Discussion: https://www.postgresql.org/message-id/tencent_A37630454CE614AFE640C56E33B4A0F0AE05%40qq.com
Backpatch-through: 15

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/797e50e1aa2eafc669ffcfbcb6fd8ed7be422666

Modified Files
--------------
doc/src/sgml/ref/pg_rewind.sgml   | 13 +++++++------
src/bin/pg_rewind/libpq_source.c  | 12 ++++++------
src/bin/pg_rewind/local_source.c  |  2 +-
src/bin/pg_rewind/pg_rewind.c     | 16 +++++++++++-----
src/bin/pg_rewind/rewind_source.h |  5 +++--
5 files changed, 28 insertions(+), 20 deletions(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1xUN33-00000000Vp4-2wH1@gemulon.postgresql.org>
Permalink:  ../E1xUN33-00000000Vp4-2wH1@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xUN33-00000000Vp4-2wH1@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: fujii@postgresql.org
  Subject: Re: pgsql: pg_rewind: Fix recovery delays at WAL page boundaries
  In-Reply-To: <E1xUN33-00000000Vp4-2wH1@gemulon.postgresql.org>
  References: <E1xUN33-00000000Vp4-2wH1@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