On Fri, Jun 26, 2026 at 12:29:38PM +0530, Nitin Jadhav wrote:
> I went ahead and reworked this to avoid duplication by grouping the
> new coverage into the existing tests that already carry most of the
> setup.

Thanks for that.  As promised previously, I have put my mind on this
proposal.

> For the missing-redo path, as discussed above, I added the
> backup_label variant to t/050_redo_segment_missing.pl. 050 already has
> the injection-point setup needed to split redo and checkpoint records
> across WAL segments, so reusing it avoids duplicating that
> orchestration elsewhere.

The refactoring for run_split_checkpoint() and checkpoint_wal_info()
could be a patch of its own, mainly for clarity to as you have wanted
to introduce them for the purpose of the second test.

Hmm, actually..  I am wondering if this could be made simpler by
writing a fully-synthetic backup_label file instead, meaning that we
would not need the dance with the injection points because we could
reuse the redo and checkpoint LSNs of the previous step, then we just
add the checkpoint segment to the starting node's pg_wal/.  I admit
that it feels artistic, but it is much less complicated than your
version, more efficient, and would still check the error path we care
about.

Nitin, what do you think about the attached?

> For the missing-checkpoint path, I added the backup_label variant to
> t/042_low_level_backup.pl. 042 already owns the low-level-backup +
> backup_label setup, so it seemed like the natural place. 052 remains
> focused on the no-backup_label checkpoint-missing path.

This one is much simpler compared to the other one, relying on the
removal of pg_wal/ in the initial backup taken from the primary.  I
have made the FATAL's regexp a bit more portable, moved the new SQL
query to get the redo segment to be just after the checkpoint
execution, and applied this part.
--
Michael
From 0f061db104907f7a149e04b7a389878f83b535cc Mon Sep 17 00:00:00 2001
From: Michael Paquier <[email protected]>
Date: Mon, 13 Jul 2026 09:53:37 +0900
Subject: [PATCH v3] Add recovery test for missing redo segment and
 backup_label

This tests the case of a valid checkpoint segment where the redo segment
is missing, something not covered yet.

Perhaps more blah.
---
 .../recovery/t/050_redo_segment_missing.pl    | 44 +++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/src/test/recovery/t/050_redo_segment_missing.pl 
b/src/test/recovery/t/050_redo_segment_missing.pl
index e07ff0c72fee..16b83d51d012 100644
--- a/src/test/recovery/t/050_redo_segment_missing.pl
+++ b/src/test/recovery/t/050_redo_segment_missing.pl
@@ -6,6 +6,7 @@
 
 use strict;
 use warnings FATAL => 'all';
+use File::Copy qw(copy);
 use PostgreSQL::Test::Cluster;
 use PostgreSQL::Test::Utils;
 use Test::More;
@@ -114,4 +115,47 @@ ok( $logfile =~
          qr/FATAL: .* could not find redo location .* referenced by checkpoint 
record at .*/,
        "ends with FATAL because it could not find redo location");
 
+# Test for a missing redo record specified in a backup_label file.
+# This reuses the redo and checkpoint LSNs calculated previously and
+# writes a fake backup_label into a fresh node.
+my $node_label = PostgreSQL::Test::Cluster->new('testnode_backup_label');
+$node_label->init;
+$node_label->append_conf('postgresql.conf', "archive_mode = off");
+
+# Copy pg_control from the original node so the new node recognizes the
+# system identifier and timeline.
+copy(
+       $node->data_dir . '/global/pg_control',
+       $node_label->data_dir . '/global/pg_control'
+) or BAIL_OUT("could not copy pg_control");
+
+# Provide only the checkpoint segment, omitting the redo segment.
+copy(
+       $node->data_dir . "/pg_wal/$checkpoint_walfile_name",
+       $node_label->data_dir . "/pg_wal/$checkpoint_walfile_name"
+) or BAIL_OUT("could not copy checkpoint WAL segment");
+
+# Write a fake backup_label with valid checkpoint and redo LSNs.
+open my $fh, '>', $node_label->data_dir . '/backup_label'
+  or BAIL_OUT("could not create backup_label");
+binmode $fh;
+print $fh "START WAL LOCATION: $redo_lsn (file $redo_walfile_name)\n";
+print $fh "CHECKPOINT LOCATION: $checkpoint_lsn\n";
+print $fh "BACKUP METHOD: pg_backup_start\n";
+print $fh "BACKUP FROM: primary\n";
+close $fh;
+
+run_log(
+       [
+               'pg_ctl',
+               '--pgdata' => $node_label->data_dir,
+               '--log' => $node_label->logfile,
+               'start',
+       ]);
+
+my $logfile_label = slurp_file($node_label->logfile());
+ok( $logfile_label =~
+         qr/FATAL: .* could not find redo location .* referenced by checkpoint 
record at .*/,
+       "ends with FATAL for missing redo location with backup_label");
+
 done_testing();
-- 
2.55.0

Attachment: signature.asc
Description: PGP signature

Reply via email to