2 # Copyright (c) 2021-2022, PostgreSQL Global Development Group
4 # Tests for handling a corrupted pg_control
9 use PostgreSQL
::Test
::Cluster
;
10 use PostgreSQL
::Test
::Utils
;
11 use Test
::More tests
=> 6;
13 my $node = PostgreSQL
::Test
::Cluster
->new('main');
16 my $pg_control = $node->data_dir . '/global/pg_control';
17 my $size = (stat($pg_control))[7];
19 # Read out the head of the file to get PG_CONTROL_VERSION in
22 open my $fh, '<', $pg_control or BAIL_OUT
($!);
27 # Fill pg_control with zeros
28 open $fh, '>', $pg_control or BAIL_OUT
($!);
30 print $fh pack("x[$size]");
34 [ 'pg_resetwal', '-n', $node->data_dir ],
36 [qr/pg_control version number/],
38 qr/pg_resetwal: warning: pg_control exists but is broken or wrong version; ignoring it/
40 'processes corrupted pg_control all zeroes');
42 # Put in the previously saved header data. This uses a different code
43 # path internally, allowing us to process a zero WAL segment size.
44 open $fh, '>', $pg_control or BAIL_OUT
($!);
46 print $fh $data, pack("x[" . ($size - 16) . "]");
50 [ 'pg_resetwal', '-n', $node->data_dir ],
52 [qr/pg_control version number/],
54 qr/\Qpg_resetwal: warning: pg_control specifies invalid WAL segment size (0 bytes); proceed with caution\E/
56 'processes zero WAL segment size');