From 9290d75aab3471e361529a6bef05d2a965f89775 Mon Sep 17 00:00:00 2001 From: Rahul Yadav Date: Thu, 1 Oct 2026 07:46:25 +0100 Subject: [PATCH v2 2/2] pg_waldump: Report the position of a WAL read error When reading a record fails, pg_waldump prints "error in WAL record at %X/%08X" followed by the reader's message, using ReadRecPtr for the position. ReadRecPtr is the start of the last record read successfully, not the place where reading failed. At the end of WAL, the most common case, the prefix names the last valid record while the message names the end of WAL: error in WAL record at 0/017AC370: invalid record length at 0/017AC3F8: expected at least 24, got 0 Since 3f1ce97346 the same happens when a record is rejected while it is being decoded. Use EndRecPtr instead, the position where the failing record starts, as pg_rewind's extractPageMap() and pg_walinspect already do when XLogReadRecord() fails. Extend the test added by the previous commit to check the prefix too. Author: Rahul Yadav Reviewed-by: Surya Poondla Discussion: https://postgr.es/m/P2qIkq4--F-9@rhyadav.dev --- src/bin/pg_waldump/pg_waldump.c | 2 +- src/bin/pg_waldump/t/001_basic.pl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/pg_waldump/pg_waldump.c b/src/bin/pg_waldump/pg_waldump.c index 6f0574a876..34ca41a7e6 100644 --- a/src/bin/pg_waldump/pg_waldump.c +++ b/src/bin/pg_waldump/pg_waldump.c @@ -1521,7 +1521,7 @@ main(int argc, char **argv) if (errormsg) pg_fatal("error in WAL record at %X/%08X: %s", - LSN_FORMAT_ARGS(xlogreader_state->ReadRecPtr), + LSN_FORMAT_ARGS(xlogreader_state->EndRecPtr), errormsg); /* diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index c345b07ef4..06044d58de 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -612,7 +612,7 @@ my $bad_fpi_error = qr{BKPIMAGE_HAS_HOLE set, but hole offset 0 length \d+ block image length \d+ at \Q$bad_lsn\E}; command_fails_like( [ 'pg_waldump', '--path' => $bad_wal_dir, '--start' => $bad_prev ], - qr{error in WAL record at [0-9A-F]+/[0-9A-F]+: $bad_fpi_error}, + qr{error in WAL record at \Q$bad_lsn\E: $bad_fpi_error}, 'decoding error names the rejected record'); command_fails_like( [ 'pg_waldump', '--path' => $bad_wal_dir, '--start' => $bad_lsn ], -- 2.50.1 (Apple Git-155)