Skip to content

Commit 87d90ac

Browse files
committed
Improve pg_amcheck's TAP test 003_check.pl.
Disable autovacuum, because we don't want it to run against intentionally corrupted tables. Also, before corrupting the tables, run pg_amcheck and ensure that it passes. Otherwise, if something unexpected happens when we check the corrupted tables, it's not so clear whether it would have also happened before we corrupted them. Mark Dilger Discussion: http://postgr.es/m/AA5506CE-7D2A-42E4-A51D-358635E3722D@enterprisedb.com
1 parent ea80138 commit 87d90ac

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/bin/pg_amcheck/t/003_check.pl

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use PostgresNode;
55
use TestLib;
6-
use Test::More tests => 60;
6+
use Test::More tests => 63;
77

88
my ($node, $port, %corrupt_page, %remove_relation);
99

@@ -117,6 +117,7 @@ ()
117117
# Test set-up
118118
$node = get_new_node('test');
119119
$node->init;
120+
$node->append_conf('postgresql.conf', 'autovacuum=off');
120121
$node->start;
121122
$port = $node->port;
122123

@@ -308,11 +309,6 @@ ()
308309
# Leave 'db3' uncorrupted
309310
#
310311

311-
# Perform the corruptions we planned above using only a single database restart.
312-
#
313-
perform_all_corruptions();
314-
315-
316312
# Standard first arguments to TestLib functions
317313
my @cmd = ('pg_amcheck', '--quiet', '-p', $port);
318314

@@ -322,6 +318,22 @@ ()
322318
my $missing_file_re = qr/could not open file ".*": No such file or directory/;
323319
my $index_missing_relation_fork_re = qr/index ".*" lacks a main relation fork/;
324320

321+
# We have created test databases with tables populated with data, but have not
322+
# yet corrupted anything. As such, we expect no corruption and verify that
323+
# none is reported
324+
#
325+
$node->command_checks_all(
326+
[ @cmd, '-d', 'db1', '-d', 'db2', '-d', 'db3' ],
327+
0,
328+
[ $no_output_re ],
329+
[ $no_output_re ],
330+
'pg_amcheck prior to corruption');
331+
332+
# Perform the corruptions we planned above using only a single database restart.
333+
#
334+
perform_all_corruptions();
335+
336+
325337
# Checking databases with amcheck installed and corrupt relations, pg_amcheck
326338
# command itself should return exit status = 2, because tables and indexes are
327339
# corrupt, not exit status = 1, which would mean the pg_amcheck command itself

0 commit comments

Comments
 (0)