pgsql: pg_rewind: Skip copy of WAL segments generated before point of d

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: pg_rewind: Skip copy of WAL segments generated before point of d
Date: 2025-10-25 00:10:24
Message-ID: E1vCRrU-003MGe-2d@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

pg_rewind: Skip copy of WAL segments generated before point of divergence

This commit makes the way WAL segments are handled from the source to
the target server slightly smarter: the copy of the WAL segments is now
skipped if these have been created before the point where source and
target have diverged (the WAL segment where the point of divergence
exists is still copied), because we know that such segments exist on
both the target and source. Note that the on-disk size of the WAL
segments on the source and target need to match. Hence, only the
segments generated after the point of divergence are now copied. A
segment existing on the source but not the target is copied.

Previously, all the WAL segments were just copied in full. This change
can make the rewind operation cheaper in some configurations, especially
for setups where some WAL retention causes many segments to remain on
the source server even after the promotion of a standby used as source
to rewind a previous primary.

A TAP test is added to track these new behaviors. The file map printed
with --debug now includes all the information related to WAL segments,
to be able to track if these are copied or skipped, and the test relies
on the debug output generated.

Author: John Hsu <johnhyvr(at)gmail(dot)com>
Author: Justin Kwan <justinpkwan(at)outlook(dot)com>
Reviewed-by: Robert Haas <robertmhaas(at)gmail(dot)com>
Reviewed-by: Alexander Korotkov <aekorotkov(at)gmail(dot)com>
Reviewed-by: Japin Li <japinli(at)hotmail(dot)com>
Reviewed-by: Michael Paquier <michael(at)paquier(dot)xyz>
Reviewed-by: Srinath Reddy Sadipiralla <srinath2133(at)gmail(dot)com>
Discussion: https://postgr.es/m/181b4c6fa9c.b8b725681941212.7547232617810891479@viggy28.dev

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/5173bfd0443e0c0f3fa37006727d516dc1ba4cee

Modified Files
--------------
doc/src/sgml/ref/pg_rewind.sgml | 32 ++++++++--
src/bin/pg_rewind/filemap.c | 55 ++++++++++++++--
src/bin/pg_rewind/filemap.h | 3 +-
src/bin/pg_rewind/meson.build | 1 +
src/bin/pg_rewind/pg_rewind.c | 9 ++-
src/bin/pg_rewind/t/011_wal_copy.pl | 122 ++++++++++++++++++++++++++++++++++++
6 files changed, 209 insertions(+), 13 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Dean Rasheed 2025-10-25 10:11:16 pgsql: Guard against division by zero in test_int128 module.
Previous Message Fujii Masao 2025-10-24 05:31:50 pgsql: psql: Improve tab completion for large objects.