事务ID和快照
以下的函数在输出形式中提供服务器事务信息。这些函数的主要用途是为了确定在两个快照之间有哪个事务提交。
pgxc_is_committed(transaction_id)
描述:如果提交或忽略给定的XID(gxid)。NULL表示的状态是未知的(运行,准备,冻结等)。
返回类型:bool
txid_current()
描述:获取当前事务ID。
返回类型:bigint
txid_current_snapshot()
描述:获取当前快照。
返回类型:txid_snapshot
txid_snapshot_xip(txid_snapshot)
描述:在快照中获取正在进行的事务ID。
返回类型:setof bigint
txid_snapshot_xmax(txid_snapshot)
描述:获取快照的xmax。
返回类型:bigint
txid_snapshot_xmin(txid_snapshot)
描述:获取快照的xmin。
返回类型:bigint
txid_visible_in_snapshot(bigint, txid_snapshot)
描述:在快照中事务ID是否可见(不使用子事务ID)。
返回类型:boolean
内部事务ID类型(xid)是32位,每40亿事务一次循环。这些函数使用的数据类型txid_snapshot,存储在特定时刻事务ID可见性的信息。其组件描述在表1。
txid_snapshot的文本表示为:xmin:xmax:xip_list。
例如,10:20:10,14,15表示:xmin=10, xmax=20, xip_list=10, 14, 15。
pgxc_gtm_txn_status()
描述:获取GTM上当前所有事务的信息。该函数仅9.1.1.300及以上集群版本支持。
| 名称 | 类型 | 描述 |
|---|---|---|
| slotnum | integer | GTM上的槽位号。 |
| threadid | bigint | GTM上的线程号。 |
| gxid | xid | 全局事务ID。 |
| state | test | 事务状态。 |
| xmin | xid | 最小事务ID。 |
| xmax | xid | 最大事务ID。 |
| isolevel | test | 事务的隔离级别。
|
| isreadonly | boolean | 是否是只读事务。 |
| isvacuum | boolean | 是否是Vacuum事务。 |
示例:
1 2 3 4 5 6 7 | SELECT * FROM pgxc_gtm_txn_status(); slotnum | threadid | gxid | state | xmin | xmax | isolevel | isreadonly | isvacuum ---------+-----------------+--------------+----------+--------------+--------------+-----------------+------------+---------- 10 | 140491592591104 | 0 | STARTING | 132507422568 | 0 | read committed | f | f 9 | 140491584186112 | 132507422574 | STARTING | 132507422568 | 132507422574 | read committed | f | f 6 | 140491588388608 | 132507422568 | STARTING | 132507422567 | 132507422568 | repeatable read | f | f (3 rows) |