|
406 | 406 | my $checksum = $node->safe_psql('postgres', 'SHOW data_checksums;'); |
407 | 407 | is($checksum, 'on', 'checksums are enabled'); |
408 | 408 |
|
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')} |
412 | 412 | ); |
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')} |
415 | 415 | ); |
416 | 416 |
|
| 417 | +# set page header and block sizes |
| 418 | +my $pageheader_size = 24; |
| 419 | +my $block_size = $node->safe_psql('postgres', 'SHOW block_size;'); |
| 420 | + |
417 | 421 | # 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); |
420 | 425 | syswrite($file, '\0\0\0\0\0\0\0\0\0'); |
421 | 426 | close $file; |
| 427 | +system_or_bail 'pg_ctl', '-D', $pgdata, 'start'; |
422 | 428 |
|
423 | 429 | $node->command_checks_all([ 'pg_basebackup', '-D', "$tempdir/backup_corrupt"], |
424 | 430 | 1, |
|
428 | 434 | ); |
429 | 435 |
|
430 | 436 | # 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; |
434 | 441 | seek($file, $offset, 0); |
435 | 442 | syswrite($file, '\0\0\0\0\0\0\0\0\0'); |
436 | 443 | } |
437 | 444 | close $file; |
| 445 | +system_or_bail 'pg_ctl', '-D', $pgdata, 'start'; |
438 | 446 |
|
439 | 447 | $node->command_checks_all([ 'pg_basebackup', '-D', "$tempdir/backup_corrupt2"], |
440 | 448 | 1, |
|
444 | 452 | ); |
445 | 453 |
|
446 | 454 | # 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"; |
448 | 457 | seek($file, 4000, 0); |
449 | 458 | syswrite($file, '\0\0\0\0\0\0\0\0\0'); |
450 | 459 | close $file; |
| 460 | +system_or_bail 'pg_ctl', '-D', $pgdata, 'start'; |
451 | 461 |
|
452 | 462 | $node->command_checks_all([ 'pg_basebackup', '-D', "$tempdir/backup_corrupt3"], |
453 | 463 | 1, |
|
460 | 470 | $node->command_ok( |
461 | 471 | [ 'pg_basebackup', '-D', "$tempdir/backup_corrupt4", '-k' ], |
462 | 472 | '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