altinity-expert-clickhouse-connection
Connection mode
Decide connection mode first and verify connectivity then:
select
hostName() as hostname,
version() as version,
getMacro('cluster') as cluster_name,
formatReadableTimeDelta(uptime()) as uptime_human,
getSetting('max_memory_usage') as max_memory_usage,
(select value from system.asynchronous_metrics where metric = 'OSMemoryTotal') as os_memory_total
MCP mode
Try to use MCP server with clickhouse in the name. If multiple ClickHouse MCP servers are available, ask the user which one to use. When executing queries by the MCP server, push a single SQL statement to the MCP server (no multy query!)
Exec mode (clickhouse-client)
- if MCP is unavailable, try to run
clickhouse-client. Don't rely on env vars. On failure, ask how to run it properly. - Prefer running queries from a
.sqlfile with--queries-fileand forcing JSON output (-f JSON) when capturing results to files.
Cluster selection for clusterAllReplicas('{cluster}', ...)
- Verify from the query results above if a cluster_name (cluster macro var) is not empty. If defined - leave macro as-is.
- if not, ask the user to choose from:
SELECT DISTINCT cluster FROM system.clusters where not is_localand replace'{cluster}'placeholders in the queries in all.sqlfiles. - if the query above returns nothing, consider single-server mode and automatically rewrite
clusterAllReplicas('{cluster}', system.<table>)→system.<table>before execution.
Timeframe default for logs/errors
- If the user explicitly provides a timeframe in the initial prompt, use it exactly.
- Otherwise always default to last 24 hours:
-- Use this pattern for system.*_log tables and system.errors time filters:
-- WHERE event_time >= now() - INTERVAL 24 HOUR
- never expend time window without an explicit user prompt. If needed, ask user to extend time window
Schema-safe rule
- If a query fails with
UNKNOWN_IDENTIFIER, runDESCRIBE TABLE system.<table>and drop/adjust only the missing columns. - If a query fails with
UNKNOWN_TABLE, skip that query and note the table is disabled or unavailable (e.g.,system.part_log,system.detached_parts).
Report Output
In all reports, always provide a header with information:
- Connection mode used: MCP or clickhouse-client
- cluster name (or “no cluster / single node”)
- clickhouse version
- time window used for analysis
More from altinity/skills
altinity-expert-clickhouse-ingestion
Diagnose ClickHouse INSERT performance, batch sizing, part creation patterns, and ingestion bottlenecks. Use for slow inserts and data pipeline issues.
56altinity-expert-clickhouse-merges
Diagnose ClickHouse merge performance, part backlog, and 'too many parts' errors. Use for merge issues and part management problems.
53altinity-expert-clickhouse-mutations
Track and diagnose ClickHouse ALTER UPDATE, ALTER DELETE, and other mutation operations. Use for stuck mutations and mutation performance issues.
53altinity-expert-clickhouse-storage
Diagnose ClickHouse disk usage, compression efficiency, part sizes, and storage bottlenecks. Use for disk space issues and slow IO.
52altinity-expert-clickhouse-index-analysis
Analyze whether ClickHouse indexes (PRIMARY KEY, ORDER BY, skipping indexes, projections) are being used effectively for actual query patterns. Use when investigating index effectiveness, ORDER BY key design, query-to-index alignment, or when queries scan more data than expected.
48altinity-expert-clickhouse-kafka
Diagnose ClickHouse Kafka engine health, consumer status, thread pool capacity, and consumption issues. Use for Kafka lag, consumer errors, and thread starvation.
31