Debian Codegraph @

src/test/modules/commit_ts/t/003_standby_2.pl

raw
1
2 # Copyright (c) 2021-2025, PostgreSQL Global Development Group
3
4 # Test primary/standby scenario where the track_commit_timestamp GUC is
5 # repeatedly toggled on and off.
6 use strict;
7 use warnings FATAL => 'all';
8
9 use PostgreSQL::Test::Utils;
10 use Test::More;
11 use PostgreSQL::Test::Cluster;
12
13 my $bkplabel = 'backup';
14 my $primary = PostgreSQL::Test::Cluster->new('primary');
15 $primary->init(allows_streaming => 1);
16 $primary->append_conf(
17 'postgresql.conf', qq{
18 track_commit_timestamp = on
19 max_wal_senders = 5
20 });
21 $primary->start;
22 $primary->backup($bkplabel);
23
24 my $standby = PostgreSQL::Test::Cluster->new('standby');
25 $standby->init_from_backup($primary, $bkplabel, has_streaming => 1);
26 $standby->start;
27
28 for my $i (1 .. 10)
29 {
30 $primary->safe_psql('postgres', "create table t$i()");
31 }
32 $primary->append_conf('postgresql.conf', 'track_commit_timestamp = off');
33 $primary->restart;
34 $primary->safe_psql('postgres', 'checkpoint');
35 my $primary_lsn =
36 $primary->safe_psql('postgres', 'select pg_current_wal_lsn()');
37 $standby->poll_query_until('postgres',
38 qq{SELECT '$primary_lsn'::pg_lsn <= pg_last_wal_replay_lsn()})
39 or die "standby never caught up";
40
41 $standby->safe_psql('postgres', 'checkpoint');
42 $standby->restart;
43
44 my ($psql_ret, $standby_ts_stdout, $standby_ts_stderr) = $standby->psql(
45 'postgres',
46 qq{SELECT ts.* FROM pg_class, pg_xact_commit_timestamp(xmin) AS ts WHERE relname = 't10'}
47 );
48 is($psql_ret, 3, 'expect error when getting commit timestamp after restart');
49 is($standby_ts_stdout, '', "standby does not return a value after restart");
50 like(
51 $standby_ts_stderr,
52 qr/could not get commit timestamp data/,
53 'expected err msg after restart');
54
55 $primary->append_conf('postgresql.conf', 'track_commit_timestamp = on');
56 $primary->restart;
57 $primary->append_conf('postgresql.conf', 'track_commit_timestamp = off');
58 $primary->restart;
59
60 system_or_bail('pg_ctl', '--pgdata' => $standby->data_dir, 'promote');
61
62 $standby->safe_psql('postgres', "create table t11()");
63 my $standby_ts = $standby->safe_psql('postgres',
64 qq{SELECT ts.* FROM pg_class, pg_xact_commit_timestamp(xmin) AS ts WHERE relname = 't11'}
65 );
66 isnt($standby_ts, '',
67 "standby gives valid value ($standby_ts) after promotion");
68
69 done_testing();