pg_xact_status() 是一个报告近期事务提交状态的系统函数。
pg_xact_status() 在 PostgreSQL 13 中添加。
用法
pg_xact_status (xid8) →text
pg_xact_status() 返回以下值之一
committedin progressaborted
pg_xact_status() 替代了 txid_status()。
变更历史
- PostgreSQL 13
- added (commit 4c04be9b)
示例
pg_xact_status() 的基本用法示例
postgres=# BEGIN;
BEGIN
postgres=*# SELECT pg_current_xact_id();
pg_current_xact_id
--------------------
762
(1 row)
postgres=*# SELECT pg_xact_status('762');
pg_xact_status
----------------
in progress
(1 row)
postgres=*# COMMIT;
COMMIT
postgres=# SELECT pg_xact_status('762');
pg_xact_status
----------------
committed
(1 row)
尝试检索尚未发生的事务的状态
postgres=# SELECT pg_xact_status('9999');
ERROR: transaction ID 9999 is in the future
参考资料
- PostgreSQL documentation: 事务 ID 和快照信息函数
