<!DOCTYPE html>
OushuDB 2.4.6 toolkit 对象图谱
基于 Greenplum 7 内核(PG 12.12)的国产化数仓 —— 全部数字来自生产实例系统目录枚举,不是文档抄录
112oushu_toolkit 函数
4oushu_toolkit 视图
83pg_catalog.gp_* 视图
79pg_catalog.gp_* 函数
0gp_toolkit schema
19GB遗留临时文件(实测)
01环境事实与采集方法
先确认“到底有什么”,再谈怎么用。GP7 那套 gp_toolkit 在 Oushu 里被拆成了两层。
| 项目 | 实测值 |
|---|---|
| 版本 | PostgreSQL 12.12 (OushuDB 2.4.6 Enterprise Edition),内核标 Greenplum Database 7.0.0-beta.0+27b8a78 |
| 拓扑 | 3 个段(node1/node2/node3 :40000,均 primary、无 mirror);两个 7432 主控条目(node1、node2) |
| 用户 schema | oushu_toolkit、recycle、public |
| 关键结论 | 不存在 gp_toolkit schema。功能被拆为 oushu_toolkit(4 视图 + 112 函数)与 pg_catalog 下的 83 个 gp_* 视图、79 个 gp_* 函数 |
枚举语句(可复现,换成自己的库也能跑):
-- 所有 toolkit 相关对象 select n.nspname, c.relkind, c.relname from pg_class c join pg_namespace n on n.oid = c.relnamespace where n.nspname in ('oushu_toolkit','gp_toolkit') order by 1,2,3; -- 函数清单(含签名与返回类型) select p.proname, pg_get_function_identity_arguments(p.oid), pg_get_function_result(p.oid) from pg_proc p join pg_namespace n on n.oid = p.pronamespace where n.nspname = 'oushu_toolkit' order by 1;
本环境
pg_proc 里没有对象注释(obj_description 全空),所以下表的“用途”是按函数名语义 + 返回值结构 + 实跑结果判定的,参数含义则以产品文档为准。凡标注“实测”的输出都是在 node1 上真实跑出来的。02oushu_toolkit 的四个视图
只有四个,但都是 GP 侧没有的“切片(slice/vsegno)视角”监控底座 —— 这是列存 + Magma 架构的特点。
| 视图 | 字段 | 用途 |
|---|---|---|
session_status_summary |
sess_id, state, count, total_cpu_usage | 会话按状态聚合,看并发与 CPU 总量 |
session_status_detail |
host, pid, sess_id, command, slice, vsegno, database_id, state, wait_event, wait_event_type, cpu_usage | 会话级明细,等价于“切片视角的 pg_stat_activity”,定位等待与 CPU 热点 |
segment_status_summary |
host, state, count, total_cpu_usage | 按段聚合执行体状态与 CPU,看是否存在单段打满 |
segment_memory_summary |
host, total_allocated, total | 按段汇总内存占用 |
-- 谁在吃 CPU(协调侧聚合) select * from oushu_toolkit.session_status_summary order by total_cpu_usage desc; -- 哪个段被打满 select * from oushu_toolkit.segment_status_summary order by total_cpu_usage desc; -- 内存大户排行 select * from oushu_toolkit.segment_memory_summary order by total_allocated desc limit 10;
实测:segment_status_summary 3 行(=3 个段)、segment_memory_summary 12 行(段 × 执行体)、session_status_summary 2 行(当前两个会话)
03oushu_toolkit 函数全表(112 个)
按用途分 9 组。同名重载已合并展示,签名列即 参数 → 返回;带表格的页面支持搜索过滤。
会话 / 段 / 内存监控 10
| 函数 | 签名 → 返回 | 用途 |
|---|---|---|
session_status_detail |
integer → TABLE(host text, pid integer, sess_id integer, command integer, slice integer, vsegno integer, database_id oid, state text, wait_event text, wait_event_type text, cpu_usage real) | 会话级明细:host、pid、slice、vsegno、state、wait_event(_type)、cpu_usage,替代 gp_toolkit.gp_stat_activity 的切片视角(重载:integer) |
session_status_detail |
integer, integer → TABLE(host text, pid integer, sess_id integer, command integer, slice integer, vsegno integer, database_id oid, state text, wait_event text, wait_event_type text, cpu_usage real) | 会话级明细:host、pid、slice、vsegno、state、wait_event(_type)、cpu_usage,替代 gp_toolkit.gp_stat_activity 的切片视角(重载:integer, integer) |
segment_status_detail |
() → TABLE(host text, pid integer, sess_id integer, command integer, slice integer, vsegno integer, database_id oid, state text, wait_event text, wait_event_type text, cpu_usage real) | 段执行体(QE)明细,含 slice/vsegno/等待事件/CPU,定位“哪一段在跑、卡在什么等待” |
segment_status_detail |
text → TABLE(host text, pid integer, sess_id integer, command integer, slice integer, vsegno integer, database_id oid, state text, wait_event text, wait_event_type text, cpu_usage real) | 段执行体(QE)明细,含 slice/vsegno/等待事件/CPU,定位“哪一段在跑、卡在什么等待”(重载:text) |
session_memory_detail |
integer → TABLE(host text, pid integer, sess_id integer, command integer, slice integer, vsegno integer, context text, parent text, level integer, peak bigint, allocated bigint, total bigint) | 会话内的内存上下文树(context/parent/level/peak/allocated),找内存大户的根因上下文(重载:integer) |
session_memory_detail |
integer, integer → TABLE(host text, pid integer, sess_id integer, command integer, slice integer, vsegno integer, context text, parent text, level integer, peak bigint, allocated bigint, total bigint) | 会话内的内存上下文树(context/parent/level/peak/allocated),找内存大户的根因上下文(重载:integer, integer) |
segment_memory_summary |
() → TABLE(host text, pid integer, sess_id integer, command integer, slice integer, vsegno integer, context text, parent text, level integer, peak bigint, allocated bigint, total bigint) | 按段汇总内存占用 |
segment_memory_detail |
() → TABLE(host text, pid integer, sess_id integer, command integer, slice integer, vsegno integer, context text, parent text, level integer, peak bigint, allocated bigint, total bigint) | 段上进程的内存上下文明细 |
segment_memory_detail |
text → TABLE(host text, pid integer, sess_id integer, command integer, slice integer, vsegno integer, context text, parent text, level integer, peak bigint, allocated bigint, total bigint) | 段上进程的内存上下文明细(重载:text) |
cluster_memory_summary |
() → TABLE(host text, allocated bigint, total bigint) | 全集群各执行体内存一览(host、allocated、total),一条 SQL 看整体水位 |
Magma 存储引擎与 Compaction 33
| 函数 | 签名 → 返回 | 用途 |
|---|---|---|
get_all_vsc_name |
() → SETOF text | 列出所有 VSC(虚拟存储集群)名称,如 vsc_catalog / vsc_default |
get_magma_rangedistinfo |
cstring → cstring | 集群 range 分布清单(addr、rgid、rangeid),看分片是否均衡 |
get_range_num |
cstring → integer | 某 VSC 的 range 总数 |
get_magma_rangeid |
integer, anyelement → integer | 计算某行/某键值落在哪个 range(分片路由)(重载:integer, anyelement) |
get_magma_rangeid |
integer, anyelement, anyelement → integer | 计算某行/某键值落在哪个 range(分片路由)(重载:integer, anyelement, anyelement) |
get_magma_rangeid |
integer, anyelement, anyelement, anyelement → integer | 计算某行/某键值落在哪个 range(分片路由)(重载:integer, anyelement, anyelement, anyelement) |
get_magma_rangeid |
integer, anyelement, anyelement, anyelement, anyelement → integer | 计算某行/某键值落在哪个 range(分片路由)(重载:integer, anyelement, anyelement, anyelement, anyelement) |
get_magma_rgid_by_rangeid |
integer, cstring → cstring | range → replication group 的映射 |
get_magma_table_size |
cstring, cstring, cstring, integer → bigint | 按库/表/分区取 Magma 表物理大小(字节) |
get_magma_table_size_by_rangeid |
cstring, cstring, integer → bigint | 按 rangeid 取表大小,用于定位单 range 倾斜 |
get_magma_table_tuples |
cstring, cstring, cstring, integer → bigint | 取 Magma 表行数 |
get_magma_table_tuples_by_rangeid |
cstring, cstring, integer → bigint | 按 rangeid 取行数,判断分布倾斜 |
get_magma_table_path |
cstring, cstring, cstring, integer → cstring | 取表在 Magma 中的存储路径 |
dump_magma_buffer_pool |
cstring, cstring, cstring → TABLE(rgid integer, pagetype text, blockhit bigint, blockread bigint, blockdirtied bigint, blockwritten bigint, blockreadtimebyms bigint, blockwritetimebyms bigint, blockcount bigint, freecount bigint, blocksize integer) | Magma Buffer Pool 读写/命中统计(按 pgs 页类型) |
dump_magma_compact_view |
cstring, cstring → TABLE(rgid integer, running integer, waiting integer, running_table integer, running_index integer, running_txn integer, dropping_table integer, dropping_index integer, waiting_table integer, waiting_index integer, waiting_txn integer, waiting_drop_table integer, waiting_drop_index integer, isblocked boolean, iscleantxn boolean, rgworker_data_limit integer, rgworker_clean_limit integer, nodeworker_limit integer, ap_threshold real, tp_threshold real, index_threshold real) | Compaction 总览视图:运行中/等待中/是否阻塞/工作线程限额/阈值 |
dump_magma_compact_stats |
cstring, cstring → TABLE(rgid integer, table_finished bigint, table_cost bigint, table_min_cost bigint, table_max_cost bigint, index_finished bigint, index_cost bigint, index_min_cost bigint, index_max_cost bigint, txn_triggered bigint, major_finished bigint, major_cost bigint, minor_finished bigint, minor_cost bigint, cancelled bigint, exception bigint, dropped_table bigint, dropped_index bigint, tp_finished bigint, tp_cost bigint, blockallcount bigint, unblockallcount bigint, cleanup_txn bigint, uptime_min bigint) | Compaction 全量指标:表/索引完成数、耗时 min/max、事务触发、major/minor、取消与异常 |
dump_magma_compact_running |
text, text → TABLE(rgid integer, running integer, running_table integer, running_index integer, dropping_table integer, dropping_index integer) | 当前正在跑的 compaction 任务数(表/索引/删除) |
dump_magma_compact_waiting |
text, text → TABLE(rgid integer, waiting integer, waiting_table integer, waiting_index integer, waiting_drop_table integer, waiting_drop_index integer, waiting_txn integer) | 等待中的 compaction 任务计数 |
dump_magma_compact_waiting_jobs |
cstring, cstring, cstring → TABLE(rgid integer, dboid integer, tableid integer, indexid integer, score real, ismanual boolean, ismajor boolean, isdrop boolean, formattype text) | 等待队列中的具体作业(db/表/索引、分值、是否手动/是否 major) |
dump_magma_compact_table_stats |
text, text → TABLE(rgid integer, table_finished bigint, table_cost bigint, table_min_cost bigint, table_max_cost bigint, dropped_table bigint, uptime_min bigint) | 表级 compaction 统计(完成数、耗时) |
dump_magma_compact_index_stats |
text, text → TABLE(rgid integer, index_finished bigint, index_cost bigint, index_min_cost bigint, index_max_cost bigint, dropped_index bigint, uptime_min bigint) | 索引级 compaction 统计 |
dump_magma_kv_compact_stats |
cstring, cstring → TABLE(rgid integer, basiccount bigint, incrinsert bigint, incrdelete bigint, sstentries bigint, sstdeletions bigint, sstfilecount bigint, sstfilesize bigint, logfilesize bigint, logfilecount bigint, estimatevalidsize bigint, estimatetotalbytes bigint, autocompactcount bigint) | KV 层 compaction:SST 条目/删除量/文件数/大小、日志大小、自动 compaction 次数 |
dump_magma_wal_statistics |
cstring, cstring → TABLE(rgid integer, writecount bigint, writetimebyms bigint, flushcount bigint, flushtimebyms bigint) | WAL 写/刷统计:次数与耗时(ms) |
dump_magma_option |
cstring, cstring, cstring, boolean → cstring | 读取 Magma 运行参数(指定 VSC / 节点 / 选项名) |
select_magma_option |
cstring, cstring, cstring, boolean → cstring | 同上,按选项查询 Magma 参数值 |
select_magma_connection |
cstring, integer → cstring | 检测到某 Magma 节点的连通性/会话 |
compact_magma_internal_table |
cstring, integer → boolean | 手动触发内部表 compaction |
show_autocompact_pending_requests |
() → TABLE(dboid integer, relid integer, type text, caller text, wait_seconds_in_global integer, wait_seconds_in_local integer) | 自动 compaction 等待队列(db/表/类型/调用方/等待秒数) |
show_autocompact_latest_run_requests |
() → TABLE(dboid integer, relid integer, type text, caller text, state text, wait_seconds_in_global integer, wait_seconds_in_local integer, run_ms_cost integer) | 最近一次自动 compaction 的运行状态与耗时 |
show_autocompact_deduplication_requests |
() → TABLE(dboid integer, relid integer, type text, blocking_seconds integer) | 被去重合并的自动 compaction 请求(谁在等、阻塞多久) |
clear_autocompact_deduplication_requests |
() → void | 清空自动 compaction 去重队列 |
autocompact_pending_requests |
() → integer | 自动 compaction 待处理请求数(整数) |
autocompact_pending_requests_number |
() → integer | 同上,返回整型计数(另一实现) |
事务 / LTM / GTM 10
| 函数 | 签名 → 返回 | 用途 |
|---|---|---|
get_transaction_status |
bigint → TABLE(vscname text, txnstatus text) | 按 VSC / 事务号 / 文本查询事务状态(活跃、已提交、已回滚)(重载:bigint) |
get_transaction_status |
text → TABLE(vscname text, txnstatus text) | 按 VSC / 事务号 / 文本查询事务状态(活跃、已提交、已回滚)(重载:text) |
get_transaction_status |
text, text → text | 按 VSC / 事务号 / 文本查询事务状态(活跃、已提交、已回滚)(重载:text, text) |
dump_magma_ltm_status |
cstring, cstring → TABLE(rgid integer, localxmin bigint, localxmax bigint, abortxmin bigint, abortxmax bigint, abortsize bigint, pendingcount bigint, waterline bigint, onepccount bigint) | LTM 水位:localxmin/max、abortxmin/max、pending、waterline、1PC 计数 |
dump_magma_ltm_pending |
cstring, cstring → TABLE(rgid integer, pendingxid bigint) | LTM 待处理事务(pendingxid),排查长事务/事务堆积 |
dump_magma_ltm_files |
cstring, cstring → TABLE(rgid integer, filepath text, filesize bigint, maxxid bigint) | LTM(本地事务管理)文件列表与大小、maxxid |
dump_magma_gtm_status |
boolean → TABLE(session integer, readxidmin bigint, writexidmin bigint, txnid bigint, state text, waitingrgs text, receivedrgs text) | Magma GTM 状态:会话、readxidmin/writexidmin、事务状态与等待的 RG |
force_abort_transaction |
bigint, boolean → boolean | 强制回滚指定事务(救急用,慎用) |
force_commit_transaction |
bigint, boolean → boolean | 强制提交指定事务(救急用,慎用) |
test_xid_is_alive |
cstring → cstring | 探测某事务号是否仍存活 |
表 / 索引元信息与膨胀 15
| 函数 | 签名 → 返回 | 用途 |
|---|---|---|
get_table_oid_info |
_regclass regclass → TABLE(relname text, dboid oid, reloid oid, relfilenode oid, namespace oid, tablespace oid) | 批量解析表:库 oid、表 oid、relfilenode、命名空间、表空间 |
get_index_oid_info |
_regclass regclass → TABLE(relname text, indexname text, dboid oid, reloid oid, relfilenode oid, indexid oid, indexrelfilenode oid, namespace oid, tablespace oid) | 批量解析索引:索引 oid/relfilenode 与所属表 |
get_table_data |
regclass → TABLE(ctid_ tid, rangeid integer, blockid bigint, rowid bigint, txnid bigint, cmdid integer, cxid bigint) | 按 regclass 列出行的物理定位(rangeid/blockid/rowid/txnid/cmdid/cxid) |
get_table_dbt_data |
regclass → TABLE(ctid_ tid, rangeid integer, blockid bigint, rowid bigint, txnid bigint, cmdid integer, cxid bigint) | 同上,针对 DBT(delete bitmap)数据 |
dump_magma_relation_bloat |
text, text, oid, oid → TABLE(rgid integer, tableid bigint, aborted bigint, deleted bigint, total bigint, tuplebloat double precision, abortxmin bigint) | Magma 表膨胀:aborted/deleted/total 元组与膨胀率、abortxmin |
dump_magma_table_files |
cstring, cstring, oid, oid → TABLE(rgid integer, tableid bigint, aborted bigint, deleted bigint, total bigint, memtablecount bigint, stablebytes bigint, dbtbytes bigint, memtablebytes bigint, abortxmin bigint, maxcxid bigint, path cstring) | 单表文件分布:memtable 数、stable/dbt 字节、memtable 字节、路径 |
dump_magma_manifest |
cstring, cstring, oid, oid → TABLE(rgid integer, tableid bigint, snapshot text) | 表的 Manifest 快照(rgid、tableid、snapshot)(重载:cstring, cstring, oid, oid) |
dump_magma_manifest |
cstring, oid → TABLE(rgid integer, tableid bigint, snapshot text) | 表的 Manifest 快照(rgid、tableid、snapshot)(重载:cstring, oid) |
dump_magma_manifest_changes |
cstring, cstring, oid, oid → TABLE(rgid integer, tableid bigint, fileid bigint, gts bigint, rli bigint, change text) | Manifest 变更流水(fileid、gts、rli、change)(重载:cstring, cstring, oid, oid) |
dump_magma_manifest_changes |
cstring, oid → TABLE(rgid integer, tableid bigint, fileid bigint, gts bigint, rli bigint, change text) | Manifest 变更流水(fileid、gts、rli、change)(重载:cstring, oid) |
dump_magma_table_compact_xmin |
cstring, cstring, oid, oid → TABLE(rgid integer, dboid integer, tableid integer, xmin bigint) | 表可回收的 compaction xmin 水位 |
dump_magma_table_index_compact_xmin |
cstring, cstring, oid, oid, oid → TABLE(rgid integer, dboid integer, tableid integer, indexid integer, xmin bigint) | 索引可回收的 compaction xmin 水位 |
shrink_vci |
text, text → boolean | 收缩 VCI 列存索引文件,回收空间 |
rebuild_index_inplace |
oid, oid, boolean → boolean | 原地重建指定索引(不重建表) |
export_catalog |
path text, rebuildgppolicy boolean → void | 导出系统目录快照(path、是否重建策略),用于升级/迁移比对 |
统计信息 / 物化视图 5
| 函数 | 签名 → 返回 | 用途 |
|---|---|---|
autostat_inquiry_table |
oid, oid → TABLE(partkey text, total bigint, delta bigint, last_analyze_start text, last_analyze_end text, dropped boolean) | 查表的自动统计任务状态:分区、总行数、增量、上次 analyze 起止时间(重载:oid, oid) |
autostat_inquiry_table |
text → TABLE(partkey text, total bigint, delta bigint, last_analyze_start text, last_analyze_end text, dropped boolean) | 查表的自动统计任务状态:分区、总行数、增量、上次 analyze 起止时间(重载:text) |
autostat_inquiry_partition |
oid, oid → TABLE(partkey text, total bigint, delta bigint, last_analyze_start text, last_analyze_end text, dropped boolean) | 查分区的自动统计任务状态(重载:oid, oid) |
autostat_inquiry_partition |
text → TABLE(partkey text, total bigint, delta bigint, last_analyze_start text, last_analyze_end text, dropped boolean) | 查分区的自动统计任务状态(重载:text) |
get_matview_refresh_status |
() → TABLE(dbid integer, relid integer, usr integer, relname text, refreshtime text, refreshmethod text, schedulestart text, scheduleinterval text, lastrefreshtime text, lastrefreshdone text, currentrefreshtime text, dependlastupdate text, clientid integer, addr text, status text, refreshenabled boolean) | 物化视图刷新状态:上次刷新时间、方法、调度间隔、当前状态 |
Hudi / Hive 外表运维 17
| 函数 | 签名 → 返回 | 用途 |
|---|---|---|
show_hudi_files |
oid → TABLE(partion text, file_id text, base_instant text, file_name text, file_size bigint, num_insert bigint, num_update bigint, num_delete bigint, latest_time text, is_replaced boolean, is_cleaned boolean) | Hudi 数据文件清单(分区、file_id、base_instant、增删改行数、是否被替换/清理) |
show_hudi_sample_files |
oid → TABLE(partion text, file_id text, base_instant text, file_name text, file_size bigint, sample_file_name text, sample_file_size bigint, latest_time text, is_replaced boolean, is_cleaned boolean) | Hudi 采样文件(含 sample_file 名称与大小) |
get_hudi_files_snapshot |
oid, cstring, boolean → TABLE(file_type text, file_name text, file_size bigint) | Hudi 表文件快照(file_type、file_name、file_size) |
get_hudi_timeline |
oid, cstring, boolean → TABLE(file_type text, file_name text, file_size bigint) | Hudi timeline 各 instant 的文件列表 |
get_hudi_table_path |
oid → text | 取 Hudi 表在对象存储/HDFS 上的路径(重载:oid) |
get_hudi_table_path |
oid, keepprotocol boolean → cstring | 取 Hudi 表在对象存储/HDFS 上的路径(重载:oid, keepprotocol boolean) |
get_hudi_table_partitions_by_oid |
oid → TABLE(relname text, partkey text) | 按表 oid 列 Hudi 分区 |
get_hudi_partition_stats |
oid → TABLE(partkey text, row_number bigint) | 读取 Hudi 分区统计 |
hudi_table_partitions |
in_reloid oid → TABLE(partitionschamename text, partitiontablename text, partitionkey text, partitionname text) | Hudi 表分区清单(schema/表名/分区键) |
hudi_table_partitions_prefixed |
in_reloid oid → TABLE(partitionschamename text, partitiontablename text, partitionkey text, prefixed_partitionname text) | Hudi 分区清单(带前缀的物理分区名) |
hudi_file_contents |
oid, cstring → SETOF text | 读取 Hudi 数据文件内容(文本行) |
hudi_archive |
oid → void | 归档 Hudi timeline,控制 timeline 增长(重载:oid) |
hudi_archive |
oid, wait_for_lock boolean → void | 归档 Hudi timeline,控制 timeline 增长(重载:oid, wait_for_lock boolean) |
hudi_clean |
oid → void | 清理 Hudi 过期文件版本,回收存储(重载:oid) |
hudi_clean |
oid, strong_lock boolean → void | 清理 Hudi 过期文件版本,回收存储(重载:oid, strong_lock boolean) |
get_hive_partition_stats_detail |
oid → TABLE(partkey text, row_number bigint, starelid oid, staattnum smallint, stainherit boolean, stanullfrac real, stawidth integer, stadistinct real, stakind1 smallint, stakind2 smallint, stakind3 smallint, stakind4 smallint, stakind5 smallint, staop1 oid, staop2 oid, staop3 oid, staop4 oid, staop5 oid, stacoll1 oid, stacoll2 oid, stacoll3 oid, stacoll4 oid, stacoll5 oid, stanumbers1 real[], stanumbers2 real[], stanumbers3 real[], stanumbers4 real[], stanumbers5 real[], stavalues1 text, stavalues2 text, stavalues3 text, stavalues4 text, stavalues5 text) | 读取 Hive 分区统计明细(pg_statistic 结构) |
hive_stats |
rel regclass → TABLE(partkey text, row_number bigint, starelid oid, staattnum smallint, stainherit boolean, stanullfrac real, stawidth integer, stadistinct real, most_common_vals text, most_common_freqs real[], histogram_bounds text, correlation real, most_common_elems text, most_common_elem_freqs real[], elem_count_histogram real[]) | 读取 Hive 表统计(MCV/直方图) |
5.x HORC 升级迁移 5
| 函数 | 签名 → 返回 | 用途 |
|---|---|---|
upgrade_5x_horc_table |
oid → integer | 把 5.x HORC 表升级到新格式 |
cleanup_5x_horc_table |
oid → integer | 清理 5.x HORC 表残留对象 |
rollback_5x_horc_table |
oid → integer | 回滚 5.x HORC 表升级 |
batch_process_5x_horc_table |
action text, divisor integer, remainder integer, OUT oid oid, OUT nspname text, OUT relname text, OUT affected integer → SETOF record | 按取模分批处理 5.x HORC 表(action/divisor/remainder),大库灰度迁移 |
transfer_5x_horc_table |
action text, srcpath text, dstpath text, bstrict boolean → text | 迁移 5.x HORC 表数据(srcpath → dstpath) |
资源管理 / 锁 / 缓存 13
| 函数 | 签名 → 返回 | 用途 |
|---|---|---|
rm_dump |
() → cstring | 导出资源管理(RM)内部状态 |
rm_test_allocate |
cstring, cstring, double precision, double precision → cstring | RM 额度分配测试(资源组/内存) |
rm_test_release |
cstring, cstring, cstring → cstring | RM 额度释放测试 |
rm_test_release_all |
() → cstring | 释放全部 RM 测试额度 |
dlm_dump |
() → cstring | 导出分布式锁管理(DLM)内部状态,排查锁等待 |
get_vsc_runtime_info |
cstring, cstring, cstring → cstring | 读取 VSC 运行时信息(拓扑、节点、参数)(重载:cstring, cstring, cstring) |
get_vsc_runtime_info |
text, text → text | 读取 VSC 运行时信息(拓扑、节点、参数)(重载:text, text) |
cache_server_internal_statistic |
() → SETOF cstring | 缓存服务内部统计(命中率等) |
cache_server_external_statistic |
() → SETOF cstring | 缓存服务外部统计 |
cache_server_internal_clear |
() → SETOF void | 清空内部缓存 |
cache_server_external_clear |
() → SETOF void | 清空外部缓存 |
cache_server_set_quota |
double precision, double precision → SETOF void | 设置缓存配额(字节或整数单位)(重载:double precision, double precision) |
cache_server_set_quota |
integer, integer → SETOF void | 设置缓存配额(字节或整数单位)(重载:integer, integer) |
SQL 辅助 / 内部 4
| 函数 | 签名 → 返回 | 用途 |
|---|---|---|
sql_split |
text → TABLE(id integer, sql text) | 把多语句文本拆成单条(id + sql),用于批量执行/审核 |
sql_lineage |
text → TABLE(sql text, session_id integer, sql_type text, table_schema text, table_column text) | 解析 SQL 血缘:涉及的表、列、语句类型 |
oushu_exttable_fdw_handler |
() → fdw_handler | 外部表 FDW handler(内部用) |
oushu_exttable_fdw_validator |
text[], oid → void | 外部表 FDW 参数校验(内部用) |
04pg_catalog 里的 gp_* 视图(83 个)
GP7 把 gp_toolkit 的“统计/进度/拓扑”类能力下沉到了 pg_catalog,Oushu 完整继承。这部分比 gp_toolkit 更好用,因为不用装扩展、跨段自动聚合。
会话 1
| pg_catalog 视图 | 说明 |
|---|---|
gp_stat_activity |
带 segment 维度的会话/查询视图,含等待事件 |
集群拓扑 2
| pg_catalog 视图 | 说明 |
|---|---|
gp_pgdatabase |
各段数据库状态(是否可连接、是否 primary) |
gp_segment_configuration |
段/主控配置:content、role、status、hostname、port(GP 最重要的拓扑视图) |
库级统计 3
| pg_catalog 视图 | 说明 |
|---|---|
gp_stat_database |
各库事务、元组、死锁等累计计数(含 summary 汇总版) |
gp_stat_database_conflicts |
各库事务、元组、死锁等累计计数(含 summary 汇总版) |
gp_stat_database_summary |
各库事务、元组、死锁等累计计数(含 summary 汇总版) |
表/索引统计 20
| pg_catalog 视图 | 说明 |
|---|---|
gp_stat_all_indexes |
索引扫描次数与元组读取 |
gp_stat_xact_sys_tables |
本事务内的表/函数统计 |
gp_stat_xact_user_functions |
本事务内的表/函数统计 |
gp_stat_xact_user_tables |
本事务内的表/函数统计 |
gp_stat_user_tables_summary |
用户表级统计 |
gp_stat_xact_all_tables_summary |
本事务内的表/函数统计 |
gp_stat_xact_sys_tables_summary |
本事务内的表/函数统计 |
gp_stat_xact_user_tables_summary |
本事务内的表/函数统计 |
gp_stat_all_indexes_summary |
索引扫描次数与元组读取 |
gp_stat_sys_tables |
系统表级统计 |
gp_stat_user_tables |
用户表级统计 |
gp_stat_xact_all_tables |
本事务内的表/函数统计 |
gp_stat_sys_indexes_summary |
系统索引统计 |
gp_stat_user_indexes_summary |
用户索引统计 |
gp_stat_all_tables |
表级扫描、元组增删改、vacuum/analyze 时间(all/user/sys/xact 多个版本 + summary) |
gp_stat_sys_indexes |
系统索引统计 |
gp_stat_user_indexes |
用户索引统计 |
gp_stat_all_tables_summary |
表级扫描、元组增删改、vacuum/analyze 时间(all/user/sys/xact 多个版本 + summary) |
gp_stat_sys_tables_summary |
系统表级统计 |
gp_stat_xact_user_functions_summary |
本事务内的表/函数统计 |
IO 统计 18
| pg_catalog 视图 | 说明 |
|---|---|
gp_statio_all_sequences |
表/索引文件层 IO:堆块读写、索引块读写、TOAST 读写 |
gp_statio_user_tables |
表/索引文件层 IO:堆块读写、索引块读写、TOAST 读写 |
gp_statio_user_tables_summary |
表/索引文件层 IO:堆块读写、索引块读写、TOAST 读写 |
gp_statio_all_sequences_summary |
表/索引文件层 IO:堆块读写、索引块读写、TOAST 读写 |
gp_statio_all_tables |
表/索引文件层 IO:堆块读写、索引块读写、TOAST 读写 |
gp_statio_sys_indexes |
表/索引文件层 IO:堆块读写、索引块读写、TOAST 读写 |
gp_statio_sys_sequences |
表/索引文件层 IO:堆块读写、索引块读写、TOAST 读写 |
gp_statio_sys_tables |
表/索引文件层 IO:堆块读写、索引块读写、TOAST 读写 |
gp_statio_user_sequences_summary |
表/索引文件层 IO:堆块读写、索引块读写、TOAST 读写 |
gp_statio_all_indexes_summary |
表/索引文件层 IO:堆块读写、索引块读写、TOAST 读写 |
gp_statio_sys_indexes_summary |
表/索引文件层 IO:堆块读写、索引块读写、TOAST 读写 |
gp_statio_all_indexes |
表/索引文件层 IO:堆块读写、索引块读写、TOAST 读写 |
gp_statio_user_indexes |
表/索引文件层 IO:堆块读写、索引块读写、TOAST 读写 |
gp_statio_user_sequences |
表/索引文件层 IO:堆块读写、索引块读写、TOAST 读写 |
gp_statio_all_tables_summary |
表/索引文件层 IO:堆块读写、索引块读写、TOAST 读写 |
gp_statio_sys_tables_summary |
表/索引文件层 IO:堆块读写、索引块读写、TOAST 读写 |
gp_statio_sys_sequences_summary |
表/索引文件层 IO:堆块读写、索引块读写、TOAST 读写 |
gp_statio_user_indexes_summary |
表/索引文件层 IO:堆块读写、索引块读写、TOAST 读写 |
进度视图 13
| pg_catalog 视图 | 说明 |
|---|---|
gp_stat_progress_copy |
长任务进度(vacuum/analyze/copy/create index/cluster/basebackup/dtx recovery),GP7 独有的一类 |
gp_stat_progress_vacuum |
长任务进度(vacuum/analyze/copy/create index/cluster/basebackup/dtx recovery),GP7 独有的一类 |
gp_stat_progress_cluster_summary |
长任务进度(vacuum/analyze/copy/create index/cluster/basebackup/dtx recovery),GP7 独有的一类 |
gp_stat_progress_create_index_summary |
长任务进度(vacuum/analyze/copy/create index/cluster/basebackup/dtx recovery),GP7 独有的一类 |
gp_stat_progress_dtx_recovery |
长任务进度(vacuum/analyze/copy/create index/cluster/basebackup/dtx recovery),GP7 独有的一类 |
gp_stat_progress_copy_summary |
长任务进度(vacuum/analyze/copy/create index/cluster/basebackup/dtx recovery),GP7 独有的一类 |
gp_stat_progress_basebackup_summary |
长任务进度(vacuum/analyze/copy/create index/cluster/basebackup/dtx recovery),GP7 独有的一类 |
gp_stat_progress_analyze |
长任务进度(vacuum/analyze/copy/create index/cluster/basebackup/dtx recovery),GP7 独有的一类 |
gp_stat_progress_basebackup |
长任务进度(vacuum/analyze/copy/create index/cluster/basebackup/dtx recovery),GP7 独有的一类 |
gp_stat_progress_cluster |
长任务进度(vacuum/analyze/copy/create index/cluster/basebackup/dtx recovery),GP7 独有的一类 |
gp_stat_progress_create_index |
长任务进度(vacuum/analyze/copy/create index/cluster/basebackup/dtx recovery),GP7 独有的一类 |
gp_stat_progress_vacuum_summary |
长任务进度(vacuum/analyze/copy/create index/cluster/basebackup/dtx recovery),GP7 独有的一类 |
gp_stat_progress_analyze_summary |
长任务进度(vacuum/analyze/copy/create index/cluster/basebackup/dtx recovery),GP7 独有的一类 |
WAL/归档 9
| pg_catalog 视图 | 说明 |
|---|---|
gp_stat_bgwriter |
后台写进程统计 |
gp_stat_slru |
SLRU 缓存统计 |
gp_stat_wal |
WAL 生成量与写入次数 |
gp_stat_wal_receiver |
WAL 接收端(mirror/standby)状态 |
gp_stat_bgwriter_summary |
后台写进程统计 |
gp_stat_archiver_summary |
归档进程统计 |
gp_stat_archiver |
归档进程统计 |
gp_stat_wal_summary |
WAL 生成量与写入次数 |
gp_stat_slru_summary |
SLRU 缓存统计 |
复制 2
| pg_catalog 视图 | 说明 |
|---|---|
gp_replication_origin_status |
复制槽、复制源状态,排查同步延迟 |
gp_replication_slots |
复制槽、复制源状态,排查同步延迟 |
内存 1
| pg_catalog 视图 | 说明 |
|---|---|
gp_backend_memory_contexts |
后端进程内存上下文(顶层分配),定位内存大户 |
Interconnect 3
| pg_catalog 视图 | 说明 |
|---|---|
gp_endpoints |
当前 interconnect 端点(发送/接收端、cursorname、state) |
gp_segment_endpoints |
按段列出的端点信息 |
gp_session_endpoints |
按会话列出的端点信息 |
参数 3
| pg_catalog 视图 | 说明 |
|---|---|
gp_config |
配置项视图 |
gp_file_settings |
配置文件解析结果,排查配置未生效 |
gp_settings |
运行参数(含 source、pending_restart) |
统计信息 2
| pg_catalog 视图 | 说明 |
|---|---|
gp_stats |
扩展统计对象 |
gp_stats_ext |
扩展统计对象 |
函数统计 2
| pg_catalog 视图 | 说明 |
|---|---|
gp_stat_user_functions |
UDF 调用次数与耗时 |
gp_stat_user_functions_summary |
UDF 调用次数与耗时 |
对象操作 1
| pg_catalog 视图 | 说明 |
|---|---|
gp_stat_operations |
库内对象操作计数 |
连接安全 2
| pg_catalog 视图 | 说明 |
|---|---|
gp_stat_ssl |
连接是否走 SSL |
gp_stat_gssapi |
连接是否走 GSSAPI |
游标 1
| pg_catalog 视图 | 说明 |
|---|---|
gp_cursors |
会话游标清单 |
与 GP7 gp_toolkit 最大的差别:这一层全是
gp_stat_*/gp_statio_* 的“全段汇总版”,在协调节点查一次就能拿到所有段的合计;要看单段,加 where gp_segment_id = N(部分视图需要 join gp_dist_random)。05pg_catalog 里的 gp_* 函数(79 个)
真正能日常用的是第一组;其余多是压缩编解码、HLL/百分位聚合的内部实现,知道存在即可。
运维可用 28
| 函数 | 签名 → 返回 | 说明 |
|---|---|---|
gp_adjust_priority |
integer, integer, text → integer | 调整语句在资源队列中的优先级 |
gp_adjust_priority |
integer, integer, integer → integer | 调整语句在资源队列中的优先级 |
gp_array_agg |
anynonarray → anyarray | 数组聚合(GP 并行版 array_agg) |
gp_array_agg |
anyarray → anyarray | 数组聚合(GP 并行版 array_agg) |
gp_backend_info |
OUT id integer, OUT type "char", OUT content integer, OUT host text, OUT port integer, OUT pid integer → SETOF record | 当前后端信息(id/type/host/port/pid) |
gp_create_restore_point |
restore_point_name text, OUT gp_segment_id smallint, OUT restore_lsn pg_lsn → SETOF record | 创建恢复点(返回各段 LSN) |
gp_execution_dbid |
() → integer | 当前执行体所在库 oid |
gp_execution_segment |
() → integer | 当前执行体(segment)编号,写 UDF/排查数据倾斜必备 |
gp_get_endpoints |
OUT gp_segment_id integer, OUT auth_token text, OUT cursorname text, OUT sessionid integer, OUT hostname character varying, OUT port integer, OUT username text, OUT state text, OUT endpointname text → SETOF record | 取 interconnect 端点 |
gp_get_segment_endpoints |
OUT auth_token text, OUT databaseid oid, OUT senderpid integer, OUT receiverpid integer, OUT state text, OUT gp_segment_id integer, OUT sessionid integer, OUT username text, OUT endpointname text, OUT cursorname text → SETOF record | 取段级端点 |
gp_get_session_endpoints |
OUT gp_segment_id integer, OUT auth_token text, OUT cursorname text, OUT sessionid integer, OUT hostname character varying, OUT port integer, OUT username text, OUT state text, OUT endpointname text → SETOF record | 取会话级端点 |
gp_get_suboverflowed_backends |
() → integer[] | 查子溢出(suboverflowed)后端,连接数打满时用 |
gp_list_backend_priorities |
() → SETOF record | 列出后端优先级 |
gp_log_backend_memory_contexts |
bigint, bigint → bigint | 把指定后端的内存上下文写入日志 |
gp_log_backend_memory_contexts |
bigint → bigint | 把指定后端的内存上下文写入日志 |
gp_opt_version |
() → text | 优化器版本标识 |
gp_pgdatabase |
() → SETOF record | 返回各段数据库状态(函数版) |
gp_read_error_log |
exttable text, OUT cmdtime timestamp with time zone, OUT relname text, OUT filename text, OUT linenum integer, OUT bytenum integer, OUT errmsg text, OUT rawdata text, OUT rawbytes bytea → SETOF record | 读取外部表错误日志(EXT 表落盘错误行) |
gp_read_persistent_error_log |
exttable text, OUT cmdtime timestamp with time zone, OUT relname text, OUT filename text, OUT linenum integer, OUT bytenum integer, OUT errmsg text, OUT rawdata text, OUT rawbytes bytea → SETOF record | 读取持久化外部表错误日志 |
gp_request_fts_probe_scan |
() → SETOF boolean | 主动触发 FTS(故障探测)扫描,加快段状态刷新 |
gp_segment_configuration |
() → SETOF record | 返回段配置(函数版,可在 join 中使用) |
gp_switch_wal |
OUT gp_segment_id smallint, OUT pg_switch_wal pg_lsn, OUT pg_walfile_name text → SETOF record | 在各段上切换 WAL 文件(配合备份/归档) |
gp_tablespace_location |
tblspc_oid oid, OUT gp_segment_id integer, OUT tblspc_loc text → SETOF record | 查表空间在各段的物理路径 |
gp_tablespace_segment_location |
tblspc_oid oid, OUT gp_segment_id integer, OUT tblspc_loc text → SETOF record | 查表空间在某段的物理路径 |
gp_terminate_mpp_backends |
() → void | 终止所有 MPP 后端会话(清场用,慎用) |
gp_truncate_error_log |
text → boolean | 清空外部表错误日志 |
gp_truncate_persistent_error_log |
text → boolean | 清空持久化错误日志 |
gp_wait_parallel_retrieve_cursor |
cursorname text, timeout_sec integer, OUT finished boolean → SETOF boolean | 等待并行游标取数完成(超时控制) |
聚合:基数估算 7
| 函数 | 签名 → 返回 | 说明 |
|---|---|---|
gp_hyperloglog_accum |
anyelement → gp_hyperloglog_estimator | HyperLogLog 基数估算聚合(内部实现,配 gp_hyperloglog_accum 使用) |
gp_hyperloglog_add_item_agg_default |
counter gp_hyperloglog_estimator, item anyelement → gp_hyperloglog_estimator | HyperLogLog 基数估算聚合(内部实现,配 gp_hyperloglog_accum 使用) |
gp_hyperloglog_comp |
counter gp_hyperloglog_estimator → gp_hyperloglog_estimator | HyperLogLog 基数估算聚合(内部实现,配 gp_hyperloglog_accum 使用) |
gp_hyperloglog_get_estimate |
counter gp_hyperloglog_estimator → double precision | HyperLogLog 基数估算聚合(内部实现,配 gp_hyperloglog_accum 使用) |
gp_hyperloglog_in |
value cstring → gp_hyperloglog_estimator | HyperLogLog 基数估算聚合(内部实现,配 gp_hyperloglog_accum 使用) |
gp_hyperloglog_merge |
estimator1 gp_hyperloglog_estimator, estimator2 gp_hyperloglog_estimator → gp_hyperloglog_estimator | HyperLogLog 基数估算聚合(内部实现,配 gp_hyperloglog_accum 使用) |
gp_hyperloglog_out |
counter gp_hyperloglog_estimator → cstring | HyperLogLog 基数估算聚合(内部实现,配 gp_hyperloglog_accum 使用) |
聚合:百分位 11
| 函数 | 签名 → 返回 | 说明 |
|---|---|---|
gp_percentile_cont |
double precision, double precision, bigint, bigint → double precision | 百分位聚合(并行 percentile_cont / percentile_disc 实现) |
gp_percentile_cont |
interval, double precision, bigint, bigint → interval | 百分位聚合(并行 percentile_cont / percentile_disc 实现) |
gp_percentile_cont |
timestamp without time zone, double precision, bigint, bigint → timestamp without time zone | 百分位聚合(并行 percentile_cont / percentile_disc 实现) |
gp_percentile_cont |
timestamp with time zone, double precision, bigint, bigint → timestamp with time zone | 百分位聚合(并行 percentile_cont / percentile_disc 实现) |
gp_percentile_cont_float8_transition |
double precision, double precision, bigint, bigint → double precision | 百分位聚合(并行 percentile_cont / percentile_disc 实现) |
gp_percentile_cont_interval_transition |
interval, double precision, bigint, bigint → interval | 百分位聚合(并行 percentile_cont / percentile_disc 实现) |
gp_percentile_cont_timestamp_transition |
timestamp without time zone, double precision, bigint, bigint → timestamp without time zone | 百分位聚合(并行 percentile_cont / percentile_disc 实现) |
gp_percentile_cont_timestamptz_transition |
timestamp with time zone, double precision, bigint, bigint → timestamp with time zone | 百分位聚合(并行 percentile_cont / percentile_disc 实现) |
gp_percentile_disc |
anyelement, double precision, bigint, bigint → anyelement | 百分位聚合(并行 percentile_cont / percentile_disc 实现) |
gp_percentile_disc_transition |
anyelement, double precision, bigint, bigint → anyelement | 百分位聚合(并行 percentile_cont / percentile_disc 实现) |
gp_percentile_final |
anyelement → anyelement | 百分位聚合(并行 percentile_cont / percentile_disc 实现) |
内部支撑 13
| 函数 | 签名 → 返回 | 说明 |
|---|---|---|
gp_acquire_correlations |
oid, boolean → SETOF record | 批量加锁相关表(内部用) |
gp_acquire_sample_rows |
oid, integer, boolean, double precision, text → SETOF record | 采样表数据(统计信息采集内部用) |
gp_deprecated |
() → void | 废弃标记函数(内部) |
gp_dump_query_oids |
text → text | 导出查询涉及的 oid(依赖分析) |
gp_expand_bump_version |
() → void | catalog 版本号自增(内部) |
gp_expand_lock_catalog |
() → void | catalog 加锁(内部) |
gp_exttable_fdw_handler |
() → fdw_handler | 外部表 FDW handler(内部) |
gp_exttable_permission_check |
text[], oid → void | 外部表权限校验(内部) |
gp_replication_error |
() → text | 复制错误信息 |
gp_stat_get_coordinator_replication |
() → SETOF record | 协调节点复制统计(内部) |
gp_stat_get_master_replication |
() → SETOF record | 主控复制统计(内部) |
gp_stat_get_segment_replication |
() → SETOF record | 段复制统计(内部) |
gp_stat_get_segment_replication_error |
() → SETOF record | 段复制错误统计(内部) |
压缩编解码(内部) 20
| 函数 | 签名 → 返回 | 说明 |
|---|---|---|
gp_dummy_compression_compress |
internal, integer, internal, integer, internal, internal → internal | 空压缩占位函数(内部) |
gp_dummy_compression_constructor |
internal, internal, boolean → internal | 空压缩占位函数(内部) |
gp_dummy_compression_decompress |
internal, integer, internal, integer, internal, internal → internal | 空压缩占位函数(内部) |
gp_dummy_compression_destructor |
internal → internal | 空压缩占位函数(内部) |
gp_dummy_compression_validator |
internal → internal | 空压缩占位函数(内部) |
gp_rle_type_compress |
internal, integer, internal, integer, internal, internal → void | RLE 行程编码压缩内部函数 |
gp_rle_type_constructor |
internal, internal, boolean → internal | RLE 行程编码压缩内部函数 |
gp_rle_type_decompress |
internal, integer, internal, integer, internal, internal → void | RLE 行程编码压缩内部函数 |
gp_rle_type_destructor |
internal → void | RLE 行程编码压缩内部函数 |
gp_rle_type_validator |
internal → void | RLE 行程编码压缩内部函数 |
gp_zlib_compress |
internal, integer, internal, integer, internal, internal → void | zlib 压缩编解码内部函数 |
gp_zlib_constructor |
internal, internal, boolean → internal | zlib 压缩编解码内部函数 |
gp_zlib_decompress |
internal, integer, internal, integer, internal, internal → void | zlib 压缩编解码内部函数 |
gp_zlib_destructor |
internal → void | zlib 压缩编解码内部函数 |
gp_zlib_validator |
internal → void | zlib 压缩编解码内部函数 |
gp_zstd_compress |
internal, integer, internal, integer, internal, internal → void | zstd 压缩编解码内部函数 |
gp_zstd_constructor |
internal, internal, boolean → internal | zstd 压缩编解码内部函数 |
gp_zstd_decompress |
internal, integer, internal, integer, internal, internal → void | zstd 压缩编解码内部函数 |
gp_zstd_destructor |
internal → void | zstd 压缩编解码内部函数 |
gp_zstd_validator |
internal → void | zstd 压缩编解码内部函数 |
06和 GP7 gp_toolkit 的对照
左侧按 GP7 官方 gp_toolkit 的六个功能族归纳;右侧是本环境实测的“有/无 + 替代路径”。
| 功能族 | GP7 gp_toolkit 代表对象 | 本环境 | 替代路径(实测) |
|---|---|---|---|
| 表膨胀 | gp_bloat_diag、gp_bloat_index_diag |
无 | Magma 行存没有 PG 那种 page 级膨胀。用 dump_magma_relation_bloat(vsc,db,oid,oid) 看 aborted/deleted/total 与膨胀率;文件级用 dump_magma_table_files |
| 数据倾斜 | gp_skew_coefficients、gp_skew_idle_fraction |
无 | 按 range 看分布:get_magma_rangedistinfo('vsc_default')、get_magma_table_tuples_by_rangeid、get_range_num;SQL 层配合 gp_segment_id 分组计数 |
| workfile 落盘 | gp_workfile_usage_per_query 等 5 个 |
无 | Oushu 走 Magma/VSC,不做 GP 式算子 workfile。落盘压力看 dump_magma_wal_statistics、dump_magma_ltm_files;执行进度看 gp_stat_progress_* |
| 资源队列 | gp_resqueue_status、gp_resq_activity、gp_resq_rule |
无 | Oushu 用 RM(资源管理)+ lava 管控台,不在库内建队列视图。库内只有 rm_dump()、rm_test_allocate/release 做内部态导出与压测 |
| 锁诊断 | gp_locks_on_relation、gp_locks_on_transaction |
有替代 | pg_catalog.oushu_lock_status:比 pg_locks 多出 mppsessionid、mppiswriter、gp_segment_id,能直接定位跨段的锁等待;DLM 内部态用 dlm_dump() |
| 分区信息 | gp_partitions、gp_partition_templates、gp_partition_default |
无 | 内核是 PG12 语法:走 pg_class/pg_inherits/pg_partitioned_table 自建查询;外表分区用 hudi_table_partitions(oid)、get_hudi_table_partitions_by_oid(oid) |
| 磁盘余量 | gp_disk_free、gp_disk_free_external_table |
无 | 段本地盘 df -h /data1 /data2(gpssh -f hostfile 批量);HDFS 侧 hdfs dfsadmin -report;Magma 内部容量 dump_magma_buffer_pool、dump_magma_kv_compact_stats |
| 表/索引统计 | gp_toolkit.__gp_user_tables 等内部视图 |
有替代 | gp_stat_user_tables、gp_stat_user_indexes、gp_statio_user_tables —— 命名沿用 PG 的 stat 体系,字段更全(含 summary 汇总版) |
迁移提醒:任何历史脚本里写
gp_toolkit.xxx 的,在本环境会直接报 schema "gp_toolkit" does not exist。要么改用上表替代,要么自建一个兼容 schema + 视图做桥接。07可直接跑的诊断 SQL(已实测)
库是空的(只有 postgres/template0/template1),SQL 全部在当前实例验证过可执行。
存储与分片
select * from oushu_toolkit.get_all_vsc_name(); -- vsc_catalog, vsc_default select * from oushu_toolkit.get_range_num('vsc_default'); -- 4 select * from oushu_toolkit.get_magma_rangedistinfo('vsc_default');
vsc_catalog / vsc_default
4
[L] addr=192.168.56.103:6688 rgid=15 rangeid=3
[L] addr=192.168.56.105:6688 rgid=14 rangeid=2
[L] addr=192.168.56.104:6688 rgid=13 rangeid=1
[L] addr=192.168.56.103:6688 rgid=12 rangeid=0
4
[L] addr=192.168.56.103:6688 rgid=15 rangeid=3
[L] addr=192.168.56.105:6688 rgid=14 rangeid=2
[L] addr=192.168.56.104:6688 rgid=13 rangeid=1
[L] addr=192.168.56.103:6688 rgid=12 rangeid=0
内存与 CPU
select * from oushu_toolkit.cluster_memory_summary() order by allocated desc limit 5; select * from oushu_toolkit.segment_status_summary order by total_cpu_usage desc; select * from pg_catalog.gp_backend_memory_contexts order by total_bytes desc limit 15;
cluster_memory_summary 实测输出(部分):
192.168.56.103 | 7865784 | 10221912
192.168.56.104 | 7661056 | 9933544
192.168.56.105 | 7644528 | 9850856 ← allocated / total,字节
192.168.56.103 | 7865784 | 10221912
192.168.56.104 | 7661056 | 9933544
192.168.56.105 | 7644528 | 9850856 ← allocated / total,字节
会话与等待
select * from pg_catalog.gp_stat_activity where state <> 'idle'; select sess_id, state, count, total_cpu_usage from oushu_toolkit.session_status_summary order by total_cpu_usage desc;
实测 gp_stat_activity 返回 49 行(含段上与内部会话),过滤 idle 后即是真实在跑的作业
事务与长事务
select * from oushu_toolkit.get_transaction_status('vsc_default');
select * from oushu_toolkit.dump_magma_ltm_pending('vsc_default','postgres'); -- 参数按 product 文档
get_transaction_status('vsc_default') 实测:逐个 RG 返回 "Rg(12):Invalid transactionId vsc_default"(当前无活跃事务)
拓扑与锁
select content, role, preferred_role, status, hostname, port from pg_catalog.gp_segment_configuration order by content, role; select pid, mode, granted, mppsessionid, gp_segment_id, relation::regclass from pg_catalog.oushu_lock_status where not granted;
gp_segment_configuration 实测:content=-1 两条(node1/node2:7432),content=0/1/2(node1/node2/node3:40000),status 全为 u
SQL 辅助
select * from oushu_toolkit.sql_split('select 1; select 2;');
select * from oushu_toolkit.sql_lineage('insert into t1 select * from t2');
08使用注意事项
| 事项 | 说明 |
|---|---|
| schema 前缀 | 所有函数都在 oushu_toolkit 下,默认 search_path 不含它,必须带前缀或先 set search_path = oushu_toolkit, public; |
| VSC 参数 | Magma 系函数的第一个参数基本是 VSC 名,只有两个取值:vsc_catalog(元数据)、vsc_default(用户数据)。先用 get_all_vsc_name() 确认 |
| 权限 | 状态/内存/Magma 诊断类函数需超级用户(本环境用 oushu);普通业务账号调用会报权限不足 |
| 参数含义 | pg_proc 无注释,多参函数(如前两参为 vsc/db)只能靠签名推断,生产脚本上线前先用小库验证一次 |
| 跨段开销 | dump_magma_* 会逐个 range 请求 Magma 服务;全量 compaction 统计在业务高峰跑会拖慢 IO,建议低峰或按 vsc 分开跑 |
| 危险函数 | force_abort_transaction、force_commit_transaction、gp_terminate_mpp_backends、cache_server_*_clear 属救急手段,会直接改变运行态,勿写进定时任务 |
| 兼容层 | 要从 GP 迁脚本过来,建议自建 create schema gp_toolkit; + 同名视图指向 gp_stat_* / oushu_lock_status,避免逐条改 SQL |
09临时文件(workfile)落盘与“哪个会话干的”
这一节全部来自 2026-12-02 07:13 在现网实例上的实测:造了一条 800k × 800k 的笛卡尔 + 排序 + limit 的语句,看它到底往哪写、文件叫什么、怎么反查会话。
9.1 决定“放哪儿”的参数
| 参数 | 本环境实测值 | 说明 |
|---|---|---|
oushudb_main_temp_directory |
/data1/oushudb/tmp,/data2/oushudb/tmp |
主控(coordinator)临时目录 —— 就是你要找的那个变量。逗号分隔多盘,按查询轮询 |
oushudb_segment_temp_directory |
/data1/oushudb/tmp,/data2/oushudb/tmp |
段(QE)临时目录。笛卡尔、大排序、大 hash 的落盘绝大部分在这里 |
temp_tablespaces |
(空) | 只管临时表,不影响算子落盘,别被名字误导 |
work_mem |
32768 kB | 单算子内存上限,超了才落盘;实测 set 成 1MB 会立刻触发 |
gp_workfile_limit_per_query |
0 kB | 每查询每段落盘上限,0 = 不限,这是最容易被打爆的一个 |
gp_workfile_limit_per_segment |
0 kB | 每段总量上限,0 = 不限 |
gp_workfile_limit_files_per_query |
100000 | 单查询文件数上限,防小文件刷爆 inode |
temp_file_limit |
-1 kB | 单进程临时文件总量,-1 = 不限 |
log_temp_files |
-1 | 本应“超过 N kB 记日志”,实测新执行器不产出日志(见 9.5) |
statement_timeout |
3600000 ms | 1 小时,兜底止损 |
9.2 两代执行器,两种命名 —— 反查的钥匙就藏在名字里
| 执行器 | 形态 | 实测样例 | 怎么反查会话 |
|---|---|---|---|
| 新执行器 (NewExecutor=ON,默认) |
目录 | /data2/oushudb/tmp/QID1048665_2_slice_1_segment_3_worker_0_node_4/目录内: merge0 … mergeN |
目录名第一段数字 = sess_id,直接查 pg_stat_activity where sess_id=1048665 |
| 旧执行器 (legacy workfile) |
单文件 | pgsql_tmpslice0_tuplestore105570.0pgsql_tmpslice0_tuplestore105570.1 |
文件名尾部数字 = 后端 pid,查 pg_stat_activity where pid=105570 或 gp_stat_activity |
命名结构:
QID{sess_id}_{qid}_slice_{N}_segment_{N}_worker_{N}_node_{N}。一个查询按 slice 拆到多条记录,segment_N 对应 gp_segment_configuration.content,能直接看出“哪一段写得最多”。9.3 实测过程与数据(2026-12-02 07:13–07:20)
-- 造数:两张 80 万行的 magma 表(按 i 哈希分布) create table tt_spill_a (i int, pad text, k int, filler text) using magmaap tablespace vsc_default distributed by (i); insert into tt_spill_a select i, md5(i::text), i % 1000, repeat('x',60) from generate_series(1,800000) i; -- 触发落盘:笛卡尔 + 排序 + limit,单算子内存压到 1MB set work_mem='1MB'; select count(*) from ( select a.i ai, b.i bi from tt_spill_a a, tt_spill_b b order by a.pad, b.pad limit 20000000) s;
| 时刻 | 观测到的现象 |
|---|---|
| 07:13 | 语句发起,node1 的 /data2/oushudb/tmp 下立即出现 QID1048665_2_slice_1_segment_3_worker_0_node_4/ |
| 07:15 | 该目录涨到 3.3 GB,里面是 merge0…merge69,单个 46.7 MB(排序归并段) |
| 07:16 | node1 的 /data1/oushudb/tmp 另起 …segment_0… 目录,1.1 GB;node2/node3 各有一个小目录 |
| 07:20 | 取消查询(pg_cancel_backend)→ 约 20 秒后目录自动删除,总体从 22 GB 回落到 19 GB |
会话反查实测:
目录 QID1048665_… → sess_id = 1048665
select pid, sess_id, state, query from pg_stat_activity where sess_id = 1048665;
→ 14039 | 1048665 | active | set work_mem='1MB'; … from tt_spill_a a, tt_spill_b b order by … limit 20000000
目录 QID1048665_… → sess_id = 1048665
select pid, sess_id, state, query from pg_stat_activity where sess_id = 1048665;
→ 14039 | 1048665 | active | set work_mem='1MB'; … from tt_spill_a a, tt_spill_b b order by … limit 20000000
顺手发现一个现成的“事故现场”:node1
/data2/oushudb/tmp 里还躺着 20 个、共 19 GB 的旧执行器文件(pgsql_tmpslice0_tuplestore105570.* 与 …106506.*,11-26 生成)。对应 PID 105570、106506 的进程早已不存在,lsof 也查不到占用 —— 典型的“会话异常终止后遗留,不会自动回收”。这块盘和根分区同一个 LVM(117 GB,已用 87 GB),19 GB 白占很危险。9.4 定位“哪个会话”的三步法
# 第 1 步:在三台节点上看谁在写(按时间排序,看大小) for h in node1 node2 node3; do echo "=== $h"; ssh $h "du -sh /data1/oushudb/tmp/QID* /data2/oushudb/tmp/QID* 2>/dev/null | sort -rh | head" done # 旧执行器遗留文件(按时间找最新的) ls -lat /data*/oushudb/tmp/ | grep pgsql_tmp | head
-- 第 2 步:目录名里的 QID → sess_id → 语句全文 select pid, sess_id, usename, client_addr, state, wait_event, now()-query_start as elapsed, query from pg_catalog.pg_stat_activity where sess_id = 1048665; -- 换成目录里的数字 -- 第 3 步:旧文件里的 PID → 段上的执行体(跨段查要带 gp_segment_id) select gp_segment_id, pid, sess_id, state, wait_event, left(query,80) from pg_catalog.gp_stat_activity where pid = 105570;
# 兜底:进程还在但会话信息查不到时,直接问操作系统 ls -l /proc/105570/cwd # 指向 /data1|2/oushudb/... tr '\0' ' ' < /proc/105570/cmdline; echo cat /proc/105570/stat | awk '{print "rss_pages="$24}'
9.5 三个“以为能查到、其实查不到”的坑(均实测)
| 你以为 | 实测结果 |
|---|---|
select temp_files, temp_bytes from pg_stat_database |
全程 0 / 0。新执行器落盘不计入该计数,不能用来判断“有没有落盘” |
set log_temp_files=0; 然后去日志里 grep temporary file |
日志里一条都没有(main / segment 两份 CSV 都翻了)。该参数在新执行器下不产出记录 |
explain (analyze) 看 Sort Method |
显示 Sort Method: (null) (null): 0kB,即使实际写了 3.3 GB。计划里也不会出现 external merge / Workfile 字样 |
结论:OushuDB 2.4.6 上判断临时文件,只能看文件系统(
oushudb_*_temp_directory 下的 QID 目录 / pgsql_tmp 文件)+ 用 QID/PID 反查会话。GP 那套 gp_toolkit.gp_workfile_usage_per_query 在本环境既没有 schema,也没有等价物。9.6 防爆与善后
| 动作 | 做法 |
|---|---|
| 先限流 | alter database xxx set gp_workfile_limit_per_query='20GB'; 给单查询设上限;temp_file_limit 给单进程设上限,超限直接报错而不是写满盘 |
| 治笛卡尔 | 笛卡尔的落盘量 ≈ 左表行数 × 右表行宽,一张 80 万行小表也能写出 GB 级 merge;优先补连接条件、加 limit、或先聚合再关联 |
| 日常盯盘 | 定时采集 du -s /data*/oushudb/tmp 与 QID 目录数量,设阈值告警;比任何库内视图都准 |
| 孤儿判定 | 目录/文件存在 + lsof +D <tmpdir> 与 fuser 均无占用 + mtime 已超数小时 → 遗留物。先用 find … -print 列出清单,按变更流程确认后再删,切勿脚本化无脑清理 |
| 事故复盘 | 遗留文件里的 PID 已消失时,用文件 mtime 对齐 pg_stat_activity 历史(若有采集)或 oushudb-YYYYMMDD.csv 日志定位当时会话 |
