track_commit_timestamp
是一个 配置参数,用于确定是否应跟踪事务的提交时间。
track_commit_timestamp
在 PostgreSQL 9.5 中添加。
默认值
track_commit_timestamp
的默认值为:off
。
用法
track_commit_timestamp
主要用于逻辑复制解决方案(如 pglogical
),其中提交时间用作冲突解决的一部分。
track_commit_timestamp
的当前值是 pg_control
中记录的配置参数之一(PostgreSQL 9.5 及更高版本)。
必须启用 track_commit_timestamp
,以下系统函数才能返回有用的数据
pg_stat_subscription_stats 中的以下列仅在订阅者上启用了 track_commit_timestamp
时才会更新(PostgreSQL 18 及更高版本)
confl_update_origin_differs
confl_delete_origin_differs
按PostgreSQL版本分列详细信息
变更历史
- PostgreSQL 9.5
- 添加 (提交 73c986ad)
示例
postgres=# SHOW track_commit_timestamp ; track_commit_timestamp ------------------------ on (1 row) postgres=# CREATE TABLE xact_test (id INT, val TEXT); CREATE TABLE postgres=# BEGIN ; BEGIN postgres=*# SELECT pg_current_xact_id(); txid_current -------------- 508 (1 row) postgres=*# INSERT INTO xact_test VALUES (1, 'foo'), (2, 'bar'), (3, 'baz'); INSERT 0 3 postgres=*# SELECT pg_xact_commit_timestamp(xmin), xmin, * FROM xact_test; pg_xact_commit_timestamp | xmin | id | val --------------------------+------+----+----- | 508 | 1 | foo | 508 | 2 | bar | 508 | 3 | baz (3 rows) postgres=*# COMMIT; postgres=# SELECT pg_xact_commit_timestamp(xmin), xmin, * FROM xact_test ; pg_xact_commit_timestamp | xmin | id | val -------------------------------+------+----+----- 2020-10-25 12:36:47.549053+01 | 508 | 1 | foo 2020-10-25 12:36:47.549053+01 | 508 | 2 | bar 2020-10-25 12:36:47.549053+01 | 508 | 3 | baz (3 rows) postgres=# SELECT * FROM pg_last_committed_xact(); xid | timestamp -----+------------------------------- 508 | 2020-10-25 12:36:47.549053+01 (1 row)
相应的 WAL 记录(由 pg_waldump
输出)
rmgr: Heap len (rec/tot): 63/ 63, tx: 508, lsn: 0/03031490, prev 0/03031458, desc: INSERT off 10 flags 0x00, blkref #0: rel 1663/13580/16456 blk 0 rmgr: Heap len (rec/tot): 63/ 63, tx: 508, lsn: 0/030314D0, prev 0/03031490, desc: INSERT off 11 flags 0x00, blkref #0: rel 1663/13580/16456 blk 0 rmgr: Heap len (rec/tot): 63/ 63, tx: 508, lsn: 0/03031510, prev 0/030314D0, desc: INSERT off 12 flags 0x00, blkref #0: rel 1663/13580/16456 blk 0 rmgr: Transaction len (rec/tot): 34/ 34, tx: 508, lsn: 0/03031588, prev 0/03031550, desc: COMMIT 2020-10-25 12:36:47.549053 MET
参考
- PostgreSQL文档: track_commit_timestamp