| 1 |
-- |
| 2 |
-- Commit Timestamp |
| 3 |
-- |
| 4 |
SHOW track_commit_timestamp; |
| 5 |
CREATE TABLE committs_test(id serial, ts timestamptz default now()); |
| 6 |
|
| 7 |
INSERT INTO committs_test DEFAULT VALUES; |
| 8 |
INSERT INTO committs_test DEFAULT VALUES; |
| 9 |
INSERT INTO committs_test DEFAULT VALUES; |
| 10 |
|
| 11 |
SELECT id, |
| 12 |
pg_xact_commit_timestamp(xmin) >= ts, |
| 13 |
pg_xact_commit_timestamp(xmin) <= now(), |
| 14 |
pg_xact_commit_timestamp(xmin) - ts < '60s' -- 60s should give a lot of reserve |
| 15 |
FROM committs_test |
| 16 |
ORDER BY id; |
| 17 |
|
| 18 |
DROP TABLE committs_test; |
| 19 |
|
| 20 |
SELECT pg_xact_commit_timestamp('0'::xid); |
| 21 |
SELECT pg_xact_commit_timestamp('1'::xid); |
| 22 |
SELECT pg_xact_commit_timestamp('2'::xid); |
| 23 |
|
| 24 |
SELECT x.xid::text::bigint > 0 as xid_valid, |
| 25 |
x.timestamp > '-infinity'::timestamptz AS ts_low, |
| 26 |
x.timestamp <= now() AS ts_high, |
| 27 |
roident != 0 AS valid_roident |
| 28 |
FROM pg_last_committed_xact() x; |
| 29 |
|
| 30 |
-- Test non-normal transaction ids. |
| 31 |
SELECT * FROM pg_xact_commit_timestamp_origin(NULL); -- ok, NULL |
| 32 |
SELECT * FROM pg_xact_commit_timestamp_origin('0'::xid); -- error |
| 33 |
SELECT * FROM pg_xact_commit_timestamp_origin('1'::xid); -- ok, NULL |
| 34 |
SELECT * FROM pg_xact_commit_timestamp_origin('2'::xid); -- ok, NULL |
| 35 |
|
| 36 |
-- Test transaction without replication origin |
| 37 |
SELECT txid_current() as txid_no_origin \gset |
| 38 |
SELECT x.timestamp > '-infinity'::timestamptz AS ts_low, |
| 39 |
x.timestamp <= now() AS ts_high, |
| 40 |
roident != 0 AS valid_roident |
| 41 |
FROM pg_last_committed_xact() x; |
| 42 |
SELECT x.timestamp > '-infinity'::timestamptz AS ts_low, |
| 43 |
x.timestamp <= now() AS ts_high, |
| 44 |
roident != 0 AS valid_roident |
| 45 |
FROM pg_xact_commit_timestamp_origin(:'txid_no_origin') x; |
| 46 |
|
| 47 |
-- Test transaction with replication origin |
| 48 |
SELECT pg_replication_origin_create('regress_commit_ts: get_origin') != 0 |
| 49 |
AS valid_roident; |
| 50 |
SELECT pg_replication_origin_session_setup('regress_commit_ts: get_origin'); |
| 51 |
SELECT txid_current() as txid_with_origin \gset |
| 52 |
SELECT x.timestamp > '-infinity'::timestamptz AS ts_low, |
| 53 |
x.timestamp <= now() AS ts_high, |
| 54 |
r.roname |
| 55 |
FROM pg_last_committed_xact() x, pg_replication_origin r |
| 56 |
WHERE r.roident = x.roident; |
| 57 |
SELECT x.timestamp > '-infinity'::timestamptz AS ts_low, |
| 58 |
x.timestamp <= now() AS ts_high, |
| 59 |
r.roname |
| 60 |
FROM pg_xact_commit_timestamp_origin(:'txid_with_origin') x, pg_replication_origin r |
| 61 |
WHERE r.roident = x.roident; |
| 62 |
|
| 63 |
SELECT pg_replication_origin_session_reset(); |
| 64 |
SELECT pg_replication_origin_drop('regress_commit_ts: get_origin'); |