Debian Codegraph @

src/test/modules/commit_ts/t/001_base.pl

raw
1
2 # Copyright (c) 2021-2025, PostgreSQL Global Development Group
3
4 # Single-node test: value can be set, and is still present after recovery
5
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 $node = PostgreSQL::Test::Cluster->new('foxtrot');
14 $node->init(extra => [ '-c', "track_commit_timestamp=on" ]);
15 $node->start;
16
17 # Create a table, compare "now()" to the commit TS of its xmin
18 $node->safe_psql('postgres',
19 'create table t as select now from (select now(), pg_sleep(1)) f');
20 my $true = $node->safe_psql('postgres',
21 'select t.now - ts.* < \'1s\' from t, pg_class c, pg_xact_commit_timestamp(c.xmin) ts where relname = \'t\''
22 );
23 is($true, 't', 'commit TS is set');
24 my $ts = $node->safe_psql('postgres',
25 'select ts.* from pg_class, pg_xact_commit_timestamp(xmin) ts where relname = \'t\''
26 );
27
28 # Verify that we read the same TS after crash recovery
29 $node->stop('immediate');
30 $node->start;
31
32 my $recovered_ts = $node->safe_psql('postgres',
33 'select ts.* from pg_class, pg_xact_commit_timestamp(xmin) ts where relname = \'t\''
34 );
35 is($recovered_ts, $ts, 'commit TS remains after crash recovery');
36
37 done_testing();