From a5447a2deaca65c69f1838240f6bdb3ff85c9577 Mon Sep 17 00:00:00 2001 From: Daniel Gustafsson Date: Mon, 28 Sep 2026 17:46:56 +0200 Subject: [PATCH] Fix WAL file selection in 013_rewind test Without an explicit WAL filename, pg_waldump determines the segment size from the first WAL-named directory entry. A preallocated segment with an uninitialized header can make this fail before the checkpoint is read. Pass the WAL filename recorded in backup_label to avoid depending on directory enumeration order. Use command_like() so command failures and stderr are checked rather than appearing only as an empty-output mismatch. This was independently reported by Nazir Bilal Yavuz and Alexander Lakhin. Author: Nazir Bilal Yavuz Reported-by: Nazir Bilal Yavuz Reported-by: Alexander Lakhin Reviewed-by: Zsolt Parragi Reviewed-by: Daniel Gustafsson Discussion: https://postgr.es/m/CAN55FZ1Yak_xBqMaDQsD7atpBkGLEkF-DKXcs3nLHM1Uq4YRew%40mail.gmail.com Discussion: https://postgr.es/m/ffd837c5-dc22-4db1-a2d8-b623cbe9b30c@gmail.com --- .../modules/test_checksums/t/013_rewind.pl | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/test/modules/test_checksums/t/013_rewind.pl b/src/test/modules/test_checksums/t/013_rewind.pl index 21715ace9f3..2cf411e9115 100644 --- a/src/test/modules/test_checksums/t/013_rewind.pl +++ b/src/test/modules/test_checksums/t/013_rewind.pl @@ -151,15 +151,27 @@ $backup_label =~ /^CHECKPOINT LOCATION: ([0-9A-F\/]+)$/m or die "checkpoint location missing from backup_label"; is($1, $shutdown_ckpt, 'replay starts at the switchover checkpoint'); -($stdout, $stderr) = run_command( +# Specify the WAL file so that pg_waldump does not try to determine the +# segment size from an arbitrary, possibly preallocated, file in pg_wal. +# This test would fail if the checkpoint record is straddling two WAL +# segments, if this is ever observed then support for reading the next +# segment as well. +$backup_label =~ + /^START WAL LOCATION: [0-9A-F\/]+ \(file ([0-9A-F]{8})[0-9A-F]{16}\)$/m + or die "WAL file name missing from backup_label"; +my $shutdown_wal = $1 + . $node_b->safe_psql('postgres', + "SELECT substr(pg_walfile_name('$shutdown_ckpt'), 9);"); + +command_like( [ 'pg_waldump', '-p' => $node_a->data_dir . '/pg_wal', - '-t' => 1, '-s' => $shutdown_ckpt, '-n' => 1, - ]); -like($stdout, qr/CHECKPOINT_SHUTDOWN/, + $shutdown_wal, + ], + qr/CHECKPOINT_SHUTDOWN/, 'last common checkpoint is a shutdown checkpoint'); # pg_rewind keeps the target's own checksum state in the control file it