Updated on 2025-05-29 GMT+08:00

XIDs and Snapshots

Internal XIDs are 64 bits. txid_snapshot, data type used by these functions, stores information about XID visibility at a particular moment in time. Table 1 Snapshot components describes the components.
Table 1 Snapshot components

Name

Description

xmin

Earliest XID (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 greater than or equal to xmin and less than xmax and that is not in this list was already completed at the time of the snapshot, and is either visible or rolled back according to its commit status. The list does not include txids of subtransactions.

The textual representation of txid_snapshot is xmin:xmax:xip_list.

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

The following functions provide server transaction information in an exportable form. These functions are mainly used to determine which transactions were committed between two snapshots.

pgxc_is_committed(transaction_id)

Description: Specifies whether the given XID (gxid) of an ordinary table is committed or ignored. NULL indicates an unknown state (such as running, preparing, or freezing). In maintenance mode (when the GUC parameter xc_maintenance_mode is set to on), the statuses of all transactions with the specified bucket IDs and ordinary tables are traversed. If a status conflict occurs, for example, the status of the same transaction is committed in bucket 1 and rolled back in bucket 2, an error is reported. Exercise caution when enabling the mode. It is used by maintenance engineers for troubleshooting. Common users should not use the mode.

Return type: Boolean

pgxc_is_committed(transaction_id, bucketid)

Description: Commits or ignores the given transaction (gxid) if bucketid is specified. NULL indicates that the status is unknown (running, ready, or frozen). bucketid is the physical bucket ID of the hash bucket table. The value is –1 for an ordinary table. In maintenance mode (when the GUC parameter xc_maintenance_mode is set to on), if bucketid is set to –1, the statuses of all transactions with the specified bucket IDs and ordinary tables are traversed. If a status conflict occurs, for example, the status of the same transaction is committed in bucket 1 and rolled back in bucket 2, an error is reported. Exercise caution when enabling the mode. It is used by maintenance engineers for troubleshooting. Common users should not use the mode.

Return type: Boolean

txid_current()

Description: Obtains the current XID.

Return type: bigint

gs_txid_oldestxmin()

Description: Obtains the minimum XID (specified by oldesxmin).

Return type: bigint

txid_current_snapshot()

Description: Obtains the current snapshot.

Return type: txid_snapshot

txid_snapshot_xip(txid_snapshot)

Description: Obtains in-progress XIDs in a snapshot.

Return type: setof bigint

txid_snapshot_xmax(txid_snapshot)

Description: Obtains xmax of snapshots.

Return type: bigint

txid_snapshot_xmin(txid_snapshot)

Description: Obtains xmin of snapshots.

Return type: bigint

txid_visible_in_snapshot(bigint, txid_snapshot)

Description: Specifies whether the XID is visible in a snapshot (do not use subtransaction IDs).

Return type: Boolean

get_local_prepared_xact()

Description: Obtains the two-phase residual transaction information of the current node, including the XID, GID of the two-phase transaction, prepared time, owner OID, database OID, and node name of the current node.

Return type: xid, text, timestamptz, oid, text

get_remote_prepared_xacts()

Description: Obtains the two-phase residual transaction information of all remote nodes, including the XID, GID of the two-phase transaction, prepared time, owner name, database name, and node name.

Return type: xid, text, timestamptz, name, text

global_clean_prepared_xacts(text, text)

Description: Concurrently cleans two-phase residual transactions. Only the gs_clean tool can call this function for cleaning. In other situations, false is returned.

Return type: Boolean

pgxc_stat_get_wal_senders()

Description: Returns the sent logs of all primary DNs and the received logs of their corresponding standby DNs in the cluster. Only users with the system admin or monitor admin permission can use this function.

Table 2 pgxc_stat_get_wal_senders output parameters describes the return values.
Table 2 pgxc_stat_get_wal_senders parameters

Column

Description

nodename

Instance name.

sender_pid

PID of the thread for sending logs.

local_role

Instance role.

peer_role

Role of the instance on the receiver.

peer_state

Status of the instance on the receiver.

state

Synchronization status between instances.

sender_sent_location

Location where the sender sends logs.

sender_write_location

Location where the sender writes logs.

sender_flush_location

Location where the sender flushes logs to disks.

sender_replay_location

Log location of the current instance. If the DN is a primary DN, the location is the value of sender_flush_location. Otherwise, the location where the current instance log is replayed is used.

receiver_received_location

Location where the receiver receives logs.

receiver_write_location

Location where the receiver writes logs.

receiver_flush_location

Location where the receiver flushes logs to disks.

receiver_replay_location

Location where the receiver replays logs.

pgxc_stat_get_wal_senders_status()

Description: Returns the receiving status of transaction logs on all nodes. Only users with the system admin or monitor admin permission can use this function.

Table 3 pgxc_stat_get_wal_senders_status output parameters describes the return values.

Table 3 pgxc_stat_get_wal_senders_status parameters

Column

Description

nodename

Name of the primary node

source_ip

IP address of the primary node

source_port

Port of the primary node

dest_ip

IP address of the standby node

dest_port

Port of the standby node

sender_pid

PID of the sending thread

local_role

Type of the primary node

peer_role

Type of the standby node

peer_state

Status of the standby node

state

WAL sender status

sender_sent_location

Sending position of the primary node

sender_write_location

Writing position of the primary node

sender_replay_location

Redo position of the primary node

receiver_received_location

Receiving position of the standby node

receiver_write_location

Writing position of the standby node

receiver_flush_location

Flushing location of the standby node

receiver_replay_location

Redo location of the standby node

gs_get_next_xid_csn()

Description: Returns the values of next_xid and next_csn on all nodes globally.

Table 4 gs_get_next_xid_csn return parameters describes the return values.

Table 4 gs_get_next_xid_csn parameters

Column

Description

nodename

Node name

next_xid

ID of the next transaction on the current node.

next_csn

Next CSN of the current node.

pg_control_system()

Description: Returns the status of the system control file.

Return type: SETOF record

pg_control_checkpoint()

Description: Returns the system checkpoint status

Return type: SETOF record

get_prepared_pending_xid()

Description: Returns nextxid when restoration is complete.

Parameter: nan

Return type: text

pg_clean_region_info()

Description: Clears the region map.

Parameter: nan

Return type: character varying

pg_get_replication_slot_name()

Description: Obtains the slot name.

Parameter: nan

Return type: text

pg_get_running_xacts()

Description: Obtains running xact.

Parameter: nan

Return type: handle integer, gxid xid, state tinyint, node text, xmin xid, vacuum Boolean, timeline bigint, prepare_xid xid, pid bigint, next_xid xid, dbid oid

pg_get_variable_info()

Description: Obtains the shared memory variable cache.

Parameter: nan

Return type: node_name text, nextOid oid, nextXid xid, oldestXid xid, xidVacLimit xid, oldestXidDB oid, lastExtendCSNLogpage xid, startExtendCSNLogpage xid, nextCommitSeqNo xid, latestCompletedXid xid, and startupMaxXid xid

pg_get_xidlimit()

Description: Obtains XID information from the shared memory.

Parameter: nan

Return type: nextXid xid, oldestXid xid, xidVacLimit xid, xidWarnLimit xid, xidStopLimit xid, xidWrapLimit xid, oldestXidDB oid

pg_relation_compression_ratio()

Description: Queries the compression rate of a table. By default, 1.0 is returned.

Parameter: text

Return type: real

pg_relation_with_compression()

Description: Specifies whether a table is compressed.

Parameter: text

Return type: Boolean

pg_stat_file_recursive()

Description: Lists all files in a path.

Parameter: location text

Return type: path text, filename text, size bigint, isdir Boolean

pg_stat_get_activity_for_temptable()

Description: Returns records of backend threads related to the temporary table.

Parameter: nan

Return type: datid oid, timelineid integer, tempid integer, and sessionid bigint

pg_stat_get_activity_ng()

Description: Returns records of backend threads related to nodegroup.

Parameter: pid bigint

Return type: datid oid, pid bigint, sessionid bigint, and node_group text

pg_stat_get_cgroup_info()

Description: Returns Cgroup information.

Parameter: nan

Return type: cgroup_name text, percent integer, usage_percent integer, shares bigint, usage bigint, cpuset text, relpath text, valid text, node_group text

pg_stat_get_realtime_info_internal()

Description: Returns real-time information. Currently, this API is unavailable. FailedToGetSessionInfo is returned.

Parameter: oid, oid, bigint, cstring, oid

Return type: text

pg_stat_get_wlm_session_iostat_info()

Description: Returns the session load I/O information.

Parameter: nan

Return type: threadid bigint, maxcurr_iops integer, mincurr_iops integer, maxpeak_iops integer, minpeak_iops integer, iops_limits integer, io_priority integer, and curr_io_limits integer

pg_test_err_contain_err()

Description: Tests the error type and return information.

Parameter: integer

Return type: void

pv_session_memory_detail_tp()

Description: Returns the memory usage of the session. For details, see pv_session_memory_detail.

Parameter: nan

Return type: sessid text, sesstype text, contextname text, level smallint, parent text, totalsize bigint, freesize bigint, usedsize bigint

gs_get_table_distribution()

Description: Returns the distribution of table data on each DN.

Parameter: table_name text, schema_name text

Return type: text

pv_builtin_functions()

Description: Displays information about all built-in system functions.

Parameter: nan

Return type: proname name, pronamespace oid, proowner oid, prolang oid, procost real, prorows real, provariadic oid, protransform regproc, proisagg Boolean, proiswindow Boolean, prosecdef Boolean, proleakproof Boolean, proisstrict Boolean, proretset Boolean, provolatile "char", pronargs smallint, pronargdefaults smallint, prorettype oid, proargtypes oidvector, proallargtypes integer[], proargmodes "char"[], proargnames text[], proargdefaults pg_node_tree, prosrc text, probin text, proconfig text[], proacl aclitem[], prodefaultargpos int2vector, fencedmode Boolean, proshippable Boolean, propackage Boolean, oid oid

pv_thread_memory_detail()

Description: Returns the memory information of each thread.

Parameter: nan

Return type: threadid text, tid bigint, thrdtype text, contextname text, level smallint, parent text, totalsize bigint, freesize bigint, usedsize bigint

pg_shared_memory_detail()

Description: Returns usage information about all generated shared memory contexts. For details about each column, see SHARED_MEMORY_DETAIL.

Parameter: nan

Return type: contextname text, level smallint, parent text, totalsize bigint, freesize bigint, usedsize bigint

pgxc_get_running_xacts()

Description: Returns information about running transactions on each node in the cluster. The field content is the same as that in PGXC_RUNNING_XACTS. Only users with the system admin or monitor admin permission can view the information.

Parameter: nan

Return type: setof record

pgxc_snapshot_status()

Description: Returns the status of key memory information in the GTM in GTM mode for fault locating. GTM-Free and GTM-Lite do not support this function.

Parameter: nan

Return type: xmin xid, xmax xid, xcnt int, oldestxmin xid, next_xid xid, timeline int, active_thread_num int, max_active_thread_num int, snapshot_num int, snapshot_totalsize bigint

Table 5 get_gtm_lite_status return parameters describes the return values.

Table 5 get_gtm_lite_status return parameters

Column

Description

xmin

Minimum active XID in the GTM.

xmax

Largest XID committed in the GTM plus 1. Transactions whose IDs are greater than or equal to this value are active.

xcnt

Number of active transactions in the GTM.

oldestxmin

ID of the earliest accessed transaction in the GTM.

next_xid

ID of the next transaction allocated by the GTM.

timeline

Current time line in the GTM.

active_thread_num

Number of active worker threads in the GTM.

max_active_thread_num

Peak number of worker threads in the GTM within one minute.

snapshot_num

Number of snapshots delivered by the GTM within one minute.

snapshot_totalsize

Total size of snapshots delivered by the GTM within one minute.

get_gtm_lite_status()

Description: Returns the backup XID and CSN in the GTM for fault locating. This system function is not supported in GTM-Free mode.

Table 6 get_gtm_lite_status return parameters describes the return values.
Table 6 get_gtm_lite_status return parameters

Column

Description

backup_xid

Backup XID in the GTM.

csn

Latest CSN issued by the GTM.

adm_hist_snapshot_func()

Description: Returns information about the snapshot execution time. To access this function, set the enable_wdr_snapshot parameter to on and obtain the permission to access the snapshot schema, snapshot table, and tables_snap_timestamp tables.

Parameter: nan

Return type: snap_id bigint, dbid oid, begin_interval_time timestamp(3), end_interval_time timestamp(3), flush_elapsed interval day(5) to second(1), begin_interval_time_tz timestamp(3) with time zone, end_interval_time_tz timestamp(3) with time zone

global_sql_patch_func()

Description: SQL patch information on each global node, which is used to return the result of the global_sql_patch view.

Table 7 global_sql_patch_func return parameters describes the return values.

Table 7 global_sql_patch_func return parameters

Name

Type

Description

node_name

text

Name of the node where the SQL patch is located.

patch_name

name

Patch name.

unique_sql_id

bigint

Global unique query ID.

owner

oid

ID of the user who creates the patch.

enable

boolean

Determines whether the patch takes effect.

status

"char"

Patch status (reserved field).

abort

boolean

Determines whether the value is AbortHint.

hint_string

text

Hint text.

description

text

Patch description.

parent_unique_sql_id

bigint

Globally unique ID of the outer statement of the SQL statement for which the patch takes effect. The value of this parameter is 0 for statements outside a stored procedure. For statements inside the stored procedure, the value of this parameter is the globally unique ID of the statement that calls the stored procedure.

gs_get_current_version()

Description: Returns the current compilation mode based on the current compilation macro. 'M' is returned.

Parameter: nan

Return type: char

gs_get_kernel_info()

Description: Global transaction information on each primary CN and DN.

Table 8 gs_get_kernel_info output parameters describes the return values.

Table 8 gs_get_kernel_info parameters

Name

Type

Description

node_name

text

Node name.

module

text

Module name, including:

  • XACT (transaction module)
  • STANDBY (standby module)
  • UNDO (undo module)
  • HOTPATH (hot patch module)

name

text

Name of the key data in the memory state, including:

  • startup_max_xid (maximum XID when a thread is started)
  • recent_local_xmin (minimum XID of a local active transaction) recent_global_xmin (minimum XID of a global active transaction)
  • standby_xmin (minimum XID of an active transaction on the standby node)
  • standby_redo_cleanup_xmin (minimum XID of cleanup logs during redo on the standby node)
  • standby_redo_cleanup_xmin_lsn (LSN of the minimum XID of cleanup logs during redo on the standby node)
  • local_csn_min (minimum CSN of a local active transaction)
  • replication_slot_xmin (minimum XID of a replication slot)
  • replication_slot_catalog_xmin (minimum XID of a catalog replication slot)
  • global_recycle_xid (minimum XID of a global undo recycling transaction)
  • global_frozen_xid (minimum XID of a globally frozen transaction)
  • recent_xmin (minimum XID of active transactions in the current session)
  • next_csn (CSN of the next transaction)
  • hotpatch_additional_info (reserved column for hot patches)
  • stmt_session_discard_records (data volume discarded by full SQL statements due to full slots supported by the kernel)
  • stmt_shm_flush_discard_records (data volume discarded by full SQL statements due to full ringbuf supported by the kernel)
  • idle_in_trans_timeout_records (accumulated data volume of idle transaction timeout counts supported by the kernel)

value

text

Value of the key data in the memory state.

Example:

gaussdb=# SELECT * FROM gs_get_kernel_info();
  node_name   | module  |             name              |  value  
--------------+---------+-------------------------------+---------
 coordinator1 | XACT    | startup_max_xid               | 16488
 coordinator1 | XACT    | recent_local_xmin             | 16504
 coordinator1 | XACT    | recent_global_xmin            | 16503
 coordinator1 | STANDBY | standby_xmin                  | 0
 coordinator1 | STANDBY | standby_redo_cleanup_xmin     | 0
 coordinator1 | STANDBY | standby_redo_cleanup_xmin_lsn | 0/0
 coordinator1 | XACT    | local_csn_min                 | 6014225
 coordinator1 | XACT    | replication_slot_xmin         | 0
 coordinator1 | XACT    | replication_slot_catalog_xmin | 0
 coordinator1 | UNDO    | global_recycle_xid            | 16501
 coordinator1 | XACT    | global_frozen_xid             | 0
 coordinator1 | XACT    | recent_xmin                   | 16504
 coordinator1 | XACT    | next_csn                      | 6014226
 coordinator1 | HOTPATH | hotpatch_additional_info      | 
 coordinator1 | FULL_SQL| stmt_session_discard_records  | 0
 coordinator1 | FULL_SQL| stmt_shm_flush_discard_records| 0
 coordinator1 | XACT    | idle_in_trans_timeout_records | 0
 datanode1    | XACT    | startup_max_xid               | 16488
 datanode1    | XACT    | recent_local_xmin             | 15805
 datanode1    | XACT    | recent_global_xmin            | 15805
 datanode1    | STANDBY | standby_xmin                  | 0
 datanode1    | STANDBY | standby_redo_cleanup_xmin     | 0
 datanode1    | STANDBY | standby_redo_cleanup_xmin_lsn | 0/0
 datanode1    | XACT    | local_csn_min                 | 6014225
 datanode1    | XACT    | replication_slot_xmin         | 0
 datanode1    | XACT    | replication_slot_catalog_xmin | 0
 datanode1    | UNDO    | global_recycle_xid            | 15805
 datanode1    | XACT    | global_frozen_xid             | 0
 datanode1    | XACT    | recent_xmin                   | 15805
 datanode1    | XACT    | next_csn                      | 6014226
 datanode1    | HOTPATH | hotpatch_additional_info      | 
 datanode1    | FULL_SQL| stmt_session_discard_records  | 0
 datanode1    | FULL_SQL| stmt_shm_flush_discard_records| 0
 datanode1    | XACT    | idle_in_trans_timeout_records | 0
(34 row)