← 返回 Skills 市场
wenbingyu

Hologres Slow Query Analysis

作者 francis · GitHub ↗ · v0.2.0 · MIT-0
cross-platform ⚠ suspicious
61
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install hologres-slow-query-analysis
功能描述
Hologres slow query log analysis and diagnosis skill. Use for analyzing slow queries, failed queries, query performance diagnosis, and log management in Alib...
使用说明 (SKILL.md)

Prerequisites

This skill requires hologres-cli to be installed first:

pip install hologres-cli
export HOLOGRES_SKILL=hologres-slow-query-analysis

All SQL execution and GUC parameter operations depend on hologres-cli commands (hologres sql run, hologres guc set).

Hologres Slow Query Analysis

Diagnose and analyze slow/failed queries in Alibaba Cloud Hologres using the hologres.hg_query_log system table.

Version Requirements

Hologres Version Feature
V0.10+ Basic slow query log
V2.2+ SQL fingerprint (digest)
V2.2.7+ Default threshold 100ms
V3.0.2+ Aggregated records for \x3C100ms queries

Quick Start

1. Check Permissions

-- Superuser: view all DB logs
ALTER USER "cloud_account_id" SUPERUSER;

-- Or join pg_read_all_stats group
GRANT pg_read_all_stats TO "cloud_account_id";

-- For current DB only (SPM model)
CALL spm_grant('\x3Cdb_name>_admin', 'cloud_account_id');

2. Basic Query Count

SELECT count(*) FROM hologres.hg_query_log;

3. Recent Slow Queries (10 min)

SELECT status AS "Status",
       duration AS "Duration(ms)",
       query_start AS "Start Time",
       (read_bytes/1048576)::text || ' MB' AS "Read",
       (memory_bytes/1048576)::text || ' MB' AS "Memory",
       (cpu_time_ms/1000)::text || ' s' AS "CPU",
       query_id AS "QueryID",
       query::char(50) AS "Query"
FROM hologres.hg_query_log
WHERE query_start >= now() - interval '10 min'
ORDER BY duration DESC
LIMIT 100;

Core Diagnostic Workflows

Workflow 1: Find Resource-Heavy Queries

Use when CPU/memory usage is high.

-- Top 10 CPU-consuming queries (past day)
SELECT digest, avg(cpu_time_ms), sum(cpu_time_ms)
FROM hologres.hg_query_log
WHERE query_start >= CURRENT_DATE - INTERVAL '1 day'
  AND digest IS NOT NULL AND usename != 'system'
GROUP BY 1 ORDER BY 3 DESC LIMIT 10;

Workflow 2: Find Failed Queries

SELECT status, message::char(100), duration, query_start, query_id, query::char(80)
FROM hologres.hg_query_log
WHERE query_start BETWEEN '2024-01-01 00:00:00'::timestamptz 
      AND '2024-01-01 01:00:00'::timestamptz
  AND status = 'FAILED'
ORDER BY query_start ASC LIMIT 100;

Workflow 3: Query Phase Analysis

Identify bottleneck phase (optimization/startup/execution).

SELECT status, duration AS "Total(ms)",
       optimization_cost AS "Optimize(ms)",
       start_query_cost AS "Startup(ms)",
       get_next_cost AS "Execute(ms)",
       duration - optimization_cost - start_query_cost - get_next_cost AS "Other(ms)",
       query_id, query::char(50)
FROM hologres.hg_query_log
WHERE query_start >= now() - interval '10 min'
ORDER BY duration DESC LIMIT 100;

Workflow 4: Compare with Yesterday

SELECT query_date, count(1), sum(read_bytes), sum(cpu_time_ms)
FROM hologres.hg_query_log
WHERE query_start >= now() - interval '3 h'
GROUP BY query_date
UNION ALL
SELECT query_date, count(1), sum(read_bytes), sum(cpu_time_ms)
FROM hologres.hg_query_log
WHERE query_start >= now() - interval '1d 3h' AND query_start \x3C= now() - interval '1d'
GROUP BY query_date;

Key Fields Reference

Field Description
query_id Unique query identifier
digest SQL fingerprint (MD5 hash)
duration Total query time (ms)
cpu_time_ms CPU time consumed
memory_bytes Peak memory usage
read_bytes Data read volume
engine_type Query engine (HQE/PQE/SDK/PG)
optimization_cost Plan generation time
start_query_cost Query startup time
get_next_cost Execution time

Configuration

-- Set slow query threshold (DB level, superuser only)
ALTER DATABASE dbname SET log_min_duration_statement = '250ms';

-- Session level
SET log_min_duration_statement = '250ms';

-- Set log retention (V3.0.27+, 3-30 days)
ALTER DATABASE dbname SET hg_query_log_retention_time_sec = 2592000;

Or use the CLI for database-level settings:

hologres guc set log_min_duration_statement '250ms'
hologres guc set hg_query_log_retention_time_sec 2592000

References

Document Content
diagnostic-queries.md Complete diagnostic SQL collection
log-export.md Export logs to internal/external tables
configuration.md Configuration parameters

Best Practices

  1. Always filter by query_start for better performance
  2. Use digest to group similar queries for pattern analysis
  3. Check engine_type - PQE queries may need optimization
  4. For start_query_cost high: check locks or resource contention
  5. For get_next_cost high: optimize SQL or add indexes
  6. Regular cleanup: set appropriate retention period
安全使用建议
Install only if you are comfortable using it as a DBA-oriented Hologres operations guide. Do not let an agent grant SUPERUSER, alter database logging, change retention, or export logs unless you have explicitly approved the exact command, scope, destination, and rollback plan.
功能分析
Type: OpenClaw Skill Name: hologres-slow-query-analysis Version: 0.2.0 The skill provides diagnostic workflows for Alibaba Cloud Hologres but requires high-risk actions such as 'pip install' for a CLI tool and granting SUPERUSER privileges (SKILL.md). It facilitates shell command execution and broad administrative database access, which are plausibly needed for the stated purpose but represent a significant attack surface and elevated risk profile according to the defined criteria.
能力评估
Purpose & Capability
Read-only slow-query analysis is purpose-aligned, but the skill also includes SUPERUSER grants, all-instance log access, database-level configuration changes, retention changes, and log export workflows.
Instruction Scope
High-impact SQL and CLI examples are visible, but the instructions do not clearly require explicit approval, least-privilege selection, rollback, or revocation before running administrative commands.
Install Mechanism
The skill is instruction-only with no reviewed code or install spec, but it asks the user to install an unpinned external CLI package even though registry requirements list no required binary.
Credentials
Accessing Hologres query logs is expected for the stated purpose, but those logs can include SQL text, users, client addresses, query plans, and other sensitive operational data.
Persistence & Privilege
The suggested SUPERUSER/role grants and ALTER DATABASE/GUC settings can persist after the analysis task, and retention changes may affect log availability.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install hologres-slow-query-analysis
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /hologres-slow-query-analysis 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v0.2.0
- Added detailed usage instructions and workflows for diagnosing slow and failed queries in Hologres. - Described required prerequisites, permissions, and version requirements. - Introduced core diagnostic workflows, including resource-heavy query analysis, failure detection, and query phase bottleneck breakdowns. - Documented key fields, configuration guides (both SQL and CLI usage), and provided quick-start query examples. - Included best practices and links to further references.
元数据
Slug hologres-slow-query-analysis
版本 0.2.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

Hologres Slow Query Analysis 是什么?

Hologres slow query log analysis and diagnosis skill. Use for analyzing slow queries, failed queries, query performance diagnosis, and log management in Alib... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 61 次。

如何安装 Hologres Slow Query Analysis?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install hologres-slow-query-analysis」即可一键安装,无需额外配置。

Hologres Slow Query Analysis 是免费的吗?

是的,Hologres Slow Query Analysis 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Hologres Slow Query Analysis 支持哪些平台?

Hologres Slow Query Analysis 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Hologres Slow Query Analysis?

由 francis(@wenbingyu)开发并维护,当前版本 v0.2.0。

💬 留言讨论