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 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).

Return type: Boolean

pgxc_is_committed(transaction_id, bucketid)

Description: The hash bucket table is not supported in the current version in centralized mode. An error is reported when the function is called.

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. If this function is called, false is returned.

Return type: Boolean

gs_get_next_xid_csn()

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

For details about the return values, see Table 2.

Table 2 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

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, and oid oid.

pv_thread_memory_detail

Description: Returns the memory information of each thread. In the multi-tenancy scenario, all information is returned if this function is called in a non-PDB, and an empty list is returned if this function is called in a PDB.

Parameter: nan

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

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. In the multi-tenancy scenario, this function is disabled in a PDB.

Parameter: location text

pg_shared_memory_detail

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

Parameter: nan

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

get_gtm_lite_status

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

gs_stat_get_wlm_plan_operator_info

Description: Obtains operator plan information from the internal hash table.

Parameter: oid

Return type: datname text, queryid int8, plan_node_id int4, startup_time int8, total_time int8, actual_rows int8, max_peak_memory int4, query_dop int4, parent_node_id int4, left_child_id int4, right_child_id int4, operation text, orientation text, strategy text, options text, condition text, projection text

pg_stat_get_partition_tuples_hot_updated

Description: Returns statistics on the number of hot updated tuples in a partition with a specified partition ID.

Parameter: oid

Return type: bigint

gs_session_memory_detail_tp

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

Parameter: nan

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

gs_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_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

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

gs_get_current_version()

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

Parameter: nan

Return type: char

gs_get_kernel_info()

Description: Transaction information on DNs.

For details about the return values, see Table 3.

Table 3 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 local active transactions)
  • recent_global_xmin (minimum XID of global active transactions)
  • 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  
--------------+---------+-------------------------------+---------
 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
(17 row)