Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc8329f9

Browse files
committed
Preserve commit timestamps across clean restart
An oversight in setting the boundaries of known commit timestamps duringstartup caused old commit timestamps to become inaccessible after aserver restart.Author and reporter: Julien RouhaudReview, test code: Craig Ringer
1 parent6beb8c7 commitc8329f9

File tree

2 files changed

+139
-0
lines changed

2 files changed

+139
-0
lines changed

‎src/backend/access/transam/commit_ts.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,8 @@ SetCommitTsLimit(TransactionId oldestXact, TransactionId newestXact)
843843
else
844844
{
845845
Assert(ShmemVariableCache->newestCommitTsXid==InvalidTransactionId);
846+
ShmemVariableCache->oldestCommitTsXid=oldestXact;
847+
ShmemVariableCache->newestCommitTsXid=newestXact;
846848
}
847849
LWLockRelease(CommitTsLock);
848850
}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Testing of commit timestamps preservation across clean restarts
2+
use strict;
3+
use warnings;
4+
use PostgresNode;
5+
use TestLib;
6+
use Test::Moretests=> 16;
7+
8+
my$node_master = get_new_node('master');
9+
$node_master->init(allows_streaming=> 1);
10+
$node_master->append_conf(
11+
'postgresql.conf',qq(
12+
track_commit_timestamp = on
13+
));
14+
$node_master->start;
15+
16+
my ($ret,$stdout,$stderr);
17+
18+
($ret,$stdout,$stderr) =
19+
$node_master->psql('postgres',qq[SELECT pg_xact_commit_timestamp('0');]);
20+
is($ret, 3,'getting ts of InvalidTransactionId reports error');
21+
like(
22+
$stderr,
23+
qr/cannot retrieve commit timestamp for transaction/,
24+
'expected error from InvalidTransactionId');
25+
26+
($ret,$stdout,$stderr) =
27+
$node_master->psql('postgres',qq[SELECT pg_xact_commit_timestamp('1');]);
28+
is($ret, 3,'getting ts of BootstrapTransactionId reports error');
29+
like(
30+
$stderr,
31+
qr/cannot retrieve commit timestamp for transaction/,
32+
'expected error from BootstrapTransactionId');
33+
34+
($ret,$stdout,$stderr) =
35+
$node_master->psql('postgres',qq[SELECT pg_xact_commit_timestamp('2');]);
36+
is($ret, 3,'getting ts of FrozenTransactionId reports error');
37+
like(
38+
$stderr,
39+
qr/cannot retrieve commit timestamp for transaction/,
40+
'expected error from FrozenTransactionId');
41+
42+
# Since FirstNormalTransactionId will've occurred during initdb, long before we
43+
# enabled commit timestamps, it'll be null since we have no cts data for it but
44+
# cts are enabled.
45+
is($node_master->safe_psql(
46+
'postgres',qq[SELECT pg_xact_commit_timestamp('3');]),
47+
'',
48+
'committs for FirstNormalTransactionId is null');
49+
50+
$node_master->safe_psql('postgres',
51+
qq[CREATE TABLE committs_test(x integer, y timestamp with time zone);]);
52+
53+
my$xid =$node_master->safe_psql(
54+
'postgres',qq[
55+
BEGIN;
56+
INSERT INTO committs_test(x, y) VALUES (1, current_timestamp);
57+
SELECT txid_current();
58+
COMMIT;
59+
]);
60+
61+
my$before_restart_ts =$node_master->safe_psql('postgres',
62+
qq[SELECT pg_xact_commit_timestamp('$xid');]);
63+
ok($before_restart_ts !='' &&$before_restart_ts !='null',
64+
'commit timestamp recorded');
65+
66+
$node_master->stop('immediate');
67+
$node_master->start;
68+
69+
my$after_crash_ts =$node_master->safe_psql('postgres',
70+
qq[SELECT pg_xact_commit_timestamp('$xid');]);
71+
is($after_crash_ts,$before_restart_ts,
72+
'timestamps before and after crash are equal');
73+
74+
$node_master->stop('fast');
75+
$node_master->start;
76+
77+
my$after_restart_ts =$node_master->safe_psql('postgres',
78+
qq[SELECT pg_xact_commit_timestamp('$xid');]);
79+
is($after_restart_ts,$before_restart_ts,
80+
'timestamps before and after restart are equal');
81+
82+
# Now disable commit timestamps
83+
84+
$node_master->append_conf(
85+
'postgresql.conf',qq(
86+
track_commit_timestamp = off
87+
));
88+
89+
$node_master->stop('fast');
90+
$node_master->start;
91+
92+
($ret,$stdout,$stderr) =$node_master->psql('postgres',
93+
qq[SELECT pg_xact_commit_timestamp('$xid');]);
94+
is($ret, 3,'no commit timestamp from enable tx when cts disabled');
95+
like(
96+
$stderr,
97+
qr/could not get commit timestamp data/,
98+
'expected error from enabled tx when committs disabled');
99+
100+
# Do a tx while cts disabled
101+
my$xid_disabled =$node_master->safe_psql(
102+
'postgres',qq[
103+
BEGIN;
104+
INSERT INTO committs_test(x, y) VALUES (2, current_timestamp);
105+
SELECT txid_current();
106+
COMMIT;
107+
]);
108+
109+
# Should be inaccessible
110+
($ret,$stdout,$stderr) =$node_master->psql('postgres',
111+
qq[SELECT pg_xact_commit_timestamp('$xid_disabled');]);
112+
is($ret, 3,'no commit timestamp when disabled');
113+
like(
114+
$stderr,
115+
qr/could not get commit timestamp data/,
116+
'expected error from disabled tx when committs disabled');
117+
118+
# Re-enable, restart and ensure we can still get the old timestamps
119+
$node_master->append_conf(
120+
'postgresql.conf',qq(
121+
track_commit_timestamp = on
122+
));
123+
124+
$node_master->stop('fast');
125+
$node_master->start;
126+
127+
128+
my$after_enable_ts =$node_master->safe_psql('postgres',
129+
qq[SELECT pg_xact_commit_timestamp('$xid');]);
130+
is($after_enable_ts,'','timestamp of enabled tx null after re-enable');
131+
132+
my$after_enable_disabled_ts =$node_master->safe_psql('postgres',
133+
qq[SELECT pg_xact_commit_timestamp('$xid_disabled');]);
134+
is($after_enable_disabled_ts,'',
135+
'timestamp of disabled tx null after re-enable');
136+
137+
$node_master->stop;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp