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 <[email protected]> Reviewed-by: Surya Poondla <[email protected]> Reviewed-by: Kyotaro Horiguchi <[email protected]> Reviewed-by: Solai V <[email protected]> Reviewed-by: Fujii Masao <[email protected]> Reviewed-by: Xuneng Zhou <[email protected]> Discussion: https://www.postgresql.org/message-id/tencent_A37630454CE614AFE640C56E33B4A0F0AE05%40qq.com Backpatch-through: 15 Branch ------ REL_15_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/f1dc31245cb18e60236086207f2b8ff38d74f403 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(-)
