Updated on 2026-07-02 GMT+08:00

Transaction IDs and Snapshots

The following functions provide server transaction information in an exportable form. The main use of these functions is to determine which transactions were committed between two snapshots.

pgxc_is_committed(transaction_id)

Description: Determines whether the given XID is committed or ignored. NULL indicates the unknown status (such as running, preparing, and freezing).

Return type: Boolean

txid_current()

Description: Gets current transaction ID.

Return type: bigint

txid_current_snapshot()

Description: Gets current snapshot.

Return type: txid_snapshot

txid_snapshot_xip(txid_snapshot)

Description: Gets in-progress transaction IDs in snapshot.

Return type: setof bigint

txid_snapshot_xmax(txid_snapshot)

Description: Gets xmax of snapshot.

Return type: bigint

txid_snapshot_xmin(txid_snapshot)

Description: Gets xmin of snapshot.

Return type: bigint

txid_visible_in_snapshot(bigint, txid_snapshot)

Description: Queries whether the transaction ID is visible in snapshot. (do not use with subtransaction ids)

Return type: boolean

The internal transaction ID type (xid) is 32 bits wide and wraps around every 4 billion transactions. txid_snapshot, the data type used by these functions, stores information about transaction ID visibility at a particular moment in time. Table 1 describes its components.

txid_snapshot's textual representation is xmin:xmax:xip_list.

For example, 10:20:10,14,15 indicates xmin=10, xmax=20, xip_list=10, 14, 15.

Table 1 Snapshot components

Component

Description

xmin

Earliest transaction ID (txid) that is still active. All earlier transactions will either be committed and visible, or rolled back.

xmax

First as-yet-unassigned txid. All txids greater than or equal to this are not yet started as of the time of the snapshot, so they are invisible.

xip_list

Active txids at the time of the snapshot. The list includes only those active txids between xmin and xmax; there might be active txids higher than xmax. A txid that is xmin <= txid < xmax and not in this list was already completed at the time of the snapshot, and is either visible or dead according to its commit status. The list does not include txids of subtransactions.

pgxc_gtm_txn_status()

Description: Retrieves information about all current transactions on the GTM. This function is supported only in clusters of version 9.1.1.300 or later.

Table 2 pgxc_gtm_txn_status() return columns

Column

Type

Description

slotnum

integer

Slot ID on the GTM.

threadid

bigint

Thread ID on the GTM.

gxid

xid

Global transaction ID.

state

test

Transaction status.

xmin

xid

Minimum transaction ID.

xmax

xid

Maximum transaction ID.

isolevel

test

Transaction isolation level. Options:

  • read committed: read committed isolation level.
  • repeatable read: repeatable read isolation level.

isreadonly

boolean

Whether the transaction is read-only.

isvacuum

boolean

Whether the transaction is a Vacuum.

Example:

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)