From fdfc1869fab11b9e01e267ff6d1c001f65f252ed Mon Sep 17 00:00:00 2001 From: Shihao Date: Thu, 1 Oct 2026 22:34:04 -0600 Subject: [PATCH v2 4/4] Test pg_resetwal --cluster-state Check that a bad value is rejected, and that with in-production the state lands in pg_control and the next start empties an unlogged table. Discussion: https://postgr.es/m/ar8mhs05SzC4hjmu@paquier.xyz --- src/bin/pg_resetwal/t/001_basic.pl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/bin/pg_resetwal/t/001_basic.pl b/src/bin/pg_resetwal/t/001_basic.pl index e59355fb396..83df26071b3 100644 --- a/src/bin/pg_resetwal/t/001_basic.pl +++ b/src/bin/pg_resetwal/t/001_basic.pl @@ -225,6 +225,12 @@ command_fails_like( qr/error: invalid argument for option --char-signedness/, 'fails with incorrect --char-signedness option'); +# --cluster-state +command_fails_like( + [ 'pg_resetwal', '--cluster-state', 'foo', $node->data_dir ], + qr/error: invalid argument for option --cluster-state/, + 'fails with incorrect --cluster-state option'); + # run with control override options my $out = (run_command([ 'pg_resetwal', '--dry-run', $node->data_dir ]))[0]; @@ -305,4 +311,20 @@ is( $node->safe_psql( 't', 'new 8-byte OID reported'); +# With a cluster state other than "shut-down", the next start goes through +# crash recovery, which empties unlogged tables. +$node->safe_psql('postgres', + 'CREATE UNLOGGED TABLE unlogged_tab AS SELECT 1 AS a'); +$node->stop; +command_ok( + [ 'pg_resetwal', '--cluster-state' => 'in-production', $node->data_dir ], + 'runs with --cluster-state'); +command_like( + [ 'pg_controldata', $node->data_dir ], + qr/^Database cluster state: *in production$/m, + 'cluster state set in pg_control'); +$node->start; +is($node->safe_psql('postgres', 'SELECT count(*) FROM unlogged_tab'), + '0', 'unlogged table reset after --cluster-state=in-production'); + done_testing(); -- 2.37.1 (Apple Git-137.1)