| From: | Fujii Masao <fujii(at)postgresql(dot)org> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: pg_rewind: Fix recovery delays at WAL page boundaries |
| Date: | 2026-11-20 11:44:58 |
| Message-ID: | E1xUN33-00000000Vp4-2wH1@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
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(at)qq(dot)com>
Reviewed-by: Surya Poondla <suryapoondla4(at)gmail(dot)com>
Reviewed-by: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
Reviewed-by: Solai V <solai(dot)cdac(at)gmail(dot)com>
Reviewed-by: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Reviewed-by: Xuneng Zhou <xunengzhou(at)gmail(dot)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(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Heikki Linnakangas | 2026-11-20 15:10:32 | pgsql: Always prune dead members in MultiXactIdExpand, to fix assertion |
| Previous Message | Fujii Masao | 2026-11-20 11:31:23 | pgsql: pg_receivewal: Fix resource leaks and error reporting during cle |