From 5173bfd0443e0c0f3fa37006727d516dc1ba4cee Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Sat, 25 Oct 2025 09:07:31 +0900 Subject: 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 Author: Justin Kwan Reviewed-by: Robert Haas Reviewed-by: Alexander Korotkov Reviewed-by: Japin Li Reviewed-by: Michael Paquier Reviewed-by: Srinath Reddy Sadipiralla Discussion: https://postgr.es/m/181b4c6fa9c.b8b725681941212.7547232617810891479@viggy28.dev --- doc/src/sgml/ref/pg_rewind.sgml | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/ref/pg_rewind.sgml b/doc/src/sgml/ref/pg_rewind.sgml index 5485033ed8c..928e78cda33 100644 --- a/doc/src/sgml/ref/pg_rewind.sgml +++ b/doc/src/sgml/ref/pg_rewind.sgml @@ -52,12 +52,32 @@ PostgreSQL documentation analogous to a base backup of the source data directory. Unlike taking a new base backup or using a tool like rsync, pg_rewind does not require comparing or copying - unchanged relation blocks in the cluster. Only changed blocks from existing - relation files are copied; all other files, including new relation files, - configuration files, and WAL segments, are copied in full. As such the - rewind operation is significantly faster than other approaches when the - database is large and only a small fraction of blocks differ between the - clusters. + unchanged relation blocks in the cluster: + + + + + Only changed blocks from existing relation files are copied. + + + + + WAL segments prior to the point where the source and target servers + have diverged are not copied. WAL segments generated after the source + and target servers have diverged are copied in full. + + + + + All other files, including new relation files and configuration files, + are copied in full. + + + + + As such, the rewind operation is significantly faster than other + approaches when the database is large and only a small fraction of blocks + differ between the clusters. -- cgit v1.2.3