1# Test simple scenario involving a standby 2 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 14$master->append_conf( 15 'postgresql.conf', qq{ 16 track_commit_timestamp = on 17 max_wal_senders = 5 18 wal_level = hot_standby 19 }); 20$master->start; 21$master->backup($bkplabel); 22 23my $standby = get_new_node('standby'); 24$standby->init_from_backup($master, $bkplabel, has_streaming => 1); 25$standby->start; 26 27for my $i (1 .. 10) 28{ 29 $master->safe_psql('postgres', "create table t$i()"); 30} 31my $master_ts = $master->safe_psql('postgres', 32qq{SELECT ts.* FROM pg_class, pg_xact_commit_timestamp(xmin) AS ts WHERE relname = 't10'} 33); 34my $master_lsn = 35 $master->safe_psql('postgres', 'select pg_current_xlog_location()'); 36$standby->poll_query_until('postgres', 37 qq{SELECT '$master_lsn'::pg_lsn <= pg_last_xlog_replay_location()}) 38 or die "slave never caught up"; 39 40my $standby_ts = $standby->safe_psql('postgres', 41qq{select ts.* from pg_class, pg_xact_commit_timestamp(xmin) ts where relname = 't10'} 42); 43is($master_ts, $standby_ts, "standby gives same value as master"); 44 45$master->append_conf('postgresql.conf', 'track_commit_timestamp = off'); 46$master->restart; 47$master->safe_psql('postgres', 'checkpoint'); 48$master_lsn = 49 $master->safe_psql('postgres', 'select pg_current_xlog_location()'); 50$standby->poll_query_until('postgres', 51 qq{SELECT '$master_lsn'::pg_lsn <= pg_last_xlog_replay_location()}) 52 or die "slave never caught up"; 53$standby->safe_psql('postgres', 'checkpoint'); 54 55# This one should raise an error now 56my ($ret, $standby_ts_stdout, $standby_ts_stderr) = $standby->psql('postgres', 57'select ts.* from pg_class, pg_xact_commit_timestamp(xmin) ts where relname = \'t10\'' 58); 59is($ret, 3, 'standby errors when master turned feature off'); 60is($standby_ts_stdout, '', 61 "standby gives no value when master turned feature off"); 62like( 63 $standby_ts_stderr, 64 qr/could not get commit timestamp data/, 65 'expected error when master turned feature off'); 66