1414# at the end.
1515sub check_relation_corruption
1616{
17- my $node = shift ;
18- my $table = shift ;
17+ my $node = shift ;
18+ my $table = shift ;
1919 my $tablespace = shift ;
20- my $pgdata = $node -> data_dir;
20+ my $pgdata = $node -> data_dir;
2121
22- $node -> safe_psql(' postgres' ,
22+ $node -> safe_psql(
23+ ' postgres' ,
2324 " SELECT a INTO $table FROM generate_series(1,10000) AS a;
2425 ALTER TABLE $table SET (autovacuum_enabled=false);" );
2526
2627 $node -> safe_psql(' postgres' ,
27- " ALTER TABLE " . $table . " SET TABLESPACE " . $tablespace . " ;" );
28+ " ALTER TABLE " . $table . " SET TABLESPACE " . $tablespace . " ;" );
2829
29- my $file_corrupted = $node -> safe_psql( ' postgres ' ,
30- " SELECT pg_relation_filepath('$table ');" );
31- my $relfilenode_corrupted = $node -> safe_psql(' postgres' ,
30+ my $file_corrupted =
31+ $node -> safe_psql( ' postgres ' , " SELECT pg_relation_filepath('$table ');" );
32+ my $relfilenode_corrupted = $node -> safe_psql(' postgres' ,
3233 " SELECT relfilenode FROM pg_class WHERE relname = '$table ';" );
3334
3435 # Set page header and block size
@@ -38,9 +39,14 @@ sub check_relation_corruption
3839
3940 # Checksums are correct for single relfilenode as the table is not
4041 # corrupted yet.
41- command_ok([' pg_checksums' , ' --check' , ' -D' , $pgdata , ' -r' ,
42- $relfilenode_corrupted ],
43- " succeeds for single relfilenode on tablespace $tablespace with offline cluster" );
42+ command_ok(
43+ [
44+ ' pg_checksums' , ' --check' ,
45+ ' -D' , $pgdata ,
46+ ' -r' , $relfilenode_corrupted
47+ ],
48+ " succeeds for single relfilenode on tablespace $tablespace with offline cluster"
49+ );
4450
4551 # Time to create some corruption
4652 open my $file , ' +<' , " $pgdata /$file_corrupted " ;
@@ -49,26 +55,32 @@ sub check_relation_corruption
4955 close $file ;
5056
5157 # Checksum checks on single relfilenode fail
52- $node -> command_checks_all([ ' pg_checksums' , ' --check' , ' -D' , $pgdata ,
53- ' -r' , $relfilenode_corrupted ],
54- 1,
55- [qr / Bad checksums:.*1/ ],
56- [qr / checksum verification failed/ ],
57- " fails with corrupted data for single relfilenode on tablespace $tablespace " );
58+ $node -> command_checks_all(
59+ [
60+ ' pg_checksums' , ' --check' ,
61+ ' -D' , $pgdata ,
62+ ' -r' , $relfilenode_corrupted
63+ ],
64+ 1,
65+ [qr / Bad checksums:.*1/ ],
66+ [qr / checksum verification failed/ ],
67+ " fails with corrupted data for single relfilenode on tablespace $tablespace "
68+ );
5869
5970 # Global checksum checks fail as well
60- $node -> command_checks_all([ ' pg_checksums' , ' --check' , ' -D' , $pgdata ],
61- 1,
62- [qr / Bad checksums:.*1/ ],
63- [qr / checksum verification failed/ ],
64- " fails with corrupted data on tablespace $tablespace " );
71+ $node -> command_checks_all(
72+ [ ' pg_checksums' , ' --check' , ' -D' , $pgdata ],
73+ 1,
74+ [qr / Bad checksums:.*1/ ],
75+ [qr / checksum verification failed/ ],
76+ " fails with corrupted data on tablespace $tablespace " );
6577
6678 # Drop corrupted table again and make sure there is no more corruption.
6779 $node -> start;
6880 $node -> safe_psql(' postgres' , " DROP TABLE $table ;" );
6981 $node -> stop;
70- $node -> command_ok([' pg_checksums' , ' --check' , ' -D' , $pgdata ],
71- " succeeds again after table drop on tablespace $tablespace " );
82+ $node -> command_ok([ ' pg_checksums' , ' --check' , ' -D' , $pgdata ],
83+ " succeeds again after table drop on tablespace $tablespace " );
7284
7385 $node -> start;
7486 return ;
@@ -80,19 +92,20 @@ sub check_relation_corruption
8092my $pgdata = $node -> data_dir;
8193
8294# Control file should know that checksums are disabled.
83- command_like([' pg_controldata' , $pgdata ],
84- qr / Data page checksum version:.*0/ ,
85- ' checksums disabled in control file' );
95+ command_like(
96+ [ ' pg_controldata' , $pgdata ],
97+ qr / Data page checksum version:.*0/ ,
98+ ' checksums disabled in control file' );
8699
87100# These are correct but empty files, so they should pass through.
88- append_to_file " $pgdata /global/99999" , " " ;
89- append_to_file " $pgdata /global/99999.123" , " " ;
90- append_to_file " $pgdata /global/99999_fsm" , " " ;
91- append_to_file " $pgdata /global/99999_init" , " " ;
92- append_to_file " $pgdata /global/99999_vm" , " " ;
101+ append_to_file " $pgdata /global/99999" , " " ;
102+ append_to_file " $pgdata /global/99999.123" , " " ;
103+ append_to_file " $pgdata /global/99999_fsm" , " " ;
104+ append_to_file " $pgdata /global/99999_init" , " " ;
105+ append_to_file " $pgdata /global/99999_vm" , " " ;
93106append_to_file " $pgdata /global/99999_init.123" , " " ;
94- append_to_file " $pgdata /global/99999_fsm.123" , " " ;
95- append_to_file " $pgdata /global/99999_vm.123" , " " ;
107+ append_to_file " $pgdata /global/99999_fsm.123" , " " ;
108+ append_to_file " $pgdata /global/99999_vm.123" , " " ;
96109
97110# These are temporary files and folders with dummy contents, which
98111# should be ignored by the scan.
@@ -101,67 +114,75 @@ sub check_relation_corruption
101114append_to_file " $pgdata /global/pgsql_tmp/1.1" , " foo" ;
102115
103116# Enable checksums.
104- command_ok([' pg_checksums' , ' --enable' , ' --no-sync' , ' -D' , $pgdata ],
105- " checksums successfully enabled in cluster" );
117+ command_ok([ ' pg_checksums' , ' --enable' , ' --no-sync' , ' -D' , $pgdata ],
118+ " checksums successfully enabled in cluster" );
106119
107120# Successive attempt to enable checksums fails.
108- command_fails([' pg_checksums' , ' --enable' , ' --no-sync' , ' -D' , $pgdata ],
109- " enabling checksums fails if already enabled" );
121+ command_fails([ ' pg_checksums' , ' --enable' , ' --no-sync' , ' -D' , $pgdata ],
122+ " enabling checksums fails if already enabled" );
110123
111124# Control file should know that checksums are enabled.
112- command_like([' pg_controldata' , $pgdata ],
113- qr / Data page checksum version:.*1/ ,
114- ' checksums enabled in control file' );
125+ command_like(
126+ [ ' pg_controldata' , $pgdata ],
127+ qr / Data page checksum version:.*1/ ,
128+ ' checksums enabled in control file' );
115129
116130# Disable checksums again. Flush result here as that should be cheap.
117- command_ok([' pg_checksums' , ' --disable' , ' -D' , $pgdata ],
118- " checksums successfully disabled in cluster" );
131+ command_ok(
132+ [ ' pg_checksums' , ' --disable' , ' -D' , $pgdata ],
133+ " checksums successfully disabled in cluster" );
119134
120135# Successive attempt to disable checksums fails.
121- command_fails([' pg_checksums' , ' --disable' , ' --no-sync' , ' -D' , $pgdata ],
122- " disabling checksums fails if already disabled" );
136+ command_fails(
137+ [ ' pg_checksums' , ' --disable' , ' --no-sync' , ' -D' , $pgdata ],
138+ " disabling checksums fails if already disabled" );
123139
124140# Control file should know that checksums are disabled.
125- command_like([' pg_controldata' , $pgdata ],
126- qr / Data page checksum version:.*0/ ,
127- ' checksums disabled in control file' );
141+ command_like(
142+ [ ' pg_controldata' , $pgdata ],
143+ qr / Data page checksum version:.*0/ ,
144+ ' checksums disabled in control file' );
128145
129146# Enable checksums again for follow-up tests.
130- command_ok([' pg_checksums' , ' --enable' , ' --no-sync' , ' -D' , $pgdata ],
131- " checksums successfully enabled in cluster" );
147+ command_ok([ ' pg_checksums' , ' --enable' , ' --no-sync' , ' -D' , $pgdata ],
148+ " checksums successfully enabled in cluster" );
132149
133150# Control file should know that checksums are enabled.
134- command_like([' pg_controldata' , $pgdata ],
135- qr / Data page checksum version:.*1/ ,
136- ' checksums enabled in control file' );
151+ command_like(
152+ [ ' pg_controldata' , $pgdata ],
153+ qr / Data page checksum version:.*1/ ,
154+ ' checksums enabled in control file' );
137155
138156# Checksums pass on a newly-created cluster
139- command_ok([' pg_checksums' , ' --check' , ' -D' , $pgdata ],
140- " succeeds with offline cluster" );
157+ command_ok([ ' pg_checksums' , ' --check' , ' -D' , $pgdata ],
158+ " succeeds with offline cluster" );
141159
142160# Checksums are verified if no other arguments are specified
143- command_ok([' pg_checksums' , ' -D' , $pgdata ],
144- " verifies checksums as default action" );
161+ command_ok(
162+ [ ' pg_checksums' , ' -D' , $pgdata ],
163+ " verifies checksums as default action" );
145164
146165# Specific relation files cannot be requested when action is --disable
147166# or --enable.
148- command_fails([' pg_checksums' , ' --disable' , ' -r' , ' 1234' , ' -D' , $pgdata ],
149- " fails when relfilenodes are requested and action is --disable" );
150- command_fails([' pg_checksums' , ' --enable' , ' -r' , ' 1234' , ' -D' , $pgdata ],
151- " fails when relfilenodes are requested and action is --enable" );
167+ command_fails(
168+ [ ' pg_checksums' , ' --disable' , ' -r' , ' 1234' , ' -D' , $pgdata ],
169+ " fails when relfilenodes are requested and action is --disable" );
170+ command_fails(
171+ [ ' pg_checksums' , ' --enable' , ' -r' , ' 1234' , ' -D' , $pgdata ],
172+ " fails when relfilenodes are requested and action is --enable" );
152173
153174# Checks cannot happen with an online cluster
154175$node -> start;
155- command_fails([' pg_checksums' , ' --check' , ' -D' , $pgdata ],
156- " fails with online cluster" );
176+ command_fails([ ' pg_checksums' , ' --check' , ' -D' , $pgdata ],
177+ " fails with online cluster" );
157178
158179# Check corruption of table on default tablespace.
159180check_relation_corruption($node , ' corrupt1' , ' pg_default' );
160181
161182# Create tablespace to check corruptions in a non-default tablespace.
162- my $basedir = $node -> basedir;
183+ my $basedir = $node -> basedir;
163184my $tablespace_dir = " $basedir /ts_corrupt_dir" ;
164- mkdir ($tablespace_dir );
185+ mkdir ($tablespace_dir );
165186$tablespace_dir = TestLib::real_dir($tablespace_dir );
166187$node -> safe_psql(' postgres' ,
167188 " CREATE TABLESPACE ts_corrupt LOCATION '$tablespace_dir ';" );
@@ -171,19 +192,20 @@ sub check_relation_corruption
171192# correctly-named relation files filled with some corrupted data.
172193sub fail_corrupt
173194{
174- my $node = shift ;
175- my $file = shift ;
195+ my $node = shift ;
196+ my $file = shift ;
176197 my $pgdata = $node -> data_dir;
177198
178199 # Create the file with some dummy data in it.
179200 my $file_name = " $pgdata /global/$file " ;
180201 append_to_file $file_name , " foo" ;
181202
182- $node -> command_checks_all([ ' pg_checksums' , ' --check' , ' -D' , $pgdata ],
183- 1,
184- [qr / ^$ / ],
185- [qr / could not read block 0 in file.*$file \" :/ ],
186- " fails for corrupted data in $file " );
203+ $node -> command_checks_all(
204+ [ ' pg_checksums' , ' --check' , ' -D' , $pgdata ],
205+ 1,
206+ [qr / ^$ / ],
207+ [qr / could not read block 0 in file.*$file \" :/ ],
208+ " fails for corrupted data in $file " );
187209
188210 # Remove file to prevent future lookup errors on conflicts.
189211 unlink $file_name ;
0 commit comments