| 1 |
-- |
| 2 |
-- Commit Timestamp |
| 3 |
-- |
| 4 |
SHOW track_commit_timestamp; |
| 5 |
track_commit_timestamp |
| 6 |
------------------------ |
| 7 |
off |
| 8 |
(1 row) |
| 9 |
|
| 10 |
CREATE TABLE committs_test(id serial, ts timestamptz default now()); |
| 11 |
INSERT INTO committs_test DEFAULT VALUES; |
| 12 |
INSERT INTO committs_test DEFAULT VALUES; |
| 13 |
INSERT INTO committs_test DEFAULT VALUES; |
| 14 |
SELECT id, |
| 15 |
pg_xact_commit_timestamp(xmin) >= ts, |
| 16 |
pg_xact_commit_timestamp(xmin) <= now(), |
| 17 |
pg_xact_commit_timestamp(xmin) - ts < '60s' -- 60s should give a lot of reserve |
| 18 |
FROM committs_test |
| 19 |
ORDER BY id; |
| 20 |
ERROR: could not get commit timestamp data |
| 21 |
HINT: Make sure the configuration parameter "track_commit_timestamp" is set. |
| 22 |
DROP TABLE committs_test; |
| 23 |
SELECT pg_xact_commit_timestamp('0'::xid); |
| 24 |
ERROR: cannot retrieve commit timestamp for transaction 0 |
| 25 |
SELECT pg_xact_commit_timestamp('1'::xid); |
| 26 |
pg_xact_commit_timestamp |
| 27 |
-------------------------- |
| 28 |
|
| 29 |
(1 row) |
| 30 |
|
| 31 |
SELECT pg_xact_commit_timestamp('2'::xid); |
| 32 |
pg_xact_commit_timestamp |
| 33 |
-------------------------- |
| 34 |
|
| 35 |
(1 row) |
| 36 |
|
| 37 |
SELECT x.xid::text::bigint > 0 as xid_valid, |
| 38 |
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 |
ERROR: could not get commit timestamp data |
| 43 |
HINT: Make sure the configuration parameter "track_commit_timestamp" is set. |
| 44 |
-- Test non-normal transaction ids. |
| 45 |
SELECT * FROM pg_xact_commit_timestamp_origin(NULL); -- ok, NULL |
| 46 |
timestamp | roident |
| 47 |
-----------+--------- |
| 48 |
| |
| 49 |
(1 row) |
| 50 |
|
| 51 |
SELECT * FROM pg_xact_commit_timestamp_origin('0'::xid); -- error |
| 52 |
ERROR: cannot retrieve commit timestamp for transaction 0 |
| 53 |
SELECT * FROM pg_xact_commit_timestamp_origin('1'::xid); -- ok, NULL |
| 54 |
timestamp | roident |
| 55 |
-----------+--------- |
| 56 |
| |
| 57 |
(1 row) |
| 58 |
|
| 59 |
SELECT * FROM pg_xact_commit_timestamp_origin('2'::xid); -- ok, NULL |
| 60 |
timestamp | roident |
| 61 |
-----------+--------- |
| 62 |
| |
| 63 |
(1 row) |
| 64 |
|
| 65 |
-- Test transaction without replication origin |
| 66 |
SELECT txid_current() as txid_no_origin \gset |
| 67 |
SELECT x.timestamp > '-infinity'::timestamptz AS ts_low, |
| 68 |
x.timestamp <= now() AS ts_high, |
| 69 |
roident != 0 AS valid_roident |
| 70 |
FROM pg_last_committed_xact() x; |
| 71 |
ERROR: could not get commit timestamp data |
| 72 |
HINT: Make sure the configuration parameter "track_commit_timestamp" is set. |
| 73 |
SELECT x.timestamp > '-infinity'::timestamptz AS ts_low, |
| 74 |
x.timestamp <= now() AS ts_high, |
| 75 |
roident != 0 AS valid_roident |
| 76 |
FROM pg_xact_commit_timestamp_origin(:'txid_no_origin') x; |
| 77 |
ERROR: could not get commit timestamp data |
| 78 |
HINT: Make sure the configuration parameter "track_commit_timestamp" is set. |
| 79 |
-- Test transaction with replication origin |
| 80 |
SELECT pg_replication_origin_create('regress_commit_ts: get_origin') != 0 |
| 81 |
AS valid_roident; |
| 82 |
valid_roident |
| 83 |
--------------- |
| 84 |
t |
| 85 |
(1 row) |
| 86 |
|
| 87 |
SELECT pg_replication_origin_session_setup('regress_commit_ts: get_origin'); |
| 88 |
pg_replication_origin_session_setup |
| 89 |
------------------------------------- |
| 90 |
|
| 91 |
(1 row) |
| 92 |
|
| 93 |
SELECT txid_current() as txid_with_origin \gset |
| 94 |
SELECT x.timestamp > '-infinity'::timestamptz AS ts_low, |
| 95 |
x.timestamp <= now() AS ts_high, |
| 96 |
r.roname |
| 97 |
FROM pg_last_committed_xact() x, pg_replication_origin r |
| 98 |
WHERE r.roident = x.roident; |
| 99 |
ERROR: could not get commit timestamp data |
| 100 |
HINT: Make sure the configuration parameter "track_commit_timestamp" is set. |
| 101 |
SELECT x.timestamp > '-infinity'::timestamptz AS ts_low, |
| 102 |
x.timestamp <= now() AS ts_high, |
| 103 |
r.roname |
| 104 |
FROM pg_xact_commit_timestamp_origin(:'txid_with_origin') x, pg_replication_origin r |
| 105 |
WHERE r.roident = x.roident; |
| 106 |
ERROR: could not get commit timestamp data |
| 107 |
HINT: Make sure the configuration parameter "track_commit_timestamp" is set. |
| 108 |
SELECT pg_replication_origin_session_reset(); |
| 109 |
pg_replication_origin_session_reset |
| 110 |
------------------------------------- |
| 111 |
|
| 112 |
(1 row) |
| 113 |
|
| 114 |
SELECT pg_replication_origin_drop('regress_commit_ts: get_origin'); |
| 115 |
pg_replication_origin_drop |
| 116 |
---------------------------- |
| 117 |
|
| 118 |
(1 row) |
| 119 |
|