Skip to content

Commit 7816d13

Browse files
committed
Fix commit_ts for FrozenXid and BootstrapXid
Previously, requesting commit timestamp for transactions FrozenTransactionId and BootstrapTransactionId resulted in an error. But since those values can validly appear in committed tuples' Xmin, this behavior is unhelpful and error prone: each caller would have to special-case those values before requesting timestamp data for an Xid. We already have a perfectly good interface for returning "the Xid you requested is too old for us to have commit TS data for it", so let's use that instead. Backpatch to 9.5, where commit timestamps appeared. Author: Craig Ringer Discussion: https://www.postgresql.org/message-id/CAMsr+YFM5Q=+ry3mKvWEqRTxrB0iU3qUSRnS28nz6FJYtBwhJg@mail.gmail.com
1 parent e0375d7 commit 7816d13

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

src/backend/access/transam/commit_ts.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,18 @@ TransactionIdGetCommitTsData(TransactionId xid, TimestampTz *ts,
288288
TransactionId oldestCommitTsXid;
289289
TransactionId newestCommitTsXid;
290290

291-
/* error if the given Xid doesn't normally commit */
292-
if (!TransactionIdIsNormal(xid))
291+
if (!TransactionIdIsValid(xid))
293292
ereport(ERROR,
294293
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
295294
errmsg("cannot retrieve commit timestamp for transaction %u", xid)));
295+
else if (!TransactionIdIsNormal(xid))
296+
{
297+
/* frozen and bootstrap xids are always committed far in the past */
298+
*ts = 0;
299+
if (nodeid)
300+
*nodeid = 0;
301+
return false;
302+
}
296303

297304
LWLockAcquire(CommitTsLock, LW_SHARED);
298305

src/test/modules/commit_ts/expected/commit_timestamp.out

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,17 @@ DROP TABLE committs_test;
2828
SELECT pg_xact_commit_timestamp('0'::xid);
2929
ERROR: cannot retrieve commit timestamp for transaction 0
3030
SELECT pg_xact_commit_timestamp('1'::xid);
31-
ERROR: cannot retrieve commit timestamp for transaction 1
31+
pg_xact_commit_timestamp
32+
--------------------------
33+
34+
(1 row)
35+
3236
SELECT pg_xact_commit_timestamp('2'::xid);
33-
ERROR: cannot retrieve commit timestamp for transaction 2
37+
pg_xact_commit_timestamp
38+
--------------------------
39+
40+
(1 row)
41+
3442
SELECT x.xid::text::bigint > 0, x.timestamp > '-infinity'::timestamptz, x.timestamp <= now() FROM pg_last_committed_xact() x;
3543
?column? | ?column? | ?column?
3644
----------+----------+----------

src/test/modules/commit_ts/expected/commit_timestamp_1.out

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,17 @@ DROP TABLE committs_test;
2323
SELECT pg_xact_commit_timestamp('0'::xid);
2424
ERROR: cannot retrieve commit timestamp for transaction 0
2525
SELECT pg_xact_commit_timestamp('1'::xid);
26-
ERROR: cannot retrieve commit timestamp for transaction 1
26+
pg_xact_commit_timestamp
27+
--------------------------
28+
29+
(1 row)
30+
2731
SELECT pg_xact_commit_timestamp('2'::xid);
28-
ERROR: cannot retrieve commit timestamp for transaction 2
32+
pg_xact_commit_timestamp
33+
--------------------------
34+
35+
(1 row)
36+
2937
SELECT x.xid::text::bigint > 0, x.timestamp > '-infinity'::timestamptz, x.timestamp <= now() FROM pg_last_committed_xact() x;
3038
ERROR: could not get commit timestamp data
3139
HINT: Make sure the configuration parameter "track_commit_timestamp" is set.

0 commit comments

Comments
 (0)