更新时间:2025-05-29 GMT+08:00

其它函数

plan_seed()

描述:获取前一次查询语句的seed值(内部使用)。

返回值类型:int

pg_stat_get_env()

描述:获取当前节点的环境变量信息,仅sysadmin和monitor admin可以访问。多租场景下,PDB内部返回为空。

返回值类型:record

示例:

gaussdb=# SELECT pg_stat_get_env();
                                                                              pg_stat_get_env
---------------------------------------------------------------------------------------------------------------------------------------
 (sgnode,"localhost,XXX.XXX.XXX.XXX",28589,26000,/home/omm,/home/omm/data/single_node,gs_log)
(1 row)

pg_catalog.plancache_clean()

描述:清理节点上无人使用的全局计划缓存。多租不支持。

返回值类型:Boolean

pg_catalog.plancache_status()

描述:显示节点上全局计划缓存的信息,函数返回信息和GLOBAL_PLANCACHE_STATUS一致。多租不支持。

返回值类型:record

textlen(text)

描述:提供查询text的逻辑长度的方法。

返回值类型:int

threadpool_status()

描述:显示线程池中工作线程及会话的状态信息。

在多租场景下,Non-PDB可见全局数据;主节点下在PDB内部仅可见PDB自身数据;备节点不做线程组隔离,在PDB内部查询返回空。

返回值类型:record

get_local_active_session()

描述:提供当前节点保存在内存中的历史活跃session状态的采样记录。多租场景下,在PDB内部仅可见PDB自己的数据,Non-PDB可见全局数据。

返回值类型:record

pg_stat_get_thread()

描述:提供当前节点下所有线程的状态信息,sysadmin和monitor admin用户可以查看所有线程信息,普通用户查看本用户的线程信息。多租场景下,non-PDB调用该函数时返回全部信息,PDB调用该函数时仅返回该PDB相关信息。

返回值类型:record

pg_stat_get_sql_count()

描述:提供当前节点中用户执行的SELECT/UPDATE/INSERT/DELETE/MERGE INTO语句的计数结果和DDL/DML/DCL语句的计数结果。DDL语句包括“TRUNCATE”、“VACUUM”、“ANALYZE”、“CREATE”(不包括“CREATE ROLE”和“CREATE USER”)、“DROP”(不包括“DROP ROLE”和“DROP USER”)、“ALTER”(不包括“ALTER ROLE”、“ALTER USER”和“ALTER DEFAULT PRIVILEGES”)、“REINDEX”和“COMMENT”语句。DML语句包括“UPDATE”、“INSERT”、“DELETE”、“MERGE”、“PREPARE”、“EXPLAIN”、“SHOW”、“LOCK”、“COPY”、“CLUSTER”、“ANONYMOUS”、“DELTA”、“EXECUTE”、“MOVE”、“FETCH”、“CLOSE”、“DEALLOCATE”、“DECLARE”和“LOAD”语句。DCL语句包括“CREATE ROLE”、“CREATE USER”、“DROP ROLE”、“DROP USER”、“ALTER ROLE”、“ALTER USER”、“ALTER DEFAULT PRIVILEGES”、“GRANT”、“REVOKE”、“REASSIGN”和“SET”语句。sysadmin和monitor admin用户可以查看所有用户的信息,普通用户查看本用户的统计信息。多租场景下,non-PDB调用该函数时返回全部信息,PDB调用该函数时仅返回该PDB相关信息。

返回值类型:record

pg_stat_get_data_senders()

描述:提供当前活跃的数据复制发送线程的详细信息。多租场景下,PDB内部返回为空。

返回值类型:record

get_wait_event_info()

描述:提供wait event事件的具体信息。

返回值类型:record

generate_wdr_report(begin_snap_id bigint, end_snap_id bigint, report_type cstring, report_scope cstring, node_name cstring)

描述:基于两个snapshot生成系统诊断报告。需要在系统库下执行,默认初始化用户或monadmin用户可以访问。只可在系统库中查询到结果,用户库中无法查询。

返回值类型:record

表1 generate_wdr_report参数说明

参数

说明

取值范围

begin_snap_id

生成某段时间内性能诊断报告的开始snapshotid。

-

end_snap_id

结束snapshot的id,默认end_snap_id大于begin_snap_id。

-

report_type

指定生成report的类型。

  • summary
  • detail
  • all,即同时包含summary和detail。

report_scope

指定生成report的范围。

  • cluster:数据库级别的信息。
  • node:节点级别的信息。

node_name

  • 在report_scope设置为node时,需要将该参数设置为对应节点的名称,节点名称可以通过执行“SELECT * FROM pg_node_env;”查询获取。
  • 在report_scope为cluster时,该参数值可以省略,或设置为空或NULL。
  • cluster:省略/空/NULL。
  • node:GaussDB中的节点名称。

generate_wdr_db_report(db_name cstring, begin_snap_id bigint, end_snap_id bigint, report_type cstring, report_scope cstring, node_name cstring)

描述:基于两个snapshot生成库级系统诊断报告。需要在系统库下执行,默认初始化用户或monadmin用户可以访问。用户只可在系统库中查询到结果,用户库中无法查询。

返回值类型:record

表2 generate_wdr_db_report参数说明

参数

说明

取值范围

db_name

指定database名称。

-

begin_snap_id

生成某段时间内性能诊断报告的开始snapshotid。

-

end_snap_id

结束snapshot的id,默认end_snap_id大于begin_snap_id。

-

report_type

指定生成report的类型。

  • summary
  • detail
  • all,即同时包含summary和detail。

report_scope

指定生成report的范围。

  • cluster:数据库级别的信息。
  • node:节点级别的信息。

node_name

  • 在report_scope指定为node时,需要把该参数指定为对应节点的名称,节点名称可以通过执行“SELECT * FROM pg_node_env;”查询。
  • 在report_scope为cluster时,该值可以省略,或者指定为空或NULL。
  • cluster:省略/空/NULL。
  • node:GaussDB中的节点名称。

create_wdr_snapshot()

描述:手工生成系统诊断快照,该函数需要sysadmin权限。

返回值类型:text

kill_snapshot()

描述:kill后台的WDR snapshot线程,调用该函数的用户需要具有SYSADMIN权限或具有REPLICATION权限或继承了内置角色gs_role_replication的权限。

返回值类型:void

generate_asp_report(start_time timestamp with time zone, end_time timestamp with time zone, slot_count bigint, node_name text)

描述:基于时间戳生成ASP诊断报告,monadmin用户可以访问。slot_count为指标展示时分隔的时间段的个数。node_name用于生成指定节点的ASP报告,取值可以是主备CN的名称,可缺省。缺省时,生成当前节点的报告。该函数只能在主DN上使用。

返回值类型:text

dbe_perf.get_active_session_profile(start_ts timestamp with time zone, end_ts timestamp with time zone, need_final boolean,node_name text)

描述:基于时间戳查询asp内存中与磁盘中的数据。need_final是否查询阻塞信息,默认值为false。node_name用于区分主备DN,如(dn_6001或dn_6002),不可缺省。多租场景下,PDB中查询PDB数据,连接到Non-PDB可查所有数据。

返回值类型:record

capture_view_to_json(text,integer)

描述:将视图的结果存入GUC: perf_directory所指定的目录,如果is_crossdb为1,则表示对于所有的database都会访问一次view;如果is_crossdb为0,则表示仅对当前database进行一次视图访问。该函数只有sysadmin和monitor admin用户可以执行。

返回值类型:int

reset_unique_sql(text,text,bigint)

描述:用来清理数据库节点内存中的Unique SQL(需要sysadmin/monitor admin权限)。多租场景下,在PDB调用仅清理PDB的数据,在Non-PDB调用会清理全局的数据。

返回值类型:Boolean

表3 reset_unique_sql参数说明

参数

类型

描述

scope

text

清理范围类型:

  • 'GLOBAL':清理所有的节点,如果是'GLOBAL',则只可以为主节点执行此函数。
  • 'LOCAL':清理本节点。

clean_type

text

  • 'BY_USERID':按用户ID来进行清理Unique SQL。多租场景下禁用该选项。
  • 'BY_CNID':按主节点的ID来进行清理Unique SQL。
  • 'ALL':全部清理。

clean_value

int8

具体清理type对应的清理值。如果第二个参数为ALL,则第三个参数不起作用,可以取任何值。

wdr_xdb_query(db_name_str text, query text)

描述:提供本地跨数据库执行query的能力。例如:在连接到testdb库时,访问test库下的表,只有初始化用户才有权限执行。多租场景下,non-PDB调用该函数时正常运行,PDB调用该函数时报错。

SELECT col1 FROM wdr_xdb_query('dbname=test','SELECT col1 FROM t1') AS dd(col1 int);

返回值类型:record

pg_wlm_jump_queue(pid int)

描述:调整任务到数据库主节点队列的最前端。

返回值类型:boolean

  • true:成功。
  • false:失败。

gs_wlm_switch_cgroup(pid int, cgroup text)

描述:调整作业的优先级到新控制组。

返回值类型:boolean

  • true:成功。
  • false:失败。

pv_session_memctx_detail(threadid tid, MemoryContextName text)

描述:将线程tid的MemoryContextName内存上下文信息记录到“$GAUSSLOG/gs_log/${node_name}/dumpmem”目录下的“threadid_timestamp.log”文件中。其中threadid可通过视图GS_SESSION_MEMORY_DETAIL中的sessid后获得。在正式发布的版本中仅接受MemoryContextName为空串(两个单引号表示输入为空串,即'')的输入,此时会记录所有的内存上下文信息,否则不会有任何操作。该函数需要管理员权限的用户才能执行。

返回值类型:boolean

  • true:成功。
  • false:失败。

pg_shared_memctx_detail(MemoryContextName text)

描述:将MemoryContextName内存上下文信息记录到“$GAUSSLOG/gs_log/${node_name}/dumpmem”目录下的“threadid_timestamp.log”文件中。该函数功能仅在DEBUG版本中供内部开发人员和测试人员调试使用,在正式发布版本中调用该函数不会有任何操作。该函数需要管理员权限的用户才能执行。

返回值类型:boolean

  • true:成功。
  • false:失败。

local_aio_completer_stat()

描述:显示本实例中AIO Completer线程的相关统计信息。

返回值类型:record

表4 local_aio_completer_stat返回值说明

参数

类型

描述

node_name

text

当前实例名称。

tid

int8

AIO Completer线程id。

thread_type

text

AIO Completer线程类型(读/写)。

aio_submitted_num

int8

AIO Completer线程已提交的异步I/O请求数量。

aio_completed_num

int8

AIO Completer线程已完成的异步I/O请求数量。

aio_incompleted_num

int8

AIO Completer线程未完成的异步I/O请求数量。

slot_count_left

int8

空闲slot数量。

local_aio_slot_usage_status()

描述:显示本实例中异步I/O提交槽位的相关统计信息。

返回值类型:record

表5 local_aio_slot_usage_status返回值说明

参数

类型

描述

nodename

text

当前实例名称。

slot_id

int4

槽位id。

slot_type

char

槽位类型(r:读,w:写)。

status

bool

槽位占用状态。

buffer_id

int8

该槽位对应的buffer id。

relfilenode_blocknum

text

该槽位对应的buffer所在的物理页面位置。

lsn

int8

页面对应的LSN。

submitted_time

int8

页面异步提交时的时间。

elapsed_time

int8

页面已经等待的时间。

gs_get_io_type()

描述:显示本实例的I/O模式。

返回值类型:text

  • BIO:表示当前实例正以BIO模式运行(即ADIO未打开)。
  • DIO:表示当前实例正以DIO模式运行(即ADIO已打开)。
  • BIO->DIO (In progress):表示当前实例正在从BIO到DIO模式的切换过程中。

local_bgwriter_stat()

描述:显示本实例的bgwriter线程刷页信息,候选buffer链中页面个数,buffer淘汰信息。

返回值类型:record

local_candidate_stat()

描述:显示本实例的候选buffer链中页面个数,buffer淘汰信息,包含normal buffer pool和segment buffer pool。

返回值类型:record

local_ckpt_stat()

描述:显示本实例的检查点信息和各类日志刷页情况。多租场景下,non-PDB调用该函数时正常运行,PDB调用该函数时返回空列表。

返回值类型:record

local_double_write_stat()

描述:显示本实例的双写文件的情况。多租场景下,non-PDB调用该函数时返回全部信息,PDB调用该函数时返回空列表。

返回值类型:record

表6 local_double_write_stat参数说明

参数

类型

描述

node_name

text

实例名称。

curr_dwn

int8

当前双写文件的序列号。

curr_start_page

int8

当前双写文件恢复起始页面。

file_trunc_num

int8

当前双写文件复用的次数。

file_reset_num

int8

当前双写文件写满后发生重置的次数。

total_writes

int8

当前双写文件总的I/O次数。

low_threshold_writes

int8

低效率写双写文件的I/O次数(一次I/O刷页数量少于16页面)。

high_threshold_writes

int8

高效率写双写文件的I/O次数(一次I/O刷页数量多于一批,421个页面)。

total_pages

int8

当前刷页到双写文件区的总的页面个数。

low_threshold_pages

int8

低效率刷页的页面个数。

high_threshold_pages

int8

高效率刷页的页面个数。

file_id

int8

当前双写文件的id号。取值范围:[1,5]的int4值。

local_single_flush_dw_stat()

描述:显示本实例的单页面淘汰双写文件的情况。

返回值类型:record

local_pagewriter_stat()

描述:显示本实例的刷页信息和检查点信息。多租场景下,non-PDB调用该函数时正常运行,PDB调用该函数时返回空列表。

返回值类型:record

local_redo_stat()

描述:显示本实例的备机的当前回放状态。多租场景下,non-PDB调用该函数时正常运行,PDB调用该函数时返回空列表。

返回值类型:record

备注:返回的回放状态主要包括当前回放位置,回放最小恢复点位置等信息。

local_recovery_status()

描述:显示本实例的主机和备机的日志流控信息。多租场景下,non-PDB调用该函数时正常运行,PDB调用该函数时返回空列表。

返回值类型:record

gs_wlm_node_recover(boolean isForce)

描述:获取当前内存中记录的TopSQL查询语句级别相关统计信息,当传入的参数不为0时,会将这部分信息从内存中清理掉。

返回值类型:record

gs_cgroup_map_ng_conf(group name)

描述:读取指定逻辑数据库的cgroup配置文件。

返回值类型:record

gs_wlm_switch_cgroup(sess_id int8, cgroup name)

描述:切换指定会话的控制组。

返回值类型:record

comm_client_info()

描述:用于查询单个节点活跃的客户端连接信息。

返回值类型:setof record

pg_get_flush_lsn()

描述:返回当前节点flush的Xlog位置。

返回值类型:text

pg_get_sync_flush_lsn()

描述:返回当前节点多数派flush的Xlog位置。

返回值类型:text

dbe_perf.get_global_full_sql_by_timestamp(start_timestamp timestamp with time zone, end_timestamp timestamp with time zone)

描述:获取数据库级的全量SQL(Full SQL)信息。只可在系统库中查询到结果,用户库中无法查询。

返回值类型:record

表7 dbe_perf.get_global_full_sql_by_timestamp参数说明

参数

类型

描述

start_timestamp

timestamp with time zone

SQL启动时间范围的开始时间点。

end_timestamp

timestamp with time zone

SQL启动时间范围的结束时间点。若start_timestamp>=end_timestamp,则函数执行报错。

dbe_perf.get_global_slow_sql_by_timestamp(start_timestamp timestamp with time zone, end_timestamp timestamp with time zone)

描述:获取数据库级的慢SQL(Slow SQL)信息。只可在系统库中查询到结果,用户库中无法查询。

返回值类型:record

表8 dbe_perf.get_global_slow_sql_by_timestamp参数说明

参数

类型

描述

start_timestamp

timestamp with time zone

SQL启动时间范围的开始时间点。

end_timestamp

timestamp with time zone

SQL启动时间范围的结束时间点。若start_timestamp>=end_timestamp,则函数执行报错。

statement_detail_decode(detail text, format text, pretty boolean)

描述:解析全量/慢SQL语句中的detail字段的信息。只可在系统库中查询到结果,用户库中无法查询。

返回值类型:text

表9 statement_detail_decode参数说明

参数

类型

描述

detail

text

SQL语句产生的事件的集合(不可读)。

format

text

解析输出格式,取值为 plaintext。

pretty

boolean

当format为plaintext时,是否以优雅的格式展示:
  • true表示通过“\n”分隔事件。
  • false表示通过“,”分隔事件。

pgxc_get_csn(tid)

描述:返回给定的事务id对应的事务提交序号(CSN)。

返回值类型:int8

pgxc_get_csn(tid, bucketid)

描述:当前版本集中式不支持hashbucket 表,该接口函数调用报错。

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。多租场景下,non-PDB调用该函数时返回全部信息,PDB调用该函数时仅返回该PDB相关信息。

参数:nan

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

描述:获取共享内存变量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()

描述:列出路径下所有文件。多租场景下,PDB内部禁用该函数。

参数: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_test_err_contain_err()

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

参数:integer

返回值类型:void

get_global_user_transaction()

描述:返回所有节点上各用户的事务相关信息。多租场景下,non-PDB调用该函数时返回全部信息,PDB调用该函数时仅返回该PDB相关信息。

返回值类型:node_name name、usename name、commit_counter bigint、rollback_counter bigint、resp_min bigint、resp_max bigint、resp_avg bigint、resp_total bigint、bg_commit_counter bigint、bg_rollback_counter bigint、bg_resp_min bigint、bg_resp_max bigint、bg_resp_avg bigint、bg_resp_total bigint、dbid oid

pg_collation_for()

描述:返回入参字符串对应的排序规则。

参数:any(如果是常量必须进行显式类型转换)

返回值类型:text

pgxc_unlock_for_sp_database(name Name)

该函数当前版本暂不可用。

pgxc_lock_for_sp_database(name Name)

该函数当前版本暂不可用。

copy_error_log_create()

描述:由于COPY FROM容错机制所需要的错误表已变更为在初始化阶段创建的系统表,因此当前函数改为始终返回true,仅做兼容。

返回值类型:Boolean

表10 错误表pg_catalog.pgxc_copy_error_log信息

列名称

类型

描述

relname

character varying

表名称。以模式名.表名形式显示。

begintime

timestamp with time zone

出现数据格式错误的时间。

filename

character varying

出现数据格式错误的数据源文件名。

lineno

bigint

在数据源文件中,出现数据格式错误的行号。

rawrecord

text

在数据源文件中,出现数据格式错误的原始记录。

detail

text

详细错误信息。

dynamic_func_control(scope text, function_name text, action text, "{params}" text[])

描述:动态开启内置的功能,当前仅支持动态开启全量SQL。

返回值类型:record

表11 dynamic_func_control参数说明

参数

类型

描述

scope

text

动态开启功能的范围,当前仅支持'LOCAL'。

function_name

text

功能的名称,当前仅支持'STMT'。

action

text

当function_name为'STMT'时,action仅支持TRACK/UNTRACK/LIST/CLEAN:
  • TRACK - 开始记录归一化SQL的全量SQL信息。
  • UNTRACK - 取消记录归一化SQL的全量SQL信息。
  • LIST - 列取当前TRACK的归一化SQL的信息。
  • CLEAN - 清理记录当前归一化SQL的信息。

params

text[]

当function_name为'STMT'时,对应不同的action时,对应的params设置如下:
  • TRACK - '{"归一化SQLID", "L0/L1/L2"}'
  • UNTRACK - '{"归一化SQLID"}'
  • LIST - '{}'
  • CLEAN - '{}'

gs_parse_page_bypath(path text, blocknum bigint, relation_type text, read_memory boolean)

描述:用于解析指定表页面,并返回存放解析内容的路径。

返回值类型:text

备注:必须是系统管理员或运维管理员才能执行此函数。

表12 gs_parse_page_bypath参数说明

参数

类型

描述

path

text

  • 对于普通表或段页式表,相对路径为:tablespace name/database oid/表的relfilenode(物理文件名)。例如:base/16603/16394。
  • 对于普通表的visibility map,相对路径为:tablespace name/database oid/表的vm文件。例如:base/16603/16394_vm。
  • 对于普通表的fsm文件,相对路径为:tablespace name/database oid/表的relfilenode(物理文件名)。例如:base/16603/16394。
  • 对于clog文件,相对路径为:pg_clog目录下的clog文件。例如:000000000000。
  • 对于csnlog文件,相对路径为:pg_csnlog目录下的csnlog文件。例如:000000000000。
  • 对于undo record文件,相对路径为:undo目录下的undo/UNDOPERSISTENCE/zondid.segno。例如:undo/permanent/00000.0000009。
  • 对于undo meta文件,相对路径为:undo目录下的undo/UNDOPERSISTENCE/zondid.meta.segno。例如:undo/permanent/00000.meta.0000004。
  • 表文件的相对路径可以通过pg_relation_filepath(table_name text)查找。分区表的路径可以查看pg_partition系统表和调用pg_partition_filepath(partition_oid)。
  • 合法的path格式列举:
    • global/relNode。
    • base/dbNode/relNode。
    • pg_tblspc/spcNode/version_dir/dbNode/relNode。

blocknum

bigint

  • -1:所有block的信息(强制从磁盘解析)。
  • 0~MaxBlockNumber:对应block的信息。
  • 对于BTree/UBTree索引,0为索引元页面。
  • 对于undo record文件,采用逻辑块号,对应文件block大于等于segno*128,小于(segno+1)*128。
  • 对于undo meta文件,采用逻辑块号,对应文件block大于等于segno*4,小于(segno+1)*4。

relation_type

text

  • heap(astore 表)。
  • uheap(ustore 表)。
  • btree(BTree 索引)。
  • ubtree(UBTree 索引)。
  • vm(astore普通表的visibility map)。
  • fsm(行存表的freespace map文件)。
  • clog(事务状态日志commit log)。
  • csnlog(快照时间戳日志commit sequence number log)。
  • undo_slot(事务槽信息)。
  • undo_record(undo 记录信息)。
  • indexurq(indexurq页面)。
  • gsivfflat_index(gsivfflat向量索引)
  • gsdiskann_index(gsdiskann向量索引)

read_memory

boolean

  • false:从磁盘文件解析。
  • true:首先尝试从共享缓冲区中解析该页面;如果共享缓冲区中不存在,则从磁盘文件解析。

正常使用示例:

# 解析BTree索引文件中所有页面的信息内容
# 函数调用前请依据参数说明中的内容确保文件路径真实存在
gaussdb=# SELECT gs_parse_page_bypath('base/16603/16394', -1, 'btree',  false);
                        gs_parse_page_bypath                        
--------------------------------------------------------------------
 gs_log_dir/dump/1663_16603_16394_-1.page
(1 row)

# 解析vm文件中所有block的可见性结果
gaussdb=# SELECT gs_parse_page_bypath('base/12828/16771_vm', -1, 'vm', false);
                         gs_parse_page_bypath                          
-----------------------------------------------------------------------
 gs_log_dir/dump/1663_12828_16771_-1_vm.page
(1 row)

# 解析clog文件中0号block的commit log日志
gaussdb=# SELECT gs_parse_page_bypath('000000000000', 0, 'clog', false); 
                        gs_parse_page_bypath                        
--------------------------------------------------------------------
 gs_log_dir/dump/000000000000.clog
(1 row)

异常场景报错示例:

# 入参blocknum超出取值范围时报错
gaussdb=# SELECT gs_parse_page_bypath('base/12828/16777', -10, 'heap', false);
ERROR:  Blocknum should be between -1 and 4294967294.
CONTEXT:  referenced column: gs_parse_page_bypath

gs_xlogdump_lsn(start_lsn text, end_lsn text)

描述:用于解析指定lsn范围之内的Xlog日志,并返回存放解析内容的路径。可以通过pg_current_xlog_location()获取当前Xlog位置。

返回值类型:text

参数:LSN起始位置,LSN结束位置

备注:必须是系统管理员或运维管理员才能执行此函数。

gs_xlogdump_xid(c_xid xid)

描述:用于解析指定xid的Xlog日志,并返回存放解析内容的路径。可以通过txid_current()获取当前事务ID。

参数:事务ID

返回值类型:text

备注:必须是系统管理员或运维管理员才能执行此函数。

gs_xlogdump_tablepath(path text, blocknum bigint, relation_type text)

描述:用于解析指定表页面对应的日志,并返回存放解析内容的路径。多租场景下,该函数在PDB内部禁用。

返回值类型:text

备注:必须是系统管理员或运维管理员才能执行此函数。

表13 gs_xlogdump_tablepath参数说明

参数

类型

描述

path

text

  • 对于普通表或段页式表,相对路径为:tablespace name/database oid/表的relfilenode(物理文件名)。例如:base/16603/16394。
  • 表文件的相对路径可以通过pg_relation_filepath(table_name text)查找。分区表的路径可以查看pg_partition系统表和调用pg_partition_filepath(partition_oid)。
  • 合法的path格式列举:
    • global/relNode
    • base/dbNode/relNode
    • pg_tblspc/spcNode/version_dir/dbNode/relNode

blocknum

bigint

  • -1:所有block的信息(强制从磁盘解析)。
  • 0~MaxBlockNumber:对应block的信息。

relation_type

text

  • heap(astore 表)
  • uheap(ustore 表)
  • btree(BTree 索引)
  • ubtree(UBTree 索引)
  • segment(段页式)

gs_xlogdump_parsepage_tablepath(path text, blocknum bigint, relation_type text,read_memory boolean)

描述:用于解析指定表页面和表页面对应的日志,并返回存放解析内容的路径。可以看做一次执行gs_parse_page_bypath和gs_xlogdump_tablepath。该函数执行的前置条件是表文件存在。如果想查看已删除的表的相关日志,请直接调用gs_xlogdump_tablepath。多租场景下,该函数在PDB内部禁用。

返回值类型:text

备注:必须是系统管理员或运维管理员才能执行此函数。

表14 gs_xlogdump_parsepage_tablepath参数说明

参数

类型

描述

path

text

  • 对于普通表,相对路径为:tablespace name/database oid/表的relfilenode(物理文件名);例如:base/16603/16394。
  • 表文件的相对路径可以通过pg_relation_filepath(table_name text)查找。分区表的路径可以查看pg_partition系统表和调用pg_partition_filepath(partition_oid)。
  • 合法的path格式列举:
    • global/relNode。
    • base/dbNode/relNode。
    • pg_tblspc/spcNode/version_dir/dbNode/relNode。

blocknum

bigint

  • -1:所有block的信息(强制从磁盘解析)。
  • 0~MaxBlockNumber:对应block的信息。

relation_type

text

  • heap(astore 表)。
  • uheap(ustore 表)。
  • btree(BTree 索引)。
  • ubtree(UBTree 索引)。
  • indexurq(indexurq 页面)。

read_memory

boolean

  • false:从磁盘文件解析。
  • true:首先尝试从共享缓冲区中解析该页面;如果共享缓冲区中不存在,则从磁盘文件解析。

gs_shared_storage_xlogdump_lsn(start_lsn text, end_lsn text, xlog_file_path text)

描述:用于解析指定共享盘的指定lsn范围之内的Xlog日志,并返回存放解析内容的路径。可以通过pg_current_xlog_location()获取当前Xlog位置。

返回值类型:text

备注:必须是系统管理员或运维管理员才能执行此函数。

表15 gs_shared_storage_xlogdump_lsn参数说明

参数

类型

描述

start_lsn

text

需要解析的Xlog的起始lsn。

end_lsn

text

需要解析的Xlog的结束lsn。

xlog_file_path

text

可选参数。需要解析的Xlog所在共享卷的路径。不指定时,解析当前DN所有共享盘的Xlog。

gs_shared_storage_ctlinfo()

描述:用于获取当前DN共享卷元数据相关信息。

返回值类型:record

表16 gs_shared_storage_ctlinfo参数说明

参数类型

参数名

类型

描述

输出参数

xlog_file_path

text

共享卷的路径。

输出参数

system_id

text

当前共享卷上存储的system_id值。

输出参数

term

text

当前共享卷上存储的term值。

输出参数

xlog_file_size

text

共享卷上存Xlog的空间大小。

输出参数

insert_tail

text

共享卷上当前有效的最小lsn。

输出参数

insert_head

text

共享卷上当前有效的最大lsn。

输出参数

shared_storage_flush_lsn

text

共享卷上当前实际落盘lsn。

gs_index_verify(oid oid, uint32 blkno)

描述:用于校验UBtree索引页面或者索引树上key的顺序是否正确。

返回值类型:record

表17 gs_index_verify参数说明

参数

类型

描述

oid

oid

  • 索引文件relfilenode,可以通过select relfilenode from pg_class where relname='name'查询,其中name表示对应的索引文件名字。

blkno

uint32

  • 0:表示检验整个索引树上所有页面。
  • 大于0:表示校验页面编码等于blkno的索引页面。

gs_index_recycle_queue(Oid oid, int type, uint32 blkno)

描述:用于解析UBtree索引回收队列信息。

返回值类型:record

表18 gs_index_recycle_queue参数说明

参数

类型

描述

oid

oid

  • 索引文件relfilenode,可以通过select relfilenode from pg_class where relname='name'查询,其中name表示对应的索引文件名字。

type

int

  • 0:表示解析整个待回收队列。
  • 1:表示解析整个空页队列。
  • 2:表示解析单个页面。

blkno

uint32

  • 回收队列页面编号,该参数只有在type=2的时候有效,blkno有效取值范围为1~4294967294。

gs_stat_wal_entrytable(int64 idx)

描述:用于输出Xlog中预写日志插入状态表的内容。

返回值类型:record

表19 gs_stat_wal_entrytable参数说明

参数类型

参数名

类型

描述

输入参数

idx

int64

  • -1:查询数组所有元素。
  • 0-最大值:具体某个数组元素内容。

输出参数

idx

uint64

记录对应数组中的下标。

输出参数

endlsn

uint64

记录的LSN标签。标识当前entry对应的Xlog是否已经完全复制到wal buffer中:

  • 0:非COPIED。
  • 非0:COPIED。

输出参数

lrc

int32

记录对应的LRC。

输出参数

status

uint32

当前版本已废弃,查询显示为0。

gs_walwriter_flush_position()

描述:输出预写日志的刷新位置。

返回值类型:record

表20 gs_walwriter_flush_position参数说明

参数类型

参数名

类型

描述

输出参数

last_flush_status_entry

int32

Xlog flush上一个刷盘的tblEntry下标索引。

输出参数

last_scanned_lrc

int32

Xlog flush上一次扫描到的最后一个tblEntry记录的LRC。

输出参数

curr_lrc

int32

WALInsertStatusEntry状态表中LRC最新的使用情况,该LRC表示下一个Xlog记录写入时在WALInsertStatusEntry对应的LRC值。

输出参数

curr_byte_pos

uint64

Xlog记录写入WAL文件,最新分配的位置,下一个Xlog记录插入点。

输出参数

prev_byte_size

uint32

上一个Xlog记录的长度。

输出参数

flush_result

uint64

当前全局Xlog刷盘的位置。

输出参数

send_result

uint64

当前主机上Xlog发送位置。

输出参数

shm_rqst_write_pos

uint64

共享内存中记录的XLogCtl中LogwrtRqst请求的write位置。

输出参数

shm_rqst_flush_pos

uint64

共享内存中记录的XLogCtl中LogwrtRqst请求的flush位置。

输出参数

shm_result_write_pos

uint64

共享内存中记录的XLogCtl中LogwrtResult的write位置。

输出参数

shm_result_flush_pos

uint64

共享内存中记录的XLogCtl中LogwrtResult的flush位置。

输出参数

curr_time

text

当前时间。

gs_walwriter_flush_stat(int operation)

描述:用于统计预写日志write与sync的次数频率与数据量,以及Xlog文件的信息。

返回值类型:record

表21 gs_walwriter_flush_stat参数说明

参数类型

参数名

类型

描述

输入参数

operation

int

  • -1:关闭统计开关(默认状态为关闭)。
  • 0:打开统计开关。
  • 1:查询统计信息。
  • 2:重置统计信息。

输出参数

write_times

uint64

Xlog调用write接口的次数。

输出参数

sync_times

uint64

Xlog调用sync接口次数。

输出参数

total_xlog_sync_bytes

uint64

Backend线程请求写入Xlog总量统计值。

输出参数

total_actual_xlog_sync_bytes

uint64

调用sync接口实际刷盘的Xlog总量统计值。

输出参数

avg_write_bytes

uint32

每次调用XLogWrite接口请求写的Xlog量。

输出参数

avg_actual_write_bytes

uint32

实际每次调用write接口写的Xlog量。

输出参数

avg_sync_bytes

uint32

平均每次请求sync的Xlog量。

输出参数

avg_actual_sync_bytes

uint32

实际每次调用sync刷盘Xlog量。

输出参数

total_write_time

uint64

调用write操作总时间统计(单位:us)。

输出参数

total_sync_time

uint64

调用sync操作总时间统计(单位:us)。

输出参数

avg_write_time

uint32

每次调用write接口平均时间(单位:us)。

输出参数

avg_sync_time

uint32

每次调用sync接口平均时间(单位:us)。

输出参数

curr_init_xlog_segno

uint64

当前最新创建的Xlog段文件编号。

输出参数

curr_open_xlog_segno

uint64

当前正在写的Xlog段文件编号。

输出参数

last_reset_time

text

上一次重置统计信息的时间。

输出参数

curr_time

text

当前时间。

gs_catalog_attribute_records()

描述:对于指定的系统表oid,返回该系统表对应的各个字段的定义。仅支持oid小于10000的普通系统表(不支持索引、toast表等)。

参数:系统表oid

返回值类型:record

gs_comm_proxy_thread_status()

描述:用于在数据库实例配置用户态网络的场景下,代理通信库comm_proxy收发数据包统计。

参数:nan

返回值类型:record

此函数的查询仅在集中式环境开始部署用户态网络,且comm_proxy_attr参数中enable_dfx配置为true的条件下显示具体信息。其他场景报错不支持查询。

pg_ls_tmpdir()

描述:返回默认表空间下临时目录(pgsql_tmp)中每个文件的名称、大小和最后修改时间。

参数:nan

返回值类型:record

备注:必须是系统管理员或者监控管理员才能执行此函数。

参数类型

参数名

类型

描述

输出参数

name

text

文件名称。

输出参数

size

int8

文件大小(单位:byte)。

输出参数

modification

timestamptz

文件最后修改时间。

pg_ls_tmpdir(oid)

描述:返回指定表空间下临时目录(pgsql_tmp)中每个文件的名称、大小和最后修改时间。

参数:oid

返回值类型:record

备注:必须是系统管理员或者监控管理员才能执行此函数。

参数类型

参数名

类型

描述

输入参数

oid

oid

表空间id。

输出参数

name

text

文件名称。

输出参数

size

int8

文件大小(单位:byte)。

输出参数

modification

timestamptz

文件最后修改时间。

pg_ls_waldir()

描述:返回预写日志(WAL)目录中每个文件的名称、大小和最后修改时间。

参数:nan

返回值类型:record

备注:必须是系统管理员或者监控管理员才能执行此函数。

参数类型

参数名

类型

描述

输出参数

name

text

文件名称。

输出参数

size

int8

文件大小(单位:byte)。

输出参数

modification

timestamptz

文件最后修改时间。

gs_stat_anti_cache()

描述:返回AntiCache的相关统计信息。

参数:nan

返回值类型:record

参数类型

参数名

类型

描述

输出参数

table_nums

int8

分区数量。

输出参数

table_init_size

int8

分区初始大小。

输出参数

table_max_size

int8

分区大小上限。

输出参数

anti_cache_upper_limit_size

int8

AntiCache大小上限。

输出参数

anti_cache_size

int8

实时AntiCache大小。

输出参数

anti_cache_max_table_size

int8

实时最大分区大小。

输出参数

anti_cache_min_table_size

int8

实时最小分区大小。

gs_stat_vlog_buffer()

描述:返回verifyLog buffer的相关统计信息。

参数:nan

返回值类型:record

参数类型

参数名

类型

描述

输出参数

vbuffer_write_offset

int8

vlog写入位置。

输出参数

vbuffer_flushed_offset

int8

vlog刷盘位置。

输出参数

max_vbuffer_flushed_value

int8

vlog下刷最大字节数。

输出参数

min_vbuffer_flushed_vlaue

int8

vlog下刷最小字节数。

输出参数

ave_vbuffer_flushed_vlaue

int8

vlog下刷平均字节数。

输出参数

vbuffer_flush_latency

int8

vlog下刷时延统计。

gs_stat_vlog_related_io()

描述:返回verifylog文件读写的io相关统计信息。

参数:nan

返回值类型:record

参数类型

参数名

类型

描述

输出参数

read_data_iops

float8

每秒读文件的页面数。

输出参数

vlog_read_iops

float8

每秒读vlog的页面数。

输出参数

vlog_write_iops

float8

每秒写vlog的页面数。

gs_write_term_log(void)

描述:写入一条日志记录DN节点当前的term值。备DN节点返回false,主DN节点写入成功后返回true。

返回值类型:Boolean

gs_stat_space(bool init)

描述:用于查询UStore中做Insert操作时拓展页面的状态。

返回值类型:record

参数类型

参数名

类型

描述

输入参数

init

bool

是否重置已统计的数据。

输出参数

access_func

int8

relation_get_buffer_for_utuple接口访问总次数。

输出参数

cache_blk

int8

relation_get_buffer_for_utuple获取缓存次数。

输出参数

cache_succ

int8

relation_get_buffer_for_utuple获取缓存成功次数。

输出参数

nblk_first

int8

relation_get_buffer_for_utuple中第一次获取nblocks-1次数。

输出参数

nblk_first_succ

int8

relation_get_buffer_for_utuple中第一次获取nblocks-1成功次数。

输出参数

nblk_second

int8

relation_get_buffer_for_utuple中第二次获取nblocks-1次数。

输出参数

nblk_second_succ

int8

relation_get_buffer_for_utuple中第二次获取nblocks-1成功次数。

输出参数

fsm_first

int8

第一次访问FSM次数。

输出参数

fsm_first_success

int8

第一次访问FSM成功次数。

输出参数

fsm_rewrite

int8

FSM回写次数。

输出参数

fsm_second

int8

第二次访问FSM次数。

输出参数

fsm_second_sucess

int8

第二次访问FSM成功次数。

输出参数

prune_count

int8

relation_get_buffer_for_utuple中Prune次数。

输出参数

prune_space

int8

relation_get_buffer_for_utuple中Prune总空间。

输出参数

coprune_count

int8

联合清理执行次数。

输出参数

coprune_scan_blocks

int8

联合清理扫描总页数。

输出参数

coprune_prune_count

int8

联合清理Prune次数。

输出参数

coprune_prune_space

int8

联合清理Prune总空间。

输出参数

con_extend_count

int8

并发扩页数量。

输出参数

con_extend_time

int8

并发扩页总时间。

输出参数

single_extend_time

int8

单一扩页次数。

示例:

gaussdb=# SELECT * FROM gs_stat_space(false);
 access_func | cache_blk | cache_succ | nblk_first | nblk_first_succ | nblk_sencond | nblk_sencond_succ | fsm_first | fsm_first_success | fsm_rewrite | fsm_
second | fsm_second_success | prune_count | prune_space | coprune_count | coprune_scan_blocks | coprune_prune_count | coprune_prune_space | con_extend_count
 | con_extend_time | single_extend_count
-------------+-----------+------------+------------+-----------------+--------------+-------------------+-----------+-------------------+-------------+-----
-------+--------------------+-------------+-------------+---------------+---------------------+---------------------+---------------------+-----------------
-+-----------------+---------------------
    10082397 |  10082397 |   10082235 |         88 |              78 |        47021 |             47021 |       162 |                74 |      360996 |
360996 |             270948 |        6711 |           0 |         45497 |              222619 |                   0 |                   0 |             3675
 |        25542884 |               26791
(1 row)

备注:请重点关注cache_succ此值较小说明系统缓存失效,prune_space 此值较小表示UStore数据页页面清理机制可能存在问题,con_extend_time此值过高可能表明UStore并发拓页时耗时较高。

gs_index_dump_read(int8 reset, text out_type)

描述:用于查询索引获取新页面时在循环队列中产生的buffer read信息和索引页面相同key从左到右遍历叶子页面的buffer read信息。多租场景下,PDB内禁用。

返回值类型:record

参数类型

参数名

类型

描述

输入参数

reset

int8

  • 0:将统计信息reset为初始值0,重新开始统计。
  • 1:直接show出当前的统计信息。

输入参数

out_type

text

  • urq:输出循环队列的统计信息。
  • ubtree:输出索引页的统计信息。
  • all:循环队列和索引页的统计信息全部输出。

输出参数

relfilenode

oid

统计到的最大buffer read值对应的索引relfilenode。

输出参数

max_count

int8

最大buffer read值。

输出参数

ave_count

int8

平均buffer read值。

  • 该接口当前仅支持USTORE索引表。
  • 该接口执行时,先reset清理、将记录全部置为0。再进行查询,直到下次统计到信息值之前,查询记录会一直为0。查询示例如下:
    gaussdb=# SELECT * FROM gs_index_dump_read(0, 'all');
    relfilenode | max_count | ave_count
    --------------+-------------+-------------
    |                     |
    (1 row)
    gaussdb=# SELECT * FROM gs_index_dump_read(1, 'all');
    relfilenode | max_count | ave_count
    --------------+-------------+-------------
    0 |                  0 |                  0
    0 |                  0 |                  0
    (2 rows)

gs_redo_upage(directory_path text, backup_path text, blocknum bigint, relation_type text, xlog_path text, lsn text)

描述:用于将备份的特定UStore数据页面重放到指定LSN,并在重放期间校验页面,若检测到页面受损则直接落盘该坏块,返回落盘路径、页面LSN以及受损信息,否则重放至指定LSN并落盘页面后返回,必须是系统管理员或运维管理员才能执行此函数。多租场景下,该函数在PDB内部禁用。

返回值类型:record

参数类型

参数

类型

描述

输入参数

directory_path

text

备份文件所在目录。

输入参数

backup_path

text

备份表文件的相对路径,与备份文件所在目录拼成表文件的完整路径,例如,base/15635/12488,若备份文件不存在,传入null。

输入参数

blocknum

bigint

0~MaxBlockNumber:对应页面的块号。

输入参数

relation_type

text

  • uheap(Ustore数据页)。
  • ubtree(Ustore索引页)。
  • indexurq(Urq页面)。
  • undo_record(Undo record页面)。
  • undo_slot(Transaction slot页面)。

输入参数

xlog_path

text

归档日志目录的绝对路径。

输入参数

lsn

text

lsn由两个16进制数(各32 bits)组成,中间通过"/"隔开,例如:2/962D1DF8。如果是0则重放到最新版本。

输出参数

output_filename

text

文件的落盘路径与文件名。

输出参数

output_lsn

text

最后一次页面重放的LSN。

输出参数

corruption_desc

text

页面受损情况描述。

gs_xlogdump_bylastlsn(last_lsn text, blocknum bigint, relation_type text)

描述:传入一个页面LSN以及块号,解析LSN对应的WAL日志,并获取对应块号的last LSN继续解析,直到last LSN为0或者更老版本的WAL日志已被复用回收,并将解析后的日志落盘到指定路径,必须是系统管理员或运维管理员才能执行此函数。本系统函数不支持备机调用。

返回值类型:text

参数类型

参数名

类型

描述

输入参数

last_lsn

text

解析指定页面的LSN,基于十六进制表示,如12BA/32CDEDDD,LSN可通过页面解析工具(gs_parse_page_bypath等)获取。

输入参数

blocknum

bigint

指定页面的逻辑块号。

参数范围:-1~MaxBlockNumber。

块号指定为-1时表示从WAL日志中获取默认块号。

输入参数

relation_type

text

指定解析页面的类型。

参数范围:uheap、ubtree、heap、btree、undo_record、undo_slot。

输出参数

output_filepath

text

WAL日志解析结果的落盘路径。

示例:
# 获取页面LSN信息
# 函数调用前请依据参数说明中的内容确保文件路径真实存在
gaussdb=# SELECT * FROM gs_parse_page_bypath('base/15833/16768', 0, 'uheap', false);
                        output_filepath
---------------------------------------------------------------
 data1/database/cluster/primary/data/1663_15833_16768_0.page
(1 row)
gaussdb=# SELECT * FROM gs_xlogdump_bylastlsn('0/4593570', -1, 'uheap');
                        output_filepath
-------------------------------------------------------------------
 /data1/database/cluster/primary/data/gs_log/dump/4593570_-1.xlog
(1 row)
gaussdb=# SELECT * FROM gs_xlogdump_bylastlsn('0/4593570', 0, 'ubtree');
ERROR:  The input lsn 0/4593570 related xlog is not ubtree.

gs_shared_storage_flush_stat(int operation)

描述:统计共享盘的写入数据量、写入速度、写入时间、读取数据量、读取速度、读取时间等。多租场景下,non-PDB调用该函数时正常运行,PDB调用该函数时报错。

返回值类型:record

参数类型

参数名

类型

描述

输入参数

operation

int

  • -1:关闭统计开关。
  • 0:打开统计开关(默认状态为打开)。
  • 1:查询统计信息。
  • 2:重置统计信息。

关闭统计开关后重新打开时会清理之前的统计信息。

输出参数

stat_switch

bool

统计开关是否打开。

输出参数

write_times

uint64

shared_storage_xlog_copy线程调用dorado_write_xlog接口的次数。

输出参数

avg_write_bytes

uint32

每次调用dorado_write_xlog接口请求写的Xlog量(单位:B)。

输出参数

avg_actual_write_bytes

uint32

实际每次调用dorado_write_xlog接口写的Xlog量(单位:B)。

输出参数

total_write_time

uint64

调用dorado_write_xlog操作总时间统计(单位:us)。

输出参数

avg_write_time

uint32

每次调用dorado_write_xlog接口平均时间(单位:us)。

输出参数

avg_write_speed

uint32

平均调用dorado_write_xlog接口请求写Xlog的速度(单位:KB/s)。

输出参数

avg_actual_write_speed

uint32

实际平均调用dorado_write_xlog接口请求写Xlog的速度(单位:KB/s)。

输出参数

total_write_sleep_time

uint64

shared_storage_xlog_copy线程总睡眠时间。

输出参数

read_times

uint64

walreceiver线程调用dorado_read_xlog接口的次数。

输出参数

avg_read_bytes

uint32

每次调用dorado_read_xlog接口请求写的Xlog量(单位:B)。

输出参数

avg_actual_read_bytes

uint32

实际每次调用dorado_read_xlog接口写的Xlog量(单位:B)。

输出参数

total_read_time

uint64

调用dorado_read_xlog操作总时间统计(单位:us)。

输出参数

avg_read_time

uint32

每次调用dorado_read_xlog接口平均时间(单位:us)。

输出参数

avg_read_speed

uint32

平均调用dorado_read_xlog接口请求写Xlog的速度(单位:KB/s)。

输出参数

avg_actual_read_speed

uint32

实际平均调用dorado_read_xlog接口请求写Xlog的速度(单位:KB/s)。

输出参数

total_read_sleep_time

uint64

walreceiver线程总睡眠时间。

输出参数

stat_start_time

timestamptz

本次统计数据开始时间,若无重置统计信息操作则为GaussDB程序开始运行时间,若有重置统计信息操作则为上次重置时间。

输出参数

stat_end_time

timestamptz

本次统计数据结束时间,若统计开关开启则为当前时间,若统计开关关闭则为上次关闭时间。

示例:

gaussdb=# SELECT * FROM gs_shared_storage_flush_stat(1);
 stat_switch | write_times | avg_write_bytes | avg_actual_write_bytes | total_write_time | avg_write_time | avg_write_speed | avg_actual_write_speed | total_write_sleep_time | read_times | avg
_read_bytes | avg_actual_read_bytes | total_read_time | avg_read_time | avg_read_speed | avg_actual_read_speed | total_read_sleep_time |        stat_start_time        |         stat_end_time

-------------+-------------+-----------------+------------------------+------------------+----------------+-----------------+------------------------+------------------------+------------+----
------------+-----------------------+-----------------+---------------+----------------+-----------------------+-----------------------+-------------------------------+------------------------
-------
 t           |       43644 | 8624            | 8624                   |        263922553 | 6047           | 1392            | 1392                   |            26918503404 |       7451 | 140
13          | 14013                 |         5321082 | 714           | 19163          | 19163                 |                     0 | 2023-12-18 07:18:39.766855+08 | 2023-12-18 16:29:22.757
535+08
(1 row)

dbe_perf.get_full_sql_by_parent_id_and_timestamp(parent_id bigint, start_timestamp timestamp with time zone, end_timestamp timestamp with time zone)

描述:根据parent_id获取某个时间段内,执行某个存储过程的数据库级的全量SQL及其子语句的记录。只可在系统库中查询到结果,用户库中无法查询。

返回值类型:record

参数

类型

描述

parent_id

bigint

指定需要检索的存储过程的调用语句的unique_sql_id。

start_timestamp

timestamp with time zone

SQL启动时间范围的开始时间点。

end_timestamp

timestamp with time zone

SQL启动时间范围的结束时间点。

示例:

gaussdb=# CREATE TABLE test(a int,b int);
CREATE TABLE
gaussdb=# INSERT INTO test values(1,1);
INSERT 0 1
gaussdb=# CREATE PROCEDURE mypro1() as num int;
gaussdb$# begin
gaussdb$# INSERT INTO test values(2,2);
gaussdb$# DELETE FROM test where a = 2;
gaussdb$# end;
gaussdb$# /
CREATE PROCEDURE

--打开参数,跟踪存储过程子语句。
gaussdb=# SET instr_unique_sql_track_type = 'all';
SET

--打开参数,dbe_perf.statement_history表生成全量语句记录。
gaussdb=# SET track_stmt_stat_level = 'L0,L0';
SET

gaussdb=# CALL mypro1();
 mypro1
--------

(1 row)

gaussdb=# SET track_stmt_stat_level = 'off,L0';
SET

gaussdb=# SET instr_unique_sql_track_type = 'top';
SET

--查询关键信息,作为函数参数使用。
gaussdb=# SELECT query,unique_query_id,start_time,finish_time FROM dbe_perf.statement_history;
                query                 | unique_query_id |          start_time           |          finish_time
--------------------------------------+-----------------+-------------------------------+-------------------------------
 set track_stmt_stat_level = 'L0,L0'; |       636388010 | 2023-06-02 17:40:49.176155+08 | 2023-06-02 17:40:49.176543+08
 call mypro1();                       |       536458473 | 2023-06-02 17:40:59.028144+08 | 2023-06-02 17:40:59.032027+08
 delete from test where a = ?         |       583323884 | 2023-06-02 17:40:59.029955+08 | 2023-06-02 17:40:59.031577+08
 insert into test values(?,?)         |       769279931 | 2023-06-02 17:40:59.029219+08 | 2023-06-02 17:40:59.029947+08
(4 rows)

--通过外层语句的unique_query_id、外层语句的开始和结束时间作为参数,查询该时间段内,指定存储过程及其子语句的信息。
gaussdb=# SELECT query FROM dbe_perf.get_full_sql_by_parent_id_and_timestamp(536458473,'2023-06-02 17:40:59.028144+08','2023-06-02 17:40:59.032027+08');
            query
------------------------------
 call mypro1();
 delete from test where a = ?
 insert into test values(?,?)
(3 rows)

gaussdb=# DROP PROCEDURE mypro1();
DROP PROCEDURE
gaussdb=# DROP TABLE test;
DROP TABLE

gin_clean_pending_list(index regclass)

描述:清理指定UGIN索引的“pending list”,将里面的条目批量移动到主索引页面中,返回清理的页面数量。如果索引未开启fastupdate选项,则不会发生清理,结果为0。

返回值类型:bigint

gs_stat_freespace(Oid relid, Oid partid, char type, int sample_ratio)

描述:通过统计信息或采样的方法估算表/分区表/索引的膨胀率,输出空间使用统计信息及膨胀率信息。

返回值类型:record

参数类型

参数

类型

描述

输入参数

relation_oid

OID

要查询的数据表/分区表主表/索引的OID。

输入参数

partation_oid

OID

分区表/二级分区表/LOCAL分区索引的OID。

  • 如果relation_oid为非分区表/非LOCAL分区索引/GPI,本入参无意义;
  • 如果relation_oid为分区表/二级分区表/LOCAL分区索引,partition_oid取值为0,代表输出所有分区的信息。

输入参数

relation_type

CHAR

表类型:

  • 'r':表示查询目标表为行存数据表
  • 'i':表示查询目标表为行存索引表

输入参数

sample_ratio

INT8

采样比例,取值范围为 0-100。

  • 当sample_ratio取值为0时,INFO为通过统计信息估算出的膨胀率;
  • 当sample_ratio取值为1-100时,INFO为通过采样估算出的膨胀率。

输入参数

read_memory

BOOL

是否从内存读取页面:

  • true:表示为从内存读取页面;
  • false:表示为从磁盘读取页面。暂时只支持取值为 false。

输出参数

OID

OID

要查询的数据表/分区表/二级分区表/索引的OID。

输出参数

INFO

TEXT

  • 当sample_ratio = 0 时,INFO为估算页面膨胀率;
  • 当sample_ratio > 0 时,INFO为页面使用率采样统计信息,包括页头长度、元组平均长度、平均normal元组数量、平均dead元组数量、平均unused元组数量、平均redirected元组数量、页面平均td数(Ustore数据表)、页面平均potential_freespace、实际freespace(页面upper - lower)、relation总页面数、通过采样信息估算数据表/索引占空间大小、通过采样信息估算数据表/索引膨胀率。

该接口当前仅支持行存表,不支持列存表、时序表、段页式表、hashbucket 表、本地临时表和全局临时表。

示例:

-- 查询普通表信息
建表语句:
drop table if exists t;
create table t(a int) with (storage_type=ustore);
insert into t values(generate_series(1, 110000));

更新统计信息:
vacuum analyze t;

估算膨胀率:
gaussdb=# select * from gs_stat_freespace((select oid from pg_class where relname='t'), 0, 'r', 0, false);
  oid  |                                                                                                       info

-------+-----------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------
 16735 | live_tuples: 110000, dead_tuples: 0, avg_tuple_len: 4, tuple_header_size: 11, rowptr_size: 440000, page_header_size: 56,  nblocks: 419, approx
imate_table_size: 2113464 (Bytes), approximate expansion rate: 1.62
(1 row)

采样信息:
gaussdb=# select * from gs_stat_freespace((select oid from pg_class where relname='t'), 0, 'r', 80, false);
  oid  |
                      info

-------+-----------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------
 16732 | Average page stat info: page_header_size: 28, tuple has storage: 222.22, normal tuple: 222.22, dead tuple: 0.00, unused tuple: 0.00, redirecte
d tuple: 0.00, td_count: 0.00, potential_freespace: 0.00, actual_freespace: 152.00. Freespace stat info: nblocks: 45, approximate_table_size: 342495 (B
ytes), approximate expansion rate: 1.08.
(1 row)

-- 查询分区表单个分区信息
建表语句:
drop table if exists t;
create table t(a int) with (storage_type=ustore) partition by range(a) (partition p1 values less than(3000), partition p2 values less than(maxvalue));
insert into t values(generate_series(1, 10000));

更新统计信息:
vacuum analyze t;

查询 oid:
select oid from pg_class where relname='t';
gaussdb=# select oid from pg_class where relname='t';
  oid
-------
 16802
(1 row)

select oid, relname, parttype from pg_partition;
gaussdb=# select oid, relname, parttype from pg_partition;
  oid  | relname | parttype
-------+---------+----------
 16805 | t       | r
 16806 | p1      | p
 16807 | p2      | p
(3 rows)

估算膨胀率:
gaussdb=# select * from gs_stat_freespace(16802, 16806, 'r', 0, false);
  oid  |                                                                                                     info

-------+-----------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------
 16806 | live_tuples: 5998, dead_tuples: 0, avg_tuple_len: 4, tuple_header_size: 11, rowptr_size: 23992, page_header_size: 56,  nblocks: 12, approximat
e_table_size: 114634 (Bytes), approximate expansion rate: 0.86
(1 row)

采样信息:
gaussdb=# select * from gs_stat_freespace(16802, 16807, 'r', 0, false);
  oid  |                                                                                                     info

-------+-----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------
 16807 | live_tuples: 14002, dead_tuples: 0, avg_tuple_len: 4, tuple_header_size: 11, rowptr_size: 56008, page_header_size: 56,  nblocks: 27, approxima
te_table_size: 267550 (Bytes), approximate expansion rate: 0.83
(1 row)

-- 查询分区表所有分区信息
建表语句:
drop table if exists t;
create table t(a int) with (storage_type=ustore) partition by range(a) (partition p1 values less than(3000), partition p2 values less than(maxvalue));
insert into t values(generate_series(1, 10000));

更新统计信息:
vacuum analyze t;

查询 oid:
select oid from pg_class where relname='t';
gaussdb=# select oid from pg_class where relname='t';
  oid
-------
 16802
(1 row)

select oid, relname, parttype from pg_partition;
gaussdb=# select oid, relname, parttype from pg_partition;
  oid  | relname | parttype
-------+---------+----------
 16805 | t       | r
 16806 | p1      | p
 16807 | p2      | p
(3 rows)

估算膨胀率:
gaussdb=# select * from gs_stat_freespace(16802, 0, 'r', 0, false);
  oid  |                                                                                                     info

-------+-----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------
 16806 | live_tuples: 5998, dead_tuples: 0, avg_tuple_len: 4, tuple_header_size: 11, rowptr_size: 23992, page_header_size: 56,  nblocks: 12, approximat
e_table_size: 114634 (Bytes), approximate expansion rate: 0.86
 16807 | live_tuples: 14002, dead_tuples: 0, avg_tuple_len: 4, tuple_header_size: 11, rowptr_size: 56008, page_header_size: 56,  nblocks: 27, approxima
te_table_size: 267550 (Bytes), approximate expansion rate: 0.83
(2 rows)

采样信息:
gaussdb=# select * from gs_stat_freespace(16802, 0, 'r', 60, false);
  oid  |
                        info

-------+-----------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------
 16806 | Average page stat info: page_header_size: 56, tuple has storage: 249.92, normal tuple: 249.92, dead tuple: 0.00, unused tuple: 0.00, redirecte
d tuple: 0.00, td_count: 4.00, potential_freespace: 1034.33, actual_freespace: 1034.33. Freespace stat info: nblocks: 12, approximate_table_size: 84636
 (Bytes), approximate expansion rate: 1.16.
 16807 | Average page stat info: page_header_size: 56, tuple has storage: 259.30, normal tuple: 259.30, dead tuple: 0.00, unused tuple: 0.00, redirecte
d tuple: 0.00, td_count: 4.00, potential_freespace: 771.70, actual_freespace: 771.70. Freespace stat info: nblocks: 27, approximate_table_size: 197532
(Bytes), approximate expansion rate: 1.12.
(2 rows)

-- 查询普通索引信息
建表语句:
drop table if exists t;
create table t(a int, b int, c varchar(1000)) with (storage_type=ustore);
create index on t(a);
insert into t values(generate_series(1, 100000), generate_series(1, 100000), 'kjgkjature');

更新统计信息:
vacuum analyze t;

估算膨胀率:
gaussdb=# select * from gs_stat_freespace((select oid from pg_class where relname='t_a_idx'), 0, 'i', 0, false);
  oid  |                                                                                                                        info

-------+-----------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------
 16776 | live_tuples: 100000, dead_tuples: 0, origin_avg_tuple_len 4, max_align_avg_tuple_len: 8, tuple_header_size: 16, rowptr_size: 401548, page_head
er_size: 24, nblocks: 387, approximate_table_size: 2838700 (Bytes), approximate expansion rate: 1.12
(1 row)

采样信息:
gaussdb=# select * from gs_stat_freespace((select oid from pg_class where relname='t_a_idx'), 0, 'i', 60, false);
  oid  |
                       info

-------+-----------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------
 16776 | Average page stat info: page_header_size: 24, tuple has storage: 260.39, normal tuple: 260.39, dead tuple: 0.00, unused tuple: 0.02, redirecte
d tuple: 0.00, td_count: 0.00, potential_freespace: 0.00, actual_freespace: 845.05. Freespace stat info: nblocks: 387, approximate_table_size: 3044529
(Bytes), approximate expansion rate: 1.04.
(1 row)

-- 查询 local 分区索引单个分区信息
建表语句:
drop table if exists t;
create table t(a int) with (storage_type=ustore) partition by range(a) (partition p1 values less than(3000), partition p2 values less than(maxvalue));;
create index on t(a) local;
insert into t values(generate_series(1, 10000));

更新统计信息:
vacuum analyze t;

查询 oid:
gaussdb=# select oid from pg_class where relname='t_a_idx';
  oid
-------
 16814
(1 row)

gaussdb=# select oid, relname, parttype from pg_partition;
  oid  | relname  | parttype
-------+----------+----------
 16811 | t        | r
 16812 | p1       | p
 16813 | p2       | p
 16815 | p1_a_idx | x
 16816 | p2_a_idx | x
(5 rows)

估算膨胀率:
gaussdb=# select * from gs_stat_freespace(16814, 16815, 'i', 0, false);
  oid  |                                                                                                                      info

-------+-----------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
 16815 | live_tuples: 10000, dead_tuples: 0, origin_avg_tuple_len 4, max_align_avg_tuple_len: 8, tuple_header_size: 16, rowptr_size: 40056, page_header
_size: 24, nblocks: 14, approximate_table_size: 281400 (Bytes), approximate expansion rate: 0.41
(1 row)

采样信息:
gaussdb=# select * from gs_stat_freespace(16814, 16815, 'i', 80, false);
  oid  |
                      info

-------+-----------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------
 16815 | Average page stat info: page_header_size: 24, tuple has storage: 215.93, normal tuple: 215.93, dead tuple: 0.00, unused tuple: 0.50, redirecte
d tuple: 0.00, td_count: 0.00, potential_freespace: 0.00, actual_freespace: 2087.43. Freespace stat info: nblocks: 14, approximate_table_size: 91476 (B
ytes), approximate expansion rate: 1.25.
(1 row)

-- 查询 local 分区索引所有分区信息
建表语句:
drop table if exists t;
create table t(a int) with (storage_type=ustore) partition by range(a) (partition p1 values less than(3000), partition p2 values less than(maxvalue));;
create index on t(a) local;
insert into t values(generate_series(1, 10000));

更新统计信息:
vacuum analyze t;

查询 oid:
gaussdb=# select oid from pg_class where relname='t_a_idx';
  oid
-------
 16814
(1 row)

估算膨胀率:
gaussdb=# select * from gs_stat_freespace(16814, 0,  'i', 0, false);
  oid  |                                                                                                                      info

-------+-----------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
 16815 | live_tuples: 10000, dead_tuples: 0, origin_avg_tuple_len 4, max_align_avg_tuple_len: 8, tuple_header_size: 16, rowptr_size: 40056, page_header
_size: 24, nblocks: 14, approximate_table_size: 281400 (Bytes), approximate expansion rate: 0.41
 16816 | live_tuples: 10000, dead_tuples: 0, origin_avg_tuple_len 4, max_align_avg_tuple_len: 8, tuple_header_size: 16, rowptr_size: 40116, page_header
_size: 24, nblocks: 29, approximate_table_size: 282900 (Bytes), approximate expansion rate: 0.84
(2 rows)

采样信息:
gaussdb=# select * from gs_stat_freespace(16814, 0,  'i', 80, false);
  oid  |
                       info

-------+-----------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------
 16815 | Average page stat info: page_header_size: 24, tuple has storage: 215.93, normal tuple: 215.93, dead tuple: 0.00, unused tuple: 0.50, redirecte
d tuple: 0.00, td_count: 0.00, potential_freespace: 0.00, actual_freespace: 2087.43. Freespace stat info: nblocks: 14, approximate_table_size: 91476 (B
ytes), approximate expansion rate: 1.25.
 16816 | Average page stat info: page_header_size: 24, tuple has storage: 243.28, normal tuple: 243.28, dead tuple: 0.00, unused tuple: 0.24, redirecte
d tuple: 0.00, td_count: 0.00, potential_freespace: 0.00, actual_freespace: 1323.03. Freespace stat info: nblocks: 29, approximate_table_size: 213237 (
Bytes), approximate expansion rate: 1.11.
(2 rows)

异常输入:
gaussdb=# select * from gs_stat_freespace(16814, 0, 'k', 0, false);
ERROR:  wrong relation_type input, type should be either 'r' or 'i'

gaussdb=# select * from gs_stat_freespace(16814, 0, 'i', 600, false);
ERROR:  wrong sample_ratio input, sample_ratio should be an integer between 0 and 100

gaussdb=# select * from gs_stat_freespace(16814, 0, 'r', 60, false);
ERROR:  "t_a_idx" is not a ordinary relation or toast relation.