Skip to content

Commit 4c279b7

Browse files
author
hackorum
committed
Apply committs-switchover-test-v2.patch
1 parent b597835 commit 4c279b7

1 file changed

Lines changed: 95 additions & 0 deletions

File tree

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Test master/standby switchover scenario where the track_commit_timestamp
2+
# GUC is originally off, then enabled on the new primary after a switchover.
3+
use strict;
4+
use warnings;
5+
6+
use TestLib;
7+
use Test::More tests => 3;
8+
use PostgresNode;
9+
10+
my $bkplabel = 'backup';
11+
my $master = get_new_node('master');
12+
$master->init(allows_streaming => 1);
13+
$master->append_conf(
14+
'postgresql.conf', qq{
15+
track_commit_timestamp = on
16+
max_wal_senders = 5
17+
max_worker_processes = 8
18+
});
19+
$master->start;
20+
$master->backup($bkplabel);
21+
22+
my $standby = get_new_node('standby');
23+
$standby->init_from_backup($master, $bkplabel, has_streaming => 1);
24+
$standby->start;
25+
26+
for my $i (1 .. 10)
27+
{
28+
$master->safe_psql('postgres', "create table t$i()");
29+
}
30+
my $master_lsn =
31+
$master->safe_psql('postgres', 'select pg_current_wal_lsn()');
32+
$standby->poll_query_until('postgres',
33+
qq{SELECT '$master_lsn'::pg_lsn <= pg_last_wal_replay_lsn()})
34+
or die "standby never caught up";
35+
36+
$standby->safe_psql('postgres', 'checkpoint');
37+
$standby->restart;
38+
39+
# Begin the switchover, and first stop cleanly the primary.
40+
$master->stop;
41+
42+
# Promote the standby with larger max_worker_processes, and enable
43+
# track_commit_timestamp while on it. Generate a XLOG_PARAMETER_CHANGE
44+
# record with those values.
45+
$standby->promote;
46+
$standby->append_conf('postgresql.conf', 'track_commit_timestamp = off');
47+
$standby->append_conf('postgresql.conf', 'max_worker_processes = 10');
48+
$standby->restart;
49+
50+
# Enable streaming on the previous primary, and start it. The node will
51+
# shut down once it finds the record XLOG_PARAMETER_CHANGE generated
52+
# previously.
53+
$master->enable_streaming($standby);
54+
command_fails(
55+
[ 'pg_ctl', '-D', $master->data_dir, '-l', $master->logfile, 'start' ],
56+
'start fails because of max_worker_processes lower on standby at recovery');
57+
58+
# Consume some transactions on the standby without the primary knowing
59+
# about it yet, generating some commit timestamps.
60+
for my $i (11 .. 20)
61+
{
62+
$standby->safe_psql('postgres', "create table t$i()");
63+
}
64+
65+
# Toggle the configuration back on, and do more transactions.
66+
$standby->append_conf('postgresql.conf', 'track_commit_timestamp = on');
67+
$standby->restart;
68+
for my $i (21 .. 30)
69+
{
70+
$standby->safe_psql('postgres', "create table t$i()");
71+
}
72+
73+
# Reconfigure the new standby and start it so as recovery is able to
74+
# go through with a setting of max_worker_processes much larger than
75+
# the primary.
76+
$master->append_conf('postgresql.conf', 'max_worker_processes = 50');
77+
$master->start;
78+
my $standby_lsn =
79+
$standby->safe_psql('postgres', 'select pg_current_wal_lsn()');
80+
$master->poll_query_until('postgres',
81+
qq{SELECT '$standby_lsn'::pg_lsn <= pg_last_wal_replay_lsn()});
82+
83+
# And finally check that commit timestamps are generated on the
84+
# new primary.
85+
my $standby_ts = $standby->safe_psql('postgres',
86+
qq{SELECT ts.* FROM pg_class, pg_xact_commit_timestamp(xmin) AS ts WHERE relname = 't30'}
87+
);
88+
isnt($standby_ts, '',
89+
"standby gives valid non-empty value after promotion");
90+
91+
$standby_ts = $standby->safe_psql('postgres',
92+
qq{SELECT ts.* FROM pg_class, pg_xact_commit_timestamp(xmin) AS ts WHERE relname = 't11'}
93+
);
94+
is($standby_ts, '',
95+
"standby gives valid empty value after promotion");

0 commit comments

Comments
 (0)