Alvaro Herrera 4aaddf2f00 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
2016-11-24 15:39:55 -03:00

48 lines
1.3 KiB
Plaintext

--
-- Commit Timestamp
--
SHOW track_commit_timestamp;
track_commit_timestamp
------------------------
on
(1 row)
CREATE TABLE committs_test(id serial, ts timestamptz default now());
INSERT INTO committs_test DEFAULT VALUES;
INSERT INTO committs_test DEFAULT VALUES;
INSERT INTO committs_test DEFAULT VALUES;
SELECT id,
pg_xact_commit_timestamp(xmin) >= ts,
pg_xact_commit_timestamp(xmin) <= now(),
pg_xact_commit_timestamp(xmin) - ts < '60s' -- 60s should give a lot of reserve
FROM committs_test
ORDER BY id;
id | ?column? | ?column? | ?column?
----+----------+----------+----------
1 | t | t | t
2 | t | t | t
3 | t | t | t
(3 rows)
DROP TABLE committs_test;
SELECT pg_xact_commit_timestamp('0'::xid);
ERROR: cannot retrieve commit timestamp for transaction 0
SELECT pg_xact_commit_timestamp('1'::xid);
pg_xact_commit_timestamp
--------------------------
(1 row)
SELECT pg_xact_commit_timestamp('2'::xid);
pg_xact_commit_timestamp
--------------------------
(1 row)
SELECT x.xid::text::bigint > 0, x.timestamp > '-infinity'::timestamptz, x.timestamp <= now() FROM pg_last_committed_xact() x;
?column? | ?column? | ?column?
----------+----------+----------
t | t | t
(1 row)