]> granicus.if.org Git - postgresql/blob - src/test/modules/commit_ts/t/003_standby_2.pl
138cc43dc2b34e0fd166f55b1b79e86145fba460
[postgresql] / src / test / modules / commit_ts / t / 003_standby_2.pl
1 # Test master/standby scenario where the track_commit_timestamp GUC is
2 # repeatedly toggled on and off.
3 use strict;
4 use warnings;
5
6 use TestLib;
7 use Test::More tests => 4;
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('postgresql.conf', qq{
14         track_commit_timestamp = on
15         max_wal_senders = 5
16         wal_level = hot_standby
17         });
18 $master->start;
19 $master->backup($bkplabel);
20
21 my $standby = get_new_node('standby');
22 $standby->init_from_backup($master, $bkplabel, has_streaming => 1);
23 $standby->start;
24
25 for my $i (1 .. 10)
26 {
27         $master->safe_psql('postgres', "create table t$i()");
28 }
29 $master->append_conf('postgresql.conf', 'track_commit_timestamp = off');
30 $master->restart;
31 $master->safe_psql('postgres', 'checkpoint');
32 my $master_lsn = $master->safe_psql('postgres',
33         'select pg_current_xlog_location()');
34 $standby->poll_query_until('postgres',
35         qq{SELECT '$master_lsn'::pg_lsn <= pg_last_xlog_replay_location()})
36         or die "slave never caught up";
37
38 $standby->safe_psql('postgres', 'checkpoint');
39 $standby->restart;
40
41 my ($psql_ret, $standby_ts_stdout, $standby_ts_stderr) = $standby->psql('postgres',
42         qq{SELECT ts.* FROM pg_class, pg_xact_commit_timestamp(xmin) AS ts WHERE relname = 't10'});
43 is($psql_ret, 3, 'expect error when getting commit timestamp after restart');
44 is($standby_ts_stdout, '', "standby does not return a value after restart");
45 like($standby_ts_stderr, qr/could not get commit timestamp data/, 'expected err msg after restart');
46
47 $master->append_conf('postgresql.conf', 'track_commit_timestamp = on');
48 $master->restart;
49 $master->append_conf('postgresql.conf', 'track_commit_timestamp = off');
50 $master->restart;
51
52 system_or_bail('pg_ctl', '-w', '-D', $standby->data_dir, 'promote');
53 $standby->poll_query_until('postgres', "SELECT pg_is_in_recovery() <> true");
54
55 $standby->safe_psql('postgres', "create table t11()");
56 my $standby_ts = $standby->safe_psql('postgres',
57         qq{SELECT ts.* FROM pg_class, pg_xact_commit_timestamp(xmin) AS ts WHERE relname = 't11'});
58 isnt($standby_ts, '', "standby gives valid value ($standby_ts) after promotion");