pg_xact_commit_timestamp() 是一个返回事务提交时间戳的系统函数。
pg_xact_commit_timestamp() 于 PostgreSQL 9.5 中添加。
用法
pg_xact_commit_timestamp (xid) →timestamp with time zone
必须启用 track_commit_timestamp,否则 pg_xact_commit_timestamp() 将发出 ERROR 错误。
变更历史
- PostgreSQL 9.5
- 添加于 (提交 73c986ad)
示例
查看表中行的提交时间戳
postgres=# SELECT pg_xact_commit_timestamp(xmin), xmin, * FROM xact_test; pg_xact_commit_timestamp | xmin | id | val -------------------------------+------+----+----- 2021-07-07 08:52:14.189175+01 | 738 | 1 | foo 2021-07-07 08:52:22.72496+01 | 739 | 2 | bar 2021-07-07 08:52:26.893677+01 | 740 | 3 | baz (3 rows)
如果 track_commit_timestamp 设置为 off,pg_xact_commit_timestamp() 将会因 ERROR 错误而失败。
postgres=# SELECT pg_xact_commit_timestamp(xmin), xmin, * FROM xact_test;
ERROR: could not get commit timestamp data
HINT: Make sure the configuration parameter "track_commit_timestamp" is set.
postgres=# SELECT pg_xact_commit_timestamp('738'::xid);
ERROR: could not get commit timestamp data
HINT: Make sure the configuration parameter "track_commit_timestamp" is set.
参考资料
- PostgreSQL 文档: 已提交事务信息函数
