]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Improve tests for recovery_target_timeline GUC.
authorFujii Masao <fujii@postgresql.org>
Fri, 6 Mar 2026 07:02:09 +0000 (16:02 +0900)
committerFujii Masao <fujii@postgresql.org>
Fri, 6 Mar 2026 07:02:57 +0000 (16:02 +0900)
Commit fd7d7b71913 added regression tests to verify recovery_target_timeline
settings. To confirm that invalid values are rejected, those tests started the
server with an invalid setting and then verified that startup failed. While
functionally correct, this approach was expensive because it required
setting up and starting the server for each test case.

This commit updates the tests for recovery_target_timeline to use
the simpler approach introduced by commit bffd7130 for recovery_target_xid,
using ALTER SYSTEM SET to verify that invalid settings are rejected.
This avoids the need to set up and start the server when checking invalid
recovery_target_timeline values.

Author: David Steele <david@pgbackrest.org>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/CAHGQGwG44vZbSoBmg076G+xkR6n=Tj2=q+fVkfP7yEsyF1daFA@mail.gmail.com

src/test/recovery/t/003_recovery_targets.pl

index 4e36e3a3fb5a6a2f790fb22db2f358f1bddd6413..047eb13293ae39541cb75fc76976308167ac8638 100644 (file)
@@ -190,58 +190,30 @@ like(
        qr/FATAL: .* recovery ended before configured recovery target was reached/,
        'recovery end before target reached is a fatal error');
 
-# Invalid timeline target
-$node_standby = PostgreSQL::Test::Cluster->new('standby_9');
-$node_standby->init_from_backup($node_primary, 'my_backup',
-       has_restoring => 1);
-$node_standby->append_conf('postgresql.conf',
-       "recovery_target_timeline = 'bogus'");
-
-$res = run_log(
-       [
-               'pg_ctl',
-               '--pgdata' => $node_standby->data_dir,
-               '--log' => $node_standby->logfile,
-               'start',
-       ]);
-ok(!$res, 'invalid timeline target (bogus value)');
-
-my $log_start = $node_standby->wait_for_log("is not a valid number");
-
-# Timeline target out of min range
-$node_standby->append_conf('postgresql.conf',
-       "recovery_target_timeline = '0'");
-
-$res = run_log(
-       [
-               'pg_ctl',
-               '--pgdata' => $node_standby->data_dir,
-               '--log' => $node_standby->logfile,
-               'start',
-       ]);
-ok(!$res, 'invalid timeline target (lower bound check)');
-
-$log_start =
-  $node_standby->wait_for_log("must be between 1 and 4294967295", $log_start);
-
-# Timeline target out of max range
-$node_standby->append_conf('postgresql.conf',
-       "recovery_target_timeline = '4294967296'");
+# Invalid recovery_target_timeline tests
+my ($result, $stdout, $stderr) = $node_primary->psql('postgres',
+       "ALTER SYSTEM SET recovery_target_timeline TO 'bogus'");
+like(
+       $stderr,
+       qr/is not a valid number/,
+       "invalid recovery_target_timeline (bogus value)");
 
-$res = run_log(
-       [
-               'pg_ctl',
-               '--pgdata' => $node_standby->data_dir,
-               '--log' => $node_standby->logfile,
-               'start',
-       ]);
-ok(!$res, 'invalid timeline target (upper bound check)');
+($result, $stdout, $stderr) = $node_primary->psql('postgres',
+       "ALTER SYSTEM SET recovery_target_timeline TO '0'");
+like(
+       $stderr,
+       qr/must be between 1 and 4294967295/,
+       "invalid recovery_target_timeline (lower bound check)");
 
-$log_start =
-  $node_standby->wait_for_log("must be between 1 and 4294967295", $log_start);
+($result, $stdout, $stderr) = $node_primary->psql('postgres',
+       "ALTER SYSTEM SET recovery_target_timeline TO '4294967296'");
+like(
+       $stderr,
+       qr/must be between 1 and 4294967295/,
+       "invalid recovery_target_timeline (upper bound check)");
 
 # Invalid recovery_target_xid tests
-my ($result, $stdout, $stderr) = $node_primary->psql('postgres',
+($result, $stdout, $stderr) = $node_primary->psql('postgres',
        "ALTER SYSTEM SET recovery_target_xid TO 'bogus'");
 like(
        $stderr,