Skip to content

Commit 9def031

Browse files
committed
Add more tests for commit_timestamp feature
These tests verify that 1) WAL replay preserves the stored value, 2) a streaming standby server replays the value obtained from the master, and 3) the behavior is sensible in the face of repeated configuration changes. One annoyance is that tmp_check/ subdir from the TAP tests is clobbered when the pg_regress test runs in the same subdirectory. This is bothersome but not too terrible a problem, since the pg_regress test is not run anyway if the TAP tests fail (unless "make -k" is used). I had these tests around since commit 69e7235; add them now that we have the recovery test framework in place.
1 parent 88802e0 commit 9def031

File tree

4 files changed

+145
-0
lines changed

4 files changed

+145
-0
lines changed

src/test/modules/commit_ts/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
REGRESS = commit_timestamp
44
REGRESS_OPTS = --temp-config=$(top_srcdir)/src/test/modules/commit_ts/commit_ts.conf
55

6+
check: prove-check
7+
8+
prove-check:
9+
$(prove_check)
10+
611
ifdef USE_PGXS
712
PG_CONFIG = pg_config
813
PGXS := $(shell $(PG_CONFIG) --pgxs)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Single-node test: value can be set, and is still present after recovery
2+
3+
use strict;
4+
use warnings;
5+
6+
use TestLib;
7+
use Test::More tests => 2;
8+
use PostgresNode;
9+
10+
my $node = get_new_node();
11+
$node->init;
12+
$node->append_conf('postgresql.conf', 'track_commit_timestamp = on');
13+
$node->start;
14+
15+
# Create a table, compare "now()" to the commit TS of its xmin
16+
$node->psql('postgres', 'create table t as select now from (select now(), pg_sleep(1)) f');
17+
my $true = $node->psql('postgres',
18+
'select t.now - ts.* < \'1s\' from t, pg_class c, pg_xact_commit_timestamp(c.xmin) ts where relname = \'t\'');
19+
is($true, 't', 'commit TS is set');
20+
my $ts = $node->psql('postgres',
21+
'select ts.* from pg_class, pg_xact_commit_timestamp(xmin) ts where relname = \'t\'');
22+
23+
# Verify that we read the same TS after crash recovery
24+
$node->stop('immediate');
25+
$node->start;
26+
27+
my $recovered_ts = $node->psql('postgres',
28+
'select ts.* from pg_class, pg_xact_commit_timestamp(xmin) ts where relname = \'t\'');
29+
is($recovered_ts, $ts, 'commit TS remains after crash recovery');
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Test simple scenario involving a standby
2+
3+
use strict;
4+
use warnings;
5+
6+
use TestLib;
7+
use Test::More tests => 2;
8+
use PostgresNode;
9+
10+
my $bkplabel = 'backup';
11+
my $master = get_new_node('master');
12+
$master->init(allows_streaming => 1);
13+
14+
$master->append_conf('postgresql.conf', qq{
15+
track_commit_timestamp = on
16+
max_wal_senders = 5
17+
wal_level = hot_standby
18+
});
19+
$master->start;
20+
$master->backup($bkplabel);
21+
22+
my $standby = get_new_node('standby');
23+
$standby->init_from_backup($master, $bkplabel, has_streaming => 1);
24+
$standby->start;
25+
26+
for my $i (1 .. 10)
27+
{
28+
$master->psql('postgres', "create table t$i()");
29+
}
30+
my $master_ts = $master->psql('postgres',
31+
qq{SELECT ts.* FROM pg_class, pg_xact_commit_timestamp(xmin) AS ts WHERE relname = 't10'});
32+
my $master_lsn = $master->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+
my $standby_ts = $standby->psql('postgres',
39+
qq{select ts.* from pg_class, pg_xact_commit_timestamp(xmin) ts where relname = 't10'});
40+
is($master_ts, $standby_ts, "standby gives same value as master");
41+
42+
$master->append_conf('postgresql.conf', 'track_commit_timestamp = off');
43+
$master->restart;
44+
$master->psql('postgres', 'checkpoint');
45+
$master_lsn = $master->psql('postgres',
46+
'select pg_current_xlog_location()');
47+
$standby->poll_query_until('postgres',
48+
qq{SELECT '$master_lsn'::pg_lsn <= pg_last_xlog_replay_location()})
49+
or die "slave never caught up";
50+
$standby->psql('postgres', 'checkpoint');
51+
52+
# This one should raise an error now
53+
$standby_ts = $standby->psql('postgres',
54+
'select ts.* from pg_class, pg_xact_commit_timestamp(xmin) ts where relname = \'t10\'');
55+
is($standby_ts, '', "standby gives no value when master turned feature off");
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 => 2;
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->psql('postgres', "create table t$i()");
28+
}
29+
$master->append_conf('postgresql.conf', 'track_commit_timestamp = off');
30+
$master->restart;
31+
$master->psql('postgres', 'checkpoint');
32+
my $master_lsn = $master->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->psql('postgres', 'checkpoint');
39+
$standby->restart;
40+
41+
my $standby_ts = $standby->psql('postgres',
42+
qq{SELECT ts.* FROM pg_class, pg_xact_commit_timestamp(xmin) AS ts WHERE relname = 't10'});
43+
is($standby_ts, '', "standby does not return a value after restart");
44+
45+
$master->append_conf('postgresql.conf', 'track_commit_timestamp = on');
46+
$master->restart;
47+
$master->append_conf('postgresql.conf', 'track_commit_timestamp = off');
48+
$master->restart;
49+
50+
system_or_bail('pg_ctl', '-w', '-D', $standby->data_dir, 'promote');
51+
$standby->poll_query_until('postgres', "SELECT pg_is_in_recovery() <> true");
52+
53+
$standby->psql('postgres', "create table t11()");
54+
$standby_ts = $standby->psql('postgres',
55+
qq{SELECT ts.* FROM pg_class, pg_xact_commit_timestamp(xmin) AS ts WHERE relname = 't11'});
56+
isnt($standby_ts, '', "standby gives valid value ($standby_ts) after promotion");

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy