Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb34e84f

Browse files
committed
Add TAP tests for pg_verify_checksums
All options available in the utility get coverage:- Tests with disabled page checksums.- Tests with enabled test checksums.- Emulation of corruption and broken checksums with a full scan andsingle relfilenode scan.This patch has been contributed mainly by Michael Banck and MagnusHagander with things presented on various threads, and I have gatheredall the contents into a single patch.Author: Michael Banck, Magnus Hagander, Michael PaquierReviewed-by: Peter EisentrautDiscussion:https://postgr.es/m/20181005012645.GE1629@paquier.xyz
1 parentcda6a8d commitb34e84f

File tree

5 files changed

+98
-1
lines changed

5 files changed

+98
-1
lines changed

‎src/bin/initdb/t/001_initdb.pl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use File::statqw{lstat};
99
use PostgresNode;
1010
use TestLib;
11-
use Test::Moretests=>18;
11+
use Test::Moretests=>22;
1212

1313
my$tempdir = TestLib::tempdir;
1414
my$xlogdir ="$tempdir/pgxlog";
@@ -58,6 +58,18 @@
5858
"check PGDATA permissions");
5959
}
6060
}
61+
62+
# Control file should tell that data checksums are disabled by default.
63+
command_like(['pg_controldata',$datadir],
64+
qr/Data page checksum version:.*0/,
65+
'checksums are disabled in control file');
66+
# pg_verify_checksums fails with checksums disabled by default. This is
67+
# not part of the tests included in pg_verify_checksums to save from
68+
# the creation of an extra instance.
69+
command_fails(
70+
['pg_verify_checksums','-D',$datadir],
71+
"pg_verify_checksums fails with data checksum disabled");
72+
6173
command_ok(['initdb','-S',$datadir ],'sync only');
6274
command_fails(['initdb',$datadir ],'existing data directory');
6375

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/pg_verify_checksums
2+
3+
/tmp_check/

‎src/bin/pg_verify_checksums/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,9 @@ uninstall:
3434
cleandistcleanmaintainer-clean:
3535
rm -f pg_verify_checksums$(X)$(OBJS)
3636
rm -rf tmp_check
37+
38+
check:
39+
$(prove_check)
40+
41+
installcheck:
42+
$(prove_installcheck)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use strict;
2+
use warnings;
3+
use TestLib;
4+
use Test::Moretests=> 8;
5+
6+
program_help_ok('pg_verify_checksums');
7+
program_version_ok('pg_verify_checksums');
8+
program_options_handling_ok('pg_verify_checksums');
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Do basic sanity checks supported by pg_verify_checksums using
2+
# an initialized cluster.
3+
4+
use strict;
5+
use warnings;
6+
use PostgresNode;
7+
use TestLib;
8+
use Test::Moretests=> 12;
9+
10+
# Initialize node with checksums enabled.
11+
my$node = get_new_node('node_checksum');
12+
$node->init(extra=> ['--data-checksums']);
13+
my$pgdata =$node->data_dir;
14+
15+
# Control file should know that checksums are enabled.
16+
command_like(['pg_controldata',$pgdata],
17+
qr/Data page checksum version:.*1/,
18+
'checksums enabled in control file');
19+
20+
# Checksums pass on a newly-created cluster
21+
command_ok(['pg_verify_checksums','-D',$pgdata],
22+
"succeeds with offline cluster");
23+
24+
# Checks cannot happen with an online cluster
25+
$node->start;
26+
command_fails(['pg_verify_checksums','-D',$pgdata],
27+
"fails with online cluster");
28+
29+
# Create table to corrupt and get its relfilenode
30+
$node->safe_psql('postgres',
31+
"SELECT a INTO corrupt1 FROM generate_series(1,10000) AS a;
32+
ALTER TABLE corrupt1 SET (autovacuum_enabled=false);");
33+
34+
my$file_corrupted =$node->safe_psql('postgres',
35+
"SELECT pg_relation_filepath('corrupt1')");
36+
my$relfilenode_corrupted =$node->safe_psql('postgres',
37+
"SELECT relfilenode FROM pg_class WHERE relname = 'corrupt1';");
38+
39+
# Set page header and block size
40+
my$pageheader_size = 24;
41+
my$block_size =$node->safe_psql('postgres','SHOW block_size;');
42+
$node->stop;
43+
44+
# Checksums are correct for single relfilenode as the table is not
45+
# corrupted yet.
46+
command_ok(['pg_verify_checksums','-D',$pgdata,
47+
'-r',$relfilenode_corrupted],
48+
"succeeds for single relfilenode with offline cluster");
49+
50+
# Time to create some corruption
51+
openmy$file,'+<',"$pgdata/$file_corrupted";
52+
seek($file,$pageheader_size, 0);
53+
syswrite($file,'\0\0\0\0\0\0\0\0\0');
54+
close$file;
55+
56+
# Global checksum checks fail
57+
$node->command_checks_all(['pg_verify_checksums','-D',$pgdata],
58+
1,
59+
[qr/Bad checksums:.*1/],
60+
[qr/checksum verification failed/],
61+
'fails with corrupted data');
62+
63+
# Checksum checks on single relfilenode fail
64+
$node->command_checks_all(['pg_verify_checksums','-D',$pgdata,'-r',
65+
$relfilenode_corrupted],
66+
1,
67+
[qr/Bad checksums:.*1/],
68+
[qr/checksum verification failed/],
69+
'fails for corrupted data on single relfilenode');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp