云数据库 GAUSSDB-系统信息函数:事务ID和快照

时间:2024-04-26 16:15:43

事务ID和快照

内部事务ID类型(xid)是64位。这些函数使用的数据类型txid_snapshot,存储在特定时刻事务ID可见性的信息。其组件描述在表14
表14 快照组件

名称

描述

xmin

最早的事务ID(txid)仍然活动。所有较早事务将是已经提交可见的,或者是直接回滚。

xmax

作为尚未分配的txid。所有大于或等于此txids的都是尚未开始的快照时间,因此不可见。

xip_list

当前快照中活动的txids。这个列表只包含在xmin和xmax之间活动的txids;有可能活动的txids高于xmax。介于大于等于xmin、小于xmax,并且不在这个列表中的txid,在这个时间快照已经完成的,因此按照提交状态查看他是可见还是回滚。这个列表不包含子事务的txids。

txid_snapshot的文本表示为:xmin:xmax:xip_list。

示例:10:20:10,14,15意思为:xmin=10, xmax=20, xip_list=10, 14, 15。

以下的函数在一个输出形式中提供服务器事务信息。这些函数的主要用途是为了确定在两个快照之间有哪个事务提交。

  • pgxc_is_committed(transaction_id)

    描述:如果提交或忽略给定的XID(gxid)。NULL表示的状态是未知的(运行、准备、冻结等)。

    返回类型:bool

  • txid_current()

    描述:获取当前事务ID。

    返回类型:bigint

  • gs_txid_oldestxmin()

    描述:获取当前最小事务id的值oldesxmin。

    返回类型: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

  • get_local_prepared_xact()

    描述:获取当前节点两阶段残留事务信息,包括事务id,两阶段gid名称,prepared的时间,owner的oid,database的oid及当前节点的node_name。

    返回类型:xid, text, timestamptz, oid, oid,text

  • get_remote_prepared_xacts()

    描述:获取所有远程节点两阶段残留事务信息,包括事务id,两阶段gid名称,prepared的时间,owner的名称,database的名称及node_name。

    返回类型:xid, text, timestamptz, name, name,text

  • global_clean_prepared_xacts(text, text)

    描述:并发清理两阶段残留事务,仅gs_clean工具调用该函数进行清理,其他情况下调用均返回false。

    返回类型:Boolean

  • pgxc_stat_get_wal_senders()

    描述:返回集群中所有主DN的发送日志的信息和其对应的备DN的接收日志的信息。仅支持system admin或monitor admin权限用户使用。

    返回值如下:
    表15 pgxc_stat_get_wal_senders返回参数说明

    字段名

    描述

    nodename

    实例名。

    sender_pid

    发送日志的线程pid。

    local_role

    实例角色。

    peer_role

    接收端的实例的角色。

    peer_state

    接收端的实例的状态。

    state

    实例间同步的状态。

    sender_sent_location

    发送端发送日志的位置。

    sender_write_location

    发送端写日志的位置。

    sender_flush_location

    发送端刷盘日志的位置。

    sender_replay_location

    当前实例的日志位置。如果是主DN,则该位置和

    sender_flush_location相同;否则该位置为当前实例日志回放到的位置。

    receiver_received_location

    接收端日志接收到的位置。

    receiver_write_location

    接收端日志写的位置。

    receiver_flush_location

    接收端日志刷盘的位置。

    receiver_replay_location

    接收端日志回放的位置。

  • pgxc_stat_get_wal_senders_status()

    描述:返回所有节点事务日志接收状态。仅支持system admin或monitor admin权限用户使用。

    返回值如下:

    表16 pgxc_stat_get_wal_senders_status返回参数说明

    字段名

    描述

    nodename

    主节点名。

    source_ip

    主节点IP。

    source_port

    主节点端口。

    dest_ip

    备节点IP。

    dest_port

    备节点端口。

    sender_pid

    发送线程PID。

    local_role

    主节点类型。

    peer_role

    备节点类型。

    peer_state

    备节点状态。

    state

    wal sender状态。

    sender_sent_location

    主节点发送位置。

    sender_write_location

    主节点落盘位置。

    sender_replay_location

    主节点redo位置。

    receiver_received_location

    备节点接收位置。

    receiver_write_location

    备节点落盘位置。

    receiver_flush_location

    备节点flush磁盘位置。

    receiver_replay_location

    备节点redo位置。

  • gs_get_next_xid_csn()

    描述:返回全局所有节点上的next_xid和next_csn值。

    返回值如下:

    表17 gs_get_next_xid_csn返回参数说明

    字段名

    描述

    nodename

    节点名称。

    next_xid

    当前节点下一个事务id号。

    next_csn

    当前节点下一个csn号。

  • pg_control_system()

    描述:返回系统控制文件状态。

    返回类型:SETOF record

  • pg_control_checkpoint()

    描述:返回系统检查点状态。

    返回类型:SETOF record

  • get_prepared_pending_xid

    描述:当恢复完成时,返回nextxid。

    参数:nan

    返回值类型:text

  • pg_clean_region_info

    描述:清理regionmap。

    参数:nan

    返回值类型:character varying

  • pg_get_replication_slot_name

    描述:获取slot name。

    参数:nan

    返回值类型:text

  • pg_get_running_xacts

    描述:获取运行中的xact。

    参数:nan

    返回值类型:handle integer, gxid xid, state tinyint, node text, xmin xid, vacuum boolean, timeline bigint, prepare_xid xid, pid bigint, next_xid xid

  • pg_get_variable_info

    描述:获取共享内存变量cache。

    参数:nan

    返回值类型:node_name text, nextOid oid, nextXid xid, oldestXid xid, xidVacLimit xid, oldestXidDB oid, lastExtendCSNLogpage xid, startExtendCSNLogpage xid, nextCommitSeqNo xid, latestCompletedXid xid, startupMaxXid xid

  • pg_get_xidlimit

    描述:从共享内存获取事物id信息。

    参数:nan

    返回值类型:nextXid xid, oldestXid xid, xidVacLimit xid, xidWarnLimit xid, xidStopLimit xid, xidWrapLimit xid, oldestXidDB oid

  • pg_relation_compression_ratio

    描述:查询表压缩率,默认返回1.0。

    参数:text

    返回值类型:real

  • pg_relation_with_compression

    描述:查询表是否压缩。

    参数:text

    返回值类型:boolean

  • pg_stat_file_recursive

    描述:列出路径下所有文件。

    参数:location text

    返回值类型:path text, filename text, size bigint, isdir boolean

  • pg_stat_get_activity_for_temptable

    描述:返回临时表相关的后台进程的记录。

    参数:nan

    返回值类型:datid oid, timelineid integer, tempid integer, sessionid bigint

  • pg_stat_get_activity_ng

    描述:返回nodegroup相关的后台进程的记录。

    参数:pid bigint

    返回值类型:datid oid, pid bigint, sessionid bigint, node_group text

  • pg_stat_get_cgroup_info

    描述:返回cgroup信息。

    参数:nan

    返回值类型: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

    描述:返回实时信息,当前该接口已不可用,返回FailedToGetSessionInfo。

    参数:oid, oid, bigint, cstring, oid

    返回值类型:text

  • pg_stat_get_session_wlmstat

    描述:返回当前会话负载信息。

    参数:pid integer

    返回值类型:datid oid, threadid bigint, sessionid bigint, threadpid integer, usesysid oid, appname text, query text, priority bigint, block_time bigint, elapsed_time bigint, total_cpu_time bigint, skew_percent integer, statement_mem integer, active_points integer, dop_value integer, current_cgroup text, current_status text, enqueue_state text, attribute text, is_plana boolean, node_group text, srespool name

  • pg_stat_get_wlm_instance_info

    描述:返回当前实例负载信息。

    参数:nan

    返回值类型:instancename text, timestamp timestamp with time zone, used_cpu integer, free_memory integer, used_memory integer, io_await double precision, io_util double precision, disk_read double precision, disk_write double precision, process_read bigint, process_write bigint, logical_read bigint, logical_write bigint, read_counts bigint, write_counts bigint

  • pg_stat_get_wlm_instance_info_with_cleanup

    描述:返回当前实例负载信息,并且保存到系统表中。

    参数:nan

    返回值类型:instancename text, timestamp timestamp with time zone, used_cpu integer, free_memory integer, used_memory integer, io_await double precision, io_util double precision, disk_read double precision, disk_write double precision, process_read bigint, process_write bigint, logical_read bigint, logical_write bigint, read_counts bigint, write_counts bigint

  • pg_stat_get_wlm_node_resource_info

    描述:获取当前节点资源信息。

    参数:nan

    返回值类型:min_mem_util integer, max_mem_util integer, min_cpu_util integer, max_cpu_util integer, min_io_util integer, max_io_util integer, used_mem_rate integer

  • pg_stat_get_wlm_operator_info

    描述:从内部哈希表中获取执行计划算子信息。

    参数:nan

    返回值类型:queryid bigint, pid bigint, plan_node_id integer, plan_node_name text, start_time timestamp with time zone, duration bigint, query_dop integer, estimated_rows bigint, tuple_processed bigint, min_peak_memory integer, max_peak_memory integer, average_peak_memory integer, memory_skew_percent integer, min_spill_size integer, max_spill_size integer, average_spill_size integer, spill_skew_percent integer, min_cpu_time bigint, max_cpu_time bigint, total_cpu_time bigint, cpu_skew_percent integer, warning text

  • pg_stat_get_wlm_realtime_operator_info

    描述:从内部哈希表中获取实时执行计划算子信息。

    参数:nan

    返回值类型:queryid bigint, pid bigint, plan_node_id integer, plan_node_name text, start_time timestamp with time zone, duration bigint, status text, query_dop integer, estimated_rows bigint, tuple_processed bigint, min_peak_memory integer, max_peak_memory integer, average_peak_memory integer, memory_skew_percent integer, min_spill_size integer, max_spill_size integer, average_spill_size integer, spill_skew_percent integer, min_cpu_time bigint, max_cpu_time bigint, total_cpu_time bigint, cpu_skew_percent integer, warning text

  • pg_stat_get_wlm_realtime_session_info

    描述:返回实时会话负载信息。

    参数:nan

    返回值类型:nodename text, threadid bigint, block_time bigint, duration bigint, estimate_total_time bigint, estimate_left_time bigint, schemaname text, query_band text, spill_info text, control_group text, estimate_memory integer, min_peak_memory integer, max_peak_memory integer, average_peak_memory integer, memory_skew_percent integer, min_spill_size integer, max_spill_size integer, average_spill_size integer, spill_skew_percent integer, min_dn_time bigint, max_dn_time bigint, average_dn_time bigint, dntime_skew_percent integer, min_cpu_time bigint, max_cpu_time bigint, total_cpu_time bigint, cpu_skew_percent integer, min_peak_iops integer, max_peak_iops integer, average_peak_iops integer, iops_skew_percent integer, warning text, query text, query_plan text, cpu_top1_node_name text, cpu_top2_node_name text, cpu_top3_node_name text, cpu_top4_node_name text, cpu_top5_node_name text, mem_top1_node_name text, mem_top2_node_name text, mem_top3_node_name text, mem_top4_node_name text, mem_top5_node_name text, cpu_top1_value bigint, cpu_top2_value bigint, cpu_top3_value bigint, cpu_top4_value bigint, cpu_top5_value bigint, mem_top1_value bigint, mem_top2_value bigint, mem_top3_value bigint, mem_top4_value bigint, mem_top5_value bigint, top_mem_dn text, top_cpu_dn text

  • pg_stat_get_wlm_session_info_internal

    描述:返回会话负载信息。

    参数:oid, bigint, bigint, oid

    返回值类型:SETOF text

  • pg_stat_get_wlm_session_iostat_info

    描述:返回会话负载IO信息。

    参数:nan

    返回值类型:threadid bigint, maxcurr_iops integer, mincurr_iops integer, maxpeak_iops integer, minpeak_iops integer, iops_limits integer, io_priority integer, curr_io_limits integer

  • pg_stat_get_wlm_statistics

    描述:返回会话负载统计数据。

    参数:nan

    返回值类型:statement text, block_time bigint, elapsed_time bigint, total_cpu_time bigint, qualification_time bigint, skew_percent integer, control_group text, status text, action text

  • pg_test_err_contain_err

    描述:测试错误类型和返回信息。

    参数:integer

    返回值类型:void

  • pv_session_memory_detail_tp

    描述:返回会话的内存使用情况,参考pv_session_memory_detail。

    参数:nan

    返回值类型:sessid text, sesstype text, contextname text, level smallint, parent text, totalsize bigint, freesize bigint, usedsize bigint

  • gs_get_table_distribution

    描述:返回表数据在各个数据节点的分布情况。

    参数:table_name text, schema_name text

    返回值类型:text

  • pv_builtin_functions

    描述:查看所有内置系统函数信息。

    参数:nan

    返回值类型: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

    描述:返回各线程的内存信息。

    参数:nan

    返回值类型:threadid text, tid bigint, thrdtype text, contextname text, level smallint, parent text, totalsize bigint, freesize bigint, usedsize bigint

  • pg_shared_memory_detail

    描述:返回所有已产生的共享内存上下文的使用信息,各列描述请参考SHARED_MEMORY_DETAIL

    参数:nan

    返回值类型:contextname text, level smallint, parent text, totalsize bigint, freesize bigint, usedsize bigint

  • pgxc_get_running_xacts

    描述:返回集群中各个节点运行事务的信息,字段内容和PGXC_RUNNING_XACTS相同。只有system admin和monitor admin用户有权限查看。

    参数:nan

    返回值类型:setof record

  • pgxc_snapshot_status()

    描述:在GTM模式下,返回GTM中关键内存信息状态,用来支持问题定位,GTM-Free、GTM-Lite不支持本函数。

    参数:nan

    返回值类型: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

    返回值描述如下:

    表18 get_gtm_lite_status返回参数说明

    字段名

    描述

    xmin

    GTM上当前最小的活跃事务id。

    xmax

    GTM上当前提交的最大的事务id + 1,大于等于该值的事务id是活跃的。

    xcnt

    GTM上当前活跃事务个数。

    oldestxmin

    GTM上最老被访问的事务id号。

    next_xid

    GTM上下一个分配的事务id号。

    timeline

    GTM上当前的时间线。

    active_thread_num

    GTM上当前活跃的工作线程数。

    max_active_thread_num

    GTM上1分钟内工作线程数峰值。

    snapshot_num

    GTM上1分钟内下发的快照个数。

    snapshot_totalsize

    GTM上1分钟内下发快照总大小。

  • get_gtm_lite_status()

    描述:返回GTM上的backupXid和csn号,用来支持问题定位,GTM-FREE模式下不支持使用本系统函数。

    返回值如下:
    表19 get_gtm_lite_status返回参数说明

    字段名

    描述

    backup_xid

    GTM上的备份Xid值。

    csn

    GTM当前下发的最新的csn号。

  • adm_hist_snapshot_func()

    描述:返回快照执行时间相关信息,访问该函数需要打开enable_wdr_snapshot参数,并且需要snapshot schema, snapshot表和tables_snap_timestamp表的访问权限。

    参数:nan

    返回值类型: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()

    描述:全局各个节点上的SQL PATCH信息,用于返回global_sql_patch视图的结果。

    返回值如下:

    表20 global_sql_patch_func返回参数说明

    名称

    类型

    描述

    node_name

    text

    SQLpatch所在节点名。

    patch_name

    name

    PATCH名称。

    unique_sql_id

    bigint

    查询全局唯一ID。

    owner

    oid

    PATCH的创建用户ID。

    enable

    boolean

    PATCH是否生效。

    status

    "char"

    PATCH的状态(预留字段)。

    abort

    boolean

    是否是AbortHint。

    hint_string

    text

    Hint文本。

    description

    text

    PATCH的备注。

    parent_unique_sql_id

    bigint

    PATCH生效的SQL语句的外层语句的全局唯一ID,存储过程外的语句该值为0,存储过程内的语句该值为调用该存储过程语句的全局唯一ID。

  • gs_get_current_version()

    描述:依据当前编译宏返回当前编译模式,返回'M'。

    参数:nan

    返回值类型:char

  • gs_get_kernel_info()

    描述:全局各个CN、DN主节点上的事务相关的信息。

    返回值如下。

    表21 gs_get_kernel_info返回参数说明

    名称

    类型

    描述

    node_name

    text

    节点名。

    module

    text

    模块名。包括:

    • XACT(事务模块)。
    • STANDBY(备机模块)。
    • UNDO(undo模块)。
    • HOTPATH(热补丁模块)。

    name

    text

    探查内存态关键数据名字。包括:

    • startup_max_xid(进程启动时最大的xid值)。
    • recent_local_xmin(本地活跃事务最小xid值)。
    • recent_global_xmin(全局活跃事务最小xid值)。
    • standby_xmin(备机活跃事务最小xid值)。
    • standby_redo_cleanup_xmin(备机redo时cleanup日志最小xid值)。
    • standby_redo_cleanup_xmin_lsn(备机redo时cleanup日志最小xid的LSN值)。
    • local_csn_min(本地活跃事务最小CSN值)。
    • replication_slot_xmin(复制槽的最小xid值)。
    • replication_slot_catalog_xmin(catalog复制槽最小xid值)。
    • global_recycle_xid(全局undo回收事务的最小xid值)。
    • global_frozen_xid(全局冻结事务的最小的xid值)。
    • hotpatch_additional_info(热补丁预留字段)。

    value

    text

    探查内存态关键数据值。

    示例:

    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 | HOTPATH | hotpatch_additional_info      | 
     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    | HOTPATH | hotpatch_additional_info      | 
    (24 row)
support.huaweicloud.com/distributed-devg-v3-gaussdb/gaussdb-12-0368.html