pg_prepared_xacts 是一个 系统目录 视图,提供有关当前已准备进行两阶段提交的事务的信息。
pg_prepared_xacts 在 PostgreSQL 8.1 中添加。
按 PostgreSQL 版本定义
pg_prepared_xacts (PostgreSQL 19)
View "pg_catalog.pg_prepared_xacts"
Column | Type | Collation | Nullable | Default
-------------+--------------------------+-----------+----------+---------
transaction | xid | | |
gid | text | | |
prepared | timestamp with time zone | | |
owner | name | | |
database | name | | |
pg_prepared_xacts (PostgreSQL 18)
View "pg_catalog.pg_prepared_xacts"
Column | Type | Collation | Nullable | Default
-------------+--------------------------+-----------+----------+---------
transaction | xid | | |
gid | text | | |
prepared | timestamp with time zone | | |
owner | name | | |
database | name | | |
pg_prepared_xacts (PostgreSQL 17)
View "pg_catalog.pg_prepared_xacts"
Column | Type | Collation | Nullable | Default
-------------+--------------------------+-----------+----------+---------
transaction | xid | | |
gid | text | | |
prepared | timestamp with time zone | | |
owner | name | | |
database | name | | |
pg_prepared_xacts (PostgreSQL 16)
View "pg_catalog.pg_prepared_xacts"
Column | Type | Collation | Nullable | Default
-------------+--------------------------+-----------+----------+---------
transaction | xid | | |
gid | text | | |
prepared | timestamp with time zone | | |
owner | name | | |
database | name | | |
pg_prepared_xacts (PostgreSQL 15)
View "pg_catalog.pg_prepared_xacts"
Column | Type | Collation | Nullable | Default
-------------+--------------------------+-----------+----------+---------
transaction | xid | | |
gid | text | | |
prepared | timestamp with time zone | | |
owner | name | | |
database | name | | |
pg_prepared_xacts (PostgreSQL 14)
View "pg_catalog.pg_prepared_xacts"
Column | Type | Collation | Nullable | Default
-------------+--------------------------+-----------+----------+---------
transaction | xid | | |
gid | text | | |
prepared | timestamp with time zone | | |
owner | name | | |
database | name | | |
pg_prepared_xacts (PostgreSQL 13)
View "pg_catalog.pg_prepared_xacts"
Column | Type | Collation | Nullable | Default
-------------+--------------------------+-----------+----------+---------
transaction | xid | | |
gid | text | | |
prepared | timestamp with time zone | | |
owner | name | | |
database | name | | |
pg_prepared_xacts (PostgreSQL 12)
View "pg_catalog.pg_prepared_xacts"
Column | Type | Collation | Nullable | Default
-------------+--------------------------+-----------+----------+---------
transaction | xid | | |
gid | text | | |
prepared | timestamp with time zone | | |
owner | name | | |
database | name | | |
pg_prepared_xacts (PostgreSQL 11)
View "pg_catalog.pg_prepared_xacts"
Column | Type | Collation | Nullable | Default
-------------+--------------------------+-----------+----------+---------
transaction | xid | | |
gid | text | | |
prepared | timestamp with time zone | | |
owner | name | | |
database | name | | |
pg_prepared_xacts (PostgreSQL 10)
View "pg_catalog.pg_prepared_xacts"
Column | Type | Collation | Nullable | Default
-------------+--------------------------+-----------+----------+---------
transaction | xid | | |
gid | text | | |
prepared | timestamp with time zone | | |
owner | name | | |
database | name | | |
pg_prepared_xacts (PostgreSQL 9.6)
View "pg_catalog.pg_prepared_xacts"
Column | Type | Modifiers
-------------+--------------------------+-----------
transaction | xid |
gid | text |
prepared | timestamp with time zone |
owner | name |
database | name |
pg_prepared_xacts (PostgreSQL 9.5)
View "pg_catalog.pg_prepared_xacts"
Column | Type | Modifiers
-------------+--------------------------+-----------
transaction | xid |
gid | text |
prepared | timestamp with time zone |
owner | name |
database | name |
pg_prepared_xacts (PostgreSQL 9.4)
View "pg_catalog.pg_prepared_xacts"
Column | Type | Modifiers
-------------+--------------------------+-----------
transaction | xid |
gid | text |
prepared | timestamp with time zone |
owner | name |
database | name |
pg_prepared_xacts (PostgreSQL 9.3)
View "pg_catalog.pg_prepared_xacts"
Column | Type | Modifiers
-------------+--------------------------+-----------
transaction | xid |
gid | text |
prepared | timestamp with time zone |
owner | name |
database | name |
pg_prepared_xacts (PostgreSQL 9.2)
View "pg_catalog.pg_prepared_xacts"
Column | Type | Modifiers
-------------+--------------------------+-----------
transaction | xid |
gid | text |
prepared | timestamp with time zone |
owner | name |
database | name |
pg_prepared_xacts (PostgreSQL 9.1)
View "pg_catalog.pg_prepared_xacts"
Column | Type | Modifiers
-------------+--------------------------+-----------
transaction | xid |
gid | text |
prepared | timestamp with time zone |
owner | name |
database | name |
pg_prepared_xacts (PostgreSQL 9.0)
View "pg_catalog.pg_prepared_xacts"
Column | Type | Modifiers
-------------+--------------------------+-----------
transaction | xid |
gid | text |
prepared | timestamp with time zone |
owner | name |
database | name |
pg_prepared_xacts (PostgreSQL 8.4)
View "pg_catalog.pg_prepared_xacts"
Column | Type | Modifiers
-------------+--------------------------+-----------
transaction | xid |
gid | text |
prepared | timestamp with time zone |
owner | name |
database | name |
View definition:
SELECT p.transaction, p.gid, p.prepared, u.rolname AS owner, d.datname AS database
FROM pg_prepared_xact() p(transaction, gid, prepared, ownerid, dbid)
LEFT JOIN pg_authid u ON p.ownerid = u.oid
LEFT JOIN pg_database d ON p.dbid = d.oid;
pg_prepared_xacts (PostgreSQL 8.3)
View "pg_catalog.pg_prepared_xacts"
Column | Type | Modifiers
-------------+--------------------------+-----------
transaction | xid |
gid | text |
prepared | timestamp with time zone |
owner | name |
database | name |
View definition:
SELECT p.transaction, p.gid, p.prepared, u.rolname AS owner, d.datname AS database
FROM pg_prepared_xact() p(transaction xid, gid text, prepared timestamp with time zone, ownerid oid, dbid oid)
LEFT JOIN pg_authid u ON p.ownerid = u.oid
LEFT JOIN pg_database d ON p.dbid = d.oid;
pg_prepared_xacts (PostgreSQL 8.2)
View "pg_catalog.pg_prepared_xacts"
Column | Type | Modifiers
-------------+--------------------------+-----------
transaction | xid |
gid | text |
prepared | timestamp with time zone |
owner | name |
database | name |
View definition:
SELECT p."transaction", p.gid, p."prepared", u.rolname AS "owner", d.datname AS "database"
FROM pg_prepared_xact() p("transaction" xid, gid text, "prepared" timestamp with time zone, ownerid oid, dbid oid)
LEFT JOIN pg_authid u ON p.ownerid = u.oid
LEFT JOIN pg_database d ON p.dbid = d.oid;
变更历史
- PostgreSQL 8.1
- 添加(提交 d0a89683)
pg_prepared_xacts 自在 PostgreSQL 8.1 中添加后未被修改。
示例
示例内容:
postgres=# BEGIN; BEGIN postgres=*# PREPARE TRANSACTION 'foo'; PREPARE TRANSACTION postgres=# SELECT * FROM pg_prepared_xacts; transaction | gid | prepared | owner | database -------------+-----+-------------------------------+----------+---------- 721 | foo | 2021-09-07 10:49:32.784179+01 | postgres | postgres (1 row)
参考资料
- PostgreSQL 文档: pg_prepared_xacts
