Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ff9e1e7

Browse files
committed
Add option force_initdb to PostgreSQL::Test::Cluster:init()
This option is useful to bypass the default behavior of init() which would create the data folder of a new cluster by copying it from a template previously initdb'd, if any. Copying the data folder is much cheaper than running initdb, but some tests may want to force that. For example, one scenario of pg_combinebackup updated in this commit needs a different system ID for two nodes. Previously, this could only be achieved by unsetting $ENV{'INITDB_TEMPLATE'}, which could become a problem in complex node setups by making tests less efficient. Author: Amul Sul Reviewed-by: Robert Haas, Michael Paquier Discussion: https://postgr.es/m/Zc1tX9lLonLGu6oH@paquier.xyz
1 parent 75bcba6 commit ff9e1e7

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/bin/pg_combinebackup/t/005_integrity.pl

+6-12
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,12 @@
1818
$node1->append_conf('postgresql.conf', 'summarize_wal = on');
1919
$node1->start;
2020

21-
# Set up another new database instance. We don't want to use the cached
22-
# INITDB_TEMPLATE for this, because we want it to be a separate cluster
23-
# with a different system ID.
24-
my $node2;
25-
{
26-
local $ENV{'INITDB_TEMPLATE'} = undef;
27-
28-
$node2 = PostgreSQL::Test::Cluster->new('node2');
29-
$node2->init(has_archiving => 1, allows_streaming => 1);
30-
$node2->append_conf('postgresql.conf', 'summarize_wal = on');
31-
$node2->start;
32-
}
21+
# Set up another new database instance. force_initdb is used because
22+
# we want it to be a separate cluster with a different system ID.
23+
my $node2 = PostgreSQL::Test::Cluster->new('node2');
24+
$node2->init(force_initdb => 1, has_archiving => 1, allows_streaming => 1);
25+
$node2->append_conf('postgresql.conf', 'summarize_wal = on');
26+
$node2->start;
3327

3428
# Take a full backup from node1.
3529
my $backup1path = $node1->backup_dir . '/backup1';

src/test/perl/PostgreSQL/Test/Cluster.pm

+12-5
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,9 @@ parameter allows_streaming => 'logical' or 'physical' (passing 1 will also
503503
suffice for physical replication) depending on type of replication that
504504
should be enabled. This is disabled by default.
505505
506+
force_initdb => 1 will force the initialization of the cluster with a new
507+
initdb rather than copying the data folder from a template.
508+
506509
The new node is set up in a fast but unsafe configuration where fsync is
507510
disabled.
508511
@@ -518,6 +521,7 @@ sub init
518521
local %ENV = $self->_get_env();
519522

520523
$params{allows_streaming} = 0 unless defined $params{allows_streaming};
524+
$params{force_initdb} = 0 unless defined $params{force_initdb};
521525
$params{has_archiving} = 0 unless defined $params{has_archiving};
522526

523527
my $initdb_extra_opts_env = $ENV{PG_TEST_INITDB_EXTRA_OPTS};
@@ -529,14 +533,17 @@ sub init
529533
mkdir $self->backup_dir;
530534
mkdir $self->archive_dir;
531535

532-
# If available and if there aren't any parameters, use a previously
533-
# initdb'd cluster as a template by copying it. For a lot of tests, that's
534-
# substantially cheaper. Do so only if there aren't parameters, it doesn't
535-
# seem worth figuring out whether they affect compatibility.
536+
# If available, if there aren't any parameters and if force_initdb is
537+
# disabled, use a previously initdb'd cluster as a template by copying it.
538+
# For a lot of tests, that's substantially cheaper. It does not seem
539+
# worth figuring out whether extra parameters affect compatibility, so
540+
# initdb is forced if any are defined.
536541
#
537542
# There's very similar code in pg_regress.c, but we can't easily
538543
# deduplicate it until we require perl at build time.
539-
if (defined $params{extra} or !defined $ENV{INITDB_TEMPLATE})
544+
if ( $params{force_initdb}
545+
or defined $params{extra}
546+
or !defined $ENV{INITDB_TEMPLATE})
540547
{
541548
note("initializing database system by running initdb");
542549
PostgreSQL::Test::Utils::system_or_bail('initdb', '-D', $pgdata, '-A',

0 commit comments

Comments
 (0)