1# Test master/standby scenario where the track_commit_timestamp GUC is
2# repeatedly toggled on and off.
3use strict;
4use warnings;
5
6use TestLib;
7use Test::More tests => 4;
8use PostgresNode;
9
10my $bkplabel = 'backup';
11my $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	});
18$master->start;
19$master->backup($bkplabel);
20
21my $standby = get_new_node('standby');
22$standby->init_from_backup($master, $bkplabel, has_streaming => 1);
23$standby->start;
24
25for 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');
32my $master_lsn =
33  $master->safe_psql('postgres', 'select pg_current_wal_lsn()');
34$standby->poll_query_until('postgres',
35	qq{SELECT '$master_lsn'::pg_lsn <= pg_last_wal_replay_lsn()})
36  or die "standby never caught up";
37
38$standby->safe_psql('postgres', 'checkpoint');
39$standby->restart;
40
41my ($psql_ret, $standby_ts_stdout, $standby_ts_stderr) = $standby->psql(
42	'postgres',
43qq{SELECT ts.* FROM pg_class, pg_xact_commit_timestamp(xmin) AS ts WHERE relname = 't10'}
44);
45is($psql_ret, 3, 'expect error when getting commit timestamp after restart');
46is($standby_ts_stdout, '', "standby does not return a value after restart");
47like(
48	$standby_ts_stderr,
49	qr/could not get commit timestamp data/,
50	'expected err msg after restart');
51
52$master->append_conf('postgresql.conf', 'track_commit_timestamp = on');
53$master->restart;
54$master->append_conf('postgresql.conf', 'track_commit_timestamp = off');
55$master->restart;
56
57system_or_bail('pg_ctl', '-D', $standby->data_dir, 'promote');
58
59$standby->safe_psql('postgres', "create table t11()");
60my $standby_ts = $standby->safe_psql('postgres',
61qq{SELECT ts.* FROM pg_class, pg_xact_commit_timestamp(xmin) AS ts WHERE relname = 't11'}
62);
63isnt($standby_ts, '',
64	"standby gives valid value ($standby_ts) after promotion");
65