1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-15 02:22:24 +03:00

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@gmail.com>
Author: Justin Kwan <justinpkwan@outlook.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Japin Li <japinli@hotmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Srinath Reddy Sadipiralla <srinath2133@gmail.com>
Discussion: https://postgr.es/m/181b4c6fa9c.b8b725681941212.7547232617810891479@viggy28.dev
This commit is contained in:
Michael Paquier
2025-10-25 09:07:31 +09:00
parent 14ee8e6403
commit 5173bfd044
6 changed files with 209 additions and 13 deletions

View File

@@ -147,6 +147,7 @@ main(int argc, char **argv)
TimeLineID source_tli;
TimeLineID target_tli;
XLogRecPtr target_wal_endrec;
XLogSegNo last_common_segno;
size_t size;
char *buffer;
bool no_ensure_shutdown = false;
@@ -397,6 +398,12 @@ main(int argc, char **argv)
LSN_FORMAT_ARGS(divergerec),
targetHistory[lastcommontliIndex].tli);
/*
* Convert the divergence LSN to a segment number, that will be used
* to decide how WAL segments should be processed.
*/
XLByteToSeg(divergerec, last_common_segno, ControlFile_target.xlog_seg_size);
/*
* Don't need the source history anymore. The target history is still
* needed by the routines in parsexlog.c, when we read the target WAL.
@@ -492,7 +499,7 @@ main(int argc, char **argv)
* We have collected all information we need from both systems. Decide
* what to do with each file.
*/
filemap = decide_file_actions();
filemap = decide_file_actions(last_common_segno);
if (showprogress)
calculate_totals(filemap);