Datastoria clickhouse-system-queries
install
source · Clone the upstream repo
git clone https://github.com/FrankChen021/datastoria
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/FrankChen021/datastoria "$T" && mkdir -p ~/.claude/skills && cp -r "$T/resources/skills/clickhouse-system-queries" ~/.claude/skills/frankchen021-datastoria-clickhouse-system-queries && rm -rf "$T"
manifest:
resources/skills/clickhouse-system-queries/SKILL.mdsource content
ClickHouse System Queries Skill
Use this skill when the user asks for operational inspection on ClickHouse
system.* tables.
Current table coverage:
viasystem.query_logreferences/system-query-log.md
Relationship to
sql-expert:
handles general SQL generation and user/business tables.sql-expert- This skill handles system-table operational patterns and routing to table-specific references.
System Metrics and ProfileEvents
- Confirm column shape from schema/reference before writing predicates.
- If the user named an exact metric, pass it in the
list viacolumns
instead of loading the full table schema.explore_schema - If
is aProfileEvents
, access entries asMap
. If flattened, useProfileEvents['Name']
.ProfileEvent_Name
Example — map vs flattened access:
-- Map access SELECT ProfileEvents['DistributedConnectionFailTry'] AS fails FROM system.query_log WHERE event_date = today(); -- Flattened column access SELECT ProfileEvent_DistributedConnectionFailTry AS fails FROM system.query_log WHERE event_date = today();
Workflow
-
Resolve target — identify system table and intent. Inherit the most recent time window from conversation, or default to last 60 minutes.
-
Load reference — for
, callsystem.query_log
to loadskill_resource
before writing any SQL. For unsupported tables, fall back toreferences/system-query-log.md
.sql-expert -
Execute — choose the right tool:
for standard ranked searches and filtered lookupssearch_query_log
for visualization, time-bucketed aggregation, trends, or histogramsexecute_sql
-- search_query_log: standard lookup -- finds top 10 slowest queries in the last hour -- execute_sql: time-bucketed visualization SELECT toStartOfFiveMinutes(event_time) AS bucket, count() AS queries, avg(query_duration_ms) AS avg_ms FROM system.query_log WHERE event_date = today() AND event_time > now() - INTERVAL 1 HOUR GROUP BY bucket ORDER BY bucketDefault to
unless the user specifies otherwise.LIMIT 50 -
Summarize with concise findings and next actions.
Guardrails
- Always apply time bounds for log-like system tables
- Always use the table-specific reference when available
- Never generate
SQL untilsystem.query_log
is loaded in the current turnreferences/system-query-log.md - Never use
for chart-oriented requestssearch_query_log - Never omit
in exploratory queriesLIMIT