v1-0001-add-regression-tests-for-recovery-target-xid-validation.patch

application/octet-stream

Filename: v1-0001-add-regression-tests-for-recovery-target-xid-validation.patch
Type: application/octet-stream
Part: 0
Message: Re: Improve checks for GUC recovery_target_xid

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch v1-0001
Subject: Add regression tests for recovery_target_xid GUC validation
File+
src/test/recovery/t/003_recovery_targets.pl 18 0
From a8ff58a7564b4db74385d0130530c45dcc6fd5c7 Mon Sep 17 00:00:00 2001
From: Huseyin Demir <huseyin.d3r@gmail.com>
Date: Mon, 16 Mar 2026 08:27:22 +0100
Subject: [PATCH] Add regression tests for recovery_target_xid GUC validation

Add two test cases to src/test/recovery/t/003_recovery_targets.pl that
verify the check_recovery_target_xid GUC hook correctly rejects invalid
values via ALTER SYSTEM:

  - Non-numeric value ('bogus') -> EINVAL from strtou64
  - Overflow value ('99999999999999999999') -> ERANGE from strtou64

Both tests verify the psql return code and the error message pattern.
Using ALTER SYSTEM on the already-running primary node exercises the same
check hook code path as the conf-edit + pg_ctl-start-failure approach
but is simpler and faster (no standby node creation needed).
---
 src/test/recovery/t/003_recovery_targets.pl | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/test/recovery/t/003_recovery_targets.pl b/src/test/recovery/t/003_recovery_targets.pl
index e0df1a23423..aba0da150dd 100644
--- a/src/test/recovery/t/003_recovery_targets.pl
+++ b/src/test/recovery/t/003_recovery_targets.pl
@@ -240,4 +240,22 @@ ok(!$res, 'invalid timeline target (upper bound check)');
 $log_start =
   $node_standby->wait_for_log("must be between 1 and 4294967295", $log_start);
 
+# Invalid recovery_target_xid via ALTER SYSTEM (non-numeric)
+my $stderr = '';
+$ret = $node_primary->psql('postgres',
+	"ALTER SYSTEM SET recovery_target_xid = 'bogus'",
+	stderr => \$stderr);
+ok($ret != 0, 'ALTER SYSTEM rejects non-numeric recovery_target_xid');
+like($stderr, qr/invalid value for parameter "recovery_target_xid"/,
+	'error message for non-numeric XID value');
+
+# Invalid recovery_target_xid via ALTER SYSTEM (overflow)
+$stderr = '';
+$ret = $node_primary->psql('postgres',
+	"ALTER SYSTEM SET recovery_target_xid = '99999999999999999999'",
+	stderr => \$stderr);
+ok($ret != 0, 'ALTER SYSTEM rejects overflow recovery_target_xid');
+like($stderr, qr/invalid value for parameter "recovery_target_xid"/,
+	'error message for overflow XID value');
+
 done_testing();
-- 
2.50.1 (Apple Git-155)