On Tue, Oct 01, 2024 at 11:15:02AM -0400, Peter Eisentraut wrote:
> I have committed 0001 (the new option) and 0004 (the docs tweak).  I think
> there is consensus for the rest, too, but I'll leave it for a few more days
> to think about.  I guess the test failure has to be addressed.

Here is a rebased patch with the test fix (for cfbot).  I have made no
other changes.

-- 
nathan
>From 912894763686e29e907a5f5600e0caabca961dad Mon Sep 17 00:00:00 2001
From: Nathan Bossart <nat...@postgresql.org>
Date: Thu, 3 Oct 2024 16:01:19 -0500
Subject: [PATCH v3 1/1] use data checksums by default

---
 contrib/amcheck/t/001_verify_heapam.pl    |  2 +-
 doc/src/sgml/ref/initdb.sgml              |  2 ++
 src/bin/initdb/initdb.c                   |  2 +-
 src/bin/initdb/t/001_initdb.pl            | 18 ++++++++++--------
 src/bin/pg_amcheck/t/003_check.pl         |  2 +-
 src/bin/pg_amcheck/t/004_verify_heapam.pl |  2 +-
 src/bin/pg_checksums/t/002_actions.pl     |  2 +-
 src/test/perl/PostgreSQL/Test/Cluster.pm  |  7 +++++++
 8 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/contrib/amcheck/t/001_verify_heapam.pl 
b/contrib/amcheck/t/001_verify_heapam.pl
index 481e4dbe4f..b380d1b034 100644
--- a/contrib/amcheck/t/001_verify_heapam.pl
+++ b/contrib/amcheck/t/001_verify_heapam.pl
@@ -15,7 +15,7 @@ my $node;
 # Test set-up
 #
 $node = PostgreSQL::Test::Cluster->new('test');
-$node->init;
+$node->init(no_checksums => 1);
 $node->append_conf('postgresql.conf', 'autovacuum=off');
 $node->start;
 $node->safe_psql('postgres', q(CREATE EXTENSION amcheck));
diff --git a/doc/src/sgml/ref/initdb.sgml b/doc/src/sgml/ref/initdb.sgml
index a0ce261999..f9f008888c 100644
--- a/doc/src/sgml/ref/initdb.sgml
+++ b/doc/src/sgml/ref/initdb.sgml
@@ -273,6 +273,8 @@ PostgreSQL documentation
         <link linkend="monitoring-pg-stat-database-view">
         <structname>pg_stat_database</structname></link> view.
         See <xref linkend="checksums" /> for details.
+        Data checksums are enabled by default. They can be
+        disabled by use of <option>--no-data-checksums</option>.
        </para>
       </listitem>
      </varlistentry>
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index eac6cbd8e5..9eff46e799 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 8072adb97f..7520d3d0dd 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');
@@ -280,4 +275,11 @@ command_like(
        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();
diff --git a/src/bin/pg_amcheck/t/003_check.pl 
b/src/bin/pg_amcheck/t/003_check.pl
index d99b094dba..c140b1622b 100644
--- a/src/bin/pg_amcheck/t/003_check.pl
+++ b/src/bin/pg_amcheck/t/003_check.pl
@@ -120,7 +120,7 @@ sub perform_all_corruptions()
 
 # Test set-up
 $node = PostgreSQL::Test::Cluster->new('test');
-$node->init;
+$node->init(no_checksums => 1);
 $node->append_conf('postgresql.conf', 'autovacuum=off');
 $node->start;
 $port = $node->port;
diff --git a/src/bin/pg_amcheck/t/004_verify_heapam.pl 
b/src/bin/pg_amcheck/t/004_verify_heapam.pl
index f6d2c5f787..2c17f7d068 100644
--- a/src/bin/pg_amcheck/t/004_verify_heapam.pl
+++ b/src/bin/pg_amcheck/t/004_verify_heapam.pl
@@ -181,7 +181,7 @@ my $aborted_xid;
 # autovacuum workers visiting the table could crash the backend.
 # Disable autovacuum so that won't happen.
 my $node = PostgreSQL::Test::Cluster->new('test');
-$node->init;
+$node->init(no_checksums => 1);
 $node->append_conf('postgresql.conf', 'autovacuum=off');
 $node->append_conf('postgresql.conf', 'max_prepared_transactions=10');
 
diff --git a/src/bin/pg_checksums/t/002_actions.pl 
b/src/bin/pg_checksums/t/002_actions.pl
index 33e7fb53c5..c136febbbb 100644
--- a/src/bin/pg_checksums/t/002_actions.pl
+++ b/src/bin/pg_checksums/t/002_actions.pl
@@ -88,7 +88,7 @@ sub check_relation_corruption
 
 # Initialize node with checksums disabled.
 my $node = PostgreSQL::Test::Cluster->new('node_checksum');
-$node->init();
+$node->init(no_checksums => 1);
 my $pgdata = $node->data_dir;
 
 # Control file should know that checksums are disabled.
diff --git a/src/test/perl/PostgreSQL/Test/Cluster.pm 
b/src/test/perl/PostgreSQL/Test/Cluster.pm
index 90a842f96a..748f21c4a4 100644
--- a/src/test/perl/PostgreSQL/Test/Cluster.pm
+++ b/src/test/perl/PostgreSQL/Test/Cluster.pm
@@ -504,6 +504,8 @@ On Windows, we use SSPI authentication to ensure the same 
(by pg_regress
 WAL archiving can be enabled on this node by passing the keyword parameter
 has_archiving => 1. This is disabled by default.
 
+Data checksums can be forced off by passing no_checksums => 1.
+
 postgresql.conf can be set up for replication by passing the keyword
 parameter allows_streaming => 'logical' or 'physical' (passing 1 will also
 suffice for physical replication) depending on type of replication that
@@ -530,6 +532,11 @@ sub init
        $params{force_initdb} = 0 unless defined $params{force_initdb};
        $params{has_archiving} = 0 unless defined $params{has_archiving};
 
+       if (defined $params{no_checksums})
+       {
+               push @{ $params{extra} }, '--no-data-checksums';
+       }
+
        my $initdb_extra_opts_env = $ENV{PG_TEST_INITDB_EXTRA_OPTS};
        if (defined $initdb_extra_opts_env)
        {
-- 
2.39.5 (Apple Git-154)

Reply via email to