1 # Test master/standby scenario where the track_commit_timestamp GUC is
2 # repeatedly toggled on and off.
7 use Test::More tests => 4;
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
16 wal_level = hot_standby
19 $master->backup($bkplabel);
21 my $standby = get_new_node('standby');
22 $standby->init_from_backup($master, $bkplabel, has_streaming => 1);
27 $master->safe_psql('postgres', "create table t$i()");
29 $master->append_conf('postgresql.conf', 'track_commit_timestamp = off');
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";
38 $standby->safe_psql('postgres', 'checkpoint');
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');
47 $master->append_conf('postgresql.conf', 'track_commit_timestamp = on');
49 $master->append_conf('postgresql.conf', 'track_commit_timestamp = off');
52 system_or_bail('pg_ctl', '-w', '-D', $standby->data_dir, 'promote');
53 $standby->poll_query_until('postgres', "SELECT pg_is_in_recovery() <> true");
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");