Skip to content

Commit ee9e145

Browse files
committed
Fix pg_bsaebackup checksum tests
Hopefully fix the fact that these checks are unstable, by introducing the corruption in a separate table from pg_class, and also explicitly disable autovacuum on those tables. Also make sure PostgreSQL is stopped while the corruption is introduced to avoid possible caching effects. Author: Michael Banck
1 parent f044d71 commit ee9e145

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

src/bin/pg_basebackup/t/010_pg_basebackup.pl

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -406,19 +406,25 @@
406406
my $checksum = $node->safe_psql('postgres', 'SHOW data_checksums;');
407407
is($checksum, 'on', 'checksums are enabled');
408408

409-
# get relfilenodes of relations to corrupt
410-
my $pg_class = $node->safe_psql('postgres',
411-
q{SELECT pg_relation_filepath('pg_class')}
409+
# create tables to corrupt and get their relfilenodes
410+
my $file_corrupt1 = $node->safe_psql('postgres',
411+
q{SELECT a INTO corrupt1 FROM generate_series(1,10000) AS a; ALTER TABLE corrupt1 SET (autovacuum_enabled=false); SELECT pg_relation_filepath('corrupt1')}
412412
);
413-
my $pg_index = $node->safe_psql('postgres',
414-
q{SELECT pg_relation_filepath('pg_index')}
413+
my $file_corrupt2 = $node->safe_psql('postgres',
414+
q{SELECT b INTO corrupt2 FROM generate_series(1,2) AS b; ALTER TABLE corrupt2 SET (autovacuum_enabled=false); SELECT pg_relation_filepath('corrupt2')}
415415
);
416416

417+
# set page header and block sizes
418+
my $pageheader_size = 24;
419+
my $block_size = $node->safe_psql('postgres', 'SHOW block_size;');
420+
417421
# induce corruption
418-
open $file, '+<', "$pgdata/$pg_class";
419-
seek($file, 4000, 0);
422+
system_or_bail 'pg_ctl', '-D', $pgdata, 'stop';
423+
open $file, '+<', "$pgdata/$file_corrupt1";
424+
seek($file, $pageheader_size, 0);
420425
syswrite($file, '\0\0\0\0\0\0\0\0\0');
421426
close $file;
427+
system_or_bail 'pg_ctl', '-D', $pgdata, 'start';
422428

423429
$node->command_checks_all([ 'pg_basebackup', '-D', "$tempdir/backup_corrupt"],
424430
1,
@@ -428,13 +434,15 @@
428434
);
429435

430436
# induce further corruption in 5 more blocks
431-
open $file, '+<', "$pgdata/$pg_class";
432-
my @offsets = (12192, 20384, 28576, 36768, 44960);
433-
foreach my $offset (@offsets) {
437+
system_or_bail 'pg_ctl', '-D', $pgdata, 'stop';
438+
open $file, '+<', "$pgdata/$file_corrupt1";
439+
for my $i ( 1..5 ) {
440+
my $offset = $pageheader_size + $i * $block_size;
434441
seek($file, $offset, 0);
435442
syswrite($file, '\0\0\0\0\0\0\0\0\0');
436443
}
437444
close $file;
445+
system_or_bail 'pg_ctl', '-D', $pgdata, 'start';
438446

439447
$node->command_checks_all([ 'pg_basebackup', '-D', "$tempdir/backup_corrupt2"],
440448
1,
@@ -444,10 +452,12 @@
444452
);
445453

446454
# induce corruption in a second file
447-
open $file, '+<', "$pgdata/$pg_index";
455+
system_or_bail 'pg_ctl', '-D', $pgdata, 'stop';
456+
open $file, '+<', "$pgdata/$file_corrupt2";
448457
seek($file, 4000, 0);
449458
syswrite($file, '\0\0\0\0\0\0\0\0\0');
450459
close $file;
460+
system_or_bail 'pg_ctl', '-D', $pgdata, 'start';
451461

452462
$node->command_checks_all([ 'pg_basebackup', '-D', "$tempdir/backup_corrupt3"],
453463
1,
@@ -460,3 +470,6 @@
460470
$node->command_ok(
461471
[ 'pg_basebackup', '-D', "$tempdir/backup_corrupt4", '-k' ],
462472
'pg_basebackup with -k does not report checksum mismatch');
473+
474+
$node->safe_psql('postgres', "DROP TABLE corrupt1;");
475+
$node->safe_psql('postgres', "DROP TABLE corrupt2;");

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy