From 8860636a97f49cbca88d45d26ce6955f9610460d Mon Sep 17 00:00:00 2001 From: Greg Sabino Mullane Date: Thu, 8 Aug 2024 12:32:17 -0400 Subject: [PATCH 3/3] Change initdb to default to using data checksums. Also adjust the documentation and tests. --- doc/src/sgml/ref/initdb.sgml | 4 +++- src/bin/initdb/initdb.c | 2 +- src/bin/initdb/t/001_initdb.pl | 32 ++++++++++++++++++++++++-------- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/doc/src/sgml/ref/initdb.sgml b/doc/src/sgml/ref/initdb.sgml index bdd613e77f..2bd6e05df1 100644 --- a/doc/src/sgml/ref/initdb.sgml +++ b/doc/src/sgml/ref/initdb.sgml @@ -267,12 +267,14 @@ PostgreSQL documentation Use checksums on data pages to help detect corruption by the I/O system that would otherwise be silent. Enabling checksums - may incur a noticeable performance penalty. If set, checksums + may incur a small performance penalty. If set, checksums are calculated for all objects, in all databases. All checksum failures will be reported in the pg_stat_database view. See for details. + Data checksums are enabled by default. They can be + disabled by use of . diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 8ead7780f5..ce7d3e99e5 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -164,7 +164,7 @@ static bool noinstructions = false; static bool do_sync = true; static bool sync_only = false; static bool show_setting = false; -static bool data_checksums = false; +static bool data_checksums = true; static char *xlog_dir = NULL; static int wal_segment_size_mb = (DEFAULT_XLOG_SEG_SIZE) / (1024 * 1024); static DataDirSyncMethod sync_method = DATA_DIR_SYNC_METHOD_FSYNC; diff --git a/src/bin/initdb/t/001_initdb.pl b/src/bin/initdb/t/001_initdb.pl index 06a35ac0b7..7345e66665 100644 --- a/src/bin/initdb/t/001_initdb.pl +++ b/src/bin/initdb/t/001_initdb.pl @@ -69,16 +69,11 @@ mkdir $datadir; } } -# Control file should tell that data checksums are disabled by default. +# Control file should tell that data checksums are enabled by default. command_like( [ 'pg_controldata', $datadir ], - qr/Data page checksum version:.*0/, - 'checksums are disabled in control file'); -# pg_checksums fails with checksums disabled by default. This is -# not part of the tests included in pg_checksums to save from -# the creation of an extra instance. -command_fails([ 'pg_checksums', '-D', $datadir ], - "pg_checksums fails with data checksum disabled"); + qr/Data page checksum version:.*1/, + 'checksums are enabled in control file'); command_ok([ 'initdb', '-S', $datadir ], 'sync only'); command_fails([ 'initdb', $datadir ], 'existing data directory'); @@ -268,4 +263,25 @@ ok($conf !~ qr/^WORK_MEM = /m, "WORK_MEM should not be configured"); ok($conf !~ qr/^Work_Mem = /m, "Work_Mem should not be configured"); ok($conf =~ qr/^work_mem = 512/m, "work_mem should be in config"); +# Test the no-data-checksums flag + +my $datadir_nochecksums = "$tempdir/data_no_checksums"; + +command_ok([ 'initdb', '--no-data-checksums', $datadir_nochecksums ], + 'successful creation without data checksums'); + +# Control file should tell that data checksums are disabled. +command_like( + [ 'pg_controldata', $datadir_nochecksums ], + qr/Data page checksum version:.*0/, + 'checksums are disabled in control file'); + +# pg_checksums fails with checksums disabled. This is +# not part of the tests included in pg_checksums to save from +# the creation of an extra instance. +command_fails( + [ 'pg_checksums', '-D', $datadir_nochecksums ], + "pg_checksums fails with data checksum disabled"); + + done_testing(); -- 2.30.2