From 0f061db104907f7a149e04b7a389878f83b535cc Mon Sep 17 00:00:00 2001 From: Michael Paquier 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