
ClickHouse Query
FreeRun ClickHouse queries for analytics and metrics analysis.
Free · Opens the source repo
What ClickHouse Query does
The ClickHouse Query skill is designed for developers and data analysts who need to execute queries directly against a ClickHouse database. This skill allows users to run ad-hoc queries for analytics, metrics analysis, and event data exploration. It provides a straightforward command-line interface to interact with ClickHouse, making it easy to analyze data and debug queries without needing to set up a separate environment.
To use the skill, simply invoke the included query.mjs script with your SQL command. The skill supports various options, such as specifying a timeout for queries, reading queries from a file, and outputting results in JSON format. This flexibility allows users to tailor their queries to specific needs, whether they are counting rows, filtering data, or checking the execution plan of a query.
Safety features are built into the skill to prevent unintended data modifications. By default, it operates in read-only mode, requiring explicit permission to perform write operations. Additionally, it has a default timeout of 30 seconds to avoid long-running queries, which can be adjusted as needed. This makes it suitable for both exploratory data analysis and performance testing.
Overall, the ClickHouse Query skill is an essential tool for anyone working with ClickHouse who needs to perform quick queries and analysis on their data, ensuring both safety and efficiency in data handling.
When to use it
Use this skill when you need to run queries on ClickHouse for analytics, metrics, or debugging purposes.
When not to use it
This skill is not suitable for applications requiring frequent write operations unless explicit permission is granted.
What you can build with it
Count Rows in a Table
Quickly count the number of rows in a ClickHouse table to get a sense of data volume.
Analyze Event Tracking Data
Run queries to filter and analyze event data, such as user interactions or model events.
Check Query Performance
Use the `--explain` flag to analyze the execution plan of your queries for optimization.
How to install ClickHouse Query
View source1. Install with the skills CLI
npx skills add civitai/civitai/clickhouse-query --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by civitaiClickHouse Query Testing
Use this skill to run ad-hoc ClickHouse queries for analytics, metrics analysis, and debugging.
Running Queries
Use the included query script:
node .claude/skills/clickhouse-query/query.mjs "SELECT count() FROM views"
Options
| Flag | Description |
|---|---|
--explain | Show query execution plan |
--writable | Allow write operations (requires user permission) |
--timeout <s>, -t | Query timeout in seconds (default: 30) |
--file, -f | Read query from a file |
--json | Output results as JSON |
--quiet, -q | Minimal output, only results |
Examples
# Count rows in a table
node .claude/skills/clickhouse-query/query.mjs "SELECT count() FROM views"
# Query with filters
node .claude/skills/clickhouse-query/query.mjs "SELECT * FROM modelEvents WHERE modelId = 123 LIMIT 10"
# Check query execution plan
node .claude/skills/clickhouse-query/query.mjs --explain "SELECT * FROM views WHERE userId = 1"
# Override default 30s timeout for longer queries
node .claude/skills/clickhouse-query/query.mjs --timeout 60 "SELECT ... (complex aggregation)"
# Query from file
node .claude/skills/clickhouse-query/query.mjs -f my-query.sql
# JSON output for processing
node .claude/skills/clickhouse-query/query.mjs --json "SELECT type, count() FROM modelEvents GROUP BY type"
Safety Features
- Read-only by default: Blocks INSERT/ALTER/DROP unless
--writableflag is used - 30 second timeout: Prevents runaway queries (override with
--timeout) - Explicit permission required: Before using
--writable, you MUST ask the user for permission
When to Use --writable
Only use the --writable flag when:
- The user explicitly requests write access
- You need to insert test data
- You're running maintenance operations
IMPORTANT: Always ask the user for permission before running with --writable.
Common Tables
| Table | Description |
|---|---|
views | Page/entity view events |
modelEvents | Model create/publish/update events |
modelVersionEvents | Model version events including downloads |
userActivities | User registration, login, subscription events |
images | Image upload/delete events |
reactions | Like/dislike events |
reports | Content report events |
entityMetricEvents | Aggregated metric events |
Querying Replica Clusters
IMPORTANT: Production uses a ClickHouse replica cluster. When querying system tables (logs, metrics, etc.), you must use clusterAllReplicas() to get data from all nodes.
System Tables on Replica Clusters
-- WRONG: Only queries the node you're connected to
SELECT * FROM system.query_log WHERE event_time > now() - INTERVAL 1 HOUR
-- CORRECT: Queries all replicas in the cluster
SELECT * FROM clusterAllReplicas(default, system.query_log)
WHERE event_time > now() - INTERVAL 1 HOUR
Common System Table Queries
-- Find recent queries across all nodes
SELECT
hostname(),
event_time,
query_duration_ms,
formatReadableSize(memory_usage) AS memory,
query
FROM clusterAllReplicas(default, system.query_log)
WHERE type = 'QueryFinish'
AND event_time > now() - INTERVAL 5 MINUTE
ORDER BY event_time DESC
LIMIT 20
-- Find expensive queries by memory usage (last 24 hours)
SELECT
count() as query_count,
user,
sum(memory_usage) AS total_memory,
normalized_query_hash
FROM clusterAllReplicas(default, system.query_log)
WHERE event_time > now() - INTERVAL 1 DAY
AND query_kind = 'Select'
AND type = 'QueryFinish'
GROUP BY normalized_query_hash, user
ORDER BY total_memory DESC
LIMIT 10
-- Search query logs by pattern
SELECT event_time, query_id, query, type
FROM clusterAllReplicas(default, merge('system', '^query_log*'))
WHERE query ILIKE '%some_table%'
AND event_time > now() - INTERVAL 5 MINUTE
-- Debug a specific query across all nodes
SELECT hostname(), message
FROM clusterAllReplicas(default, system.text_log)
WHERE query_id = 'your-query-id-here'
ORDER BY event_time_microseconds ASC
When to Use clusterAllReplicas()
| Use Case | Function |
|---|---|
| System tables (query_log, text_log, etc.) | clusterAllReplicas(default, system.table_name) |
| Application tables (views, modelEvents, etc.) | Direct query (already distributed) |
| Search multiple system tables | clusterAllReplicas(default, merge('system', '^pattern*')) |
ClickHouse SQL Tips
-- Use count() not COUNT(*)
SELECT count() FROM views
-- Date filtering with toDate()
SELECT * FROM views WHERE toDate(time) = today()
-- Last 7 days
SELECT * FROM modelEvents WHERE time > now() - INTERVAL 7 DAY
-- Aggregations
SELECT type, count() as cnt FROM modelEvents GROUP BY type ORDER BY cnt DESC
Frequently asked questions about ClickHouse Query
Similar skills
Create Data Lake Tables
Efficiently manage Iceberg tables on Amazon S3.
OneKGPd
Query individual-level data from the 1000 Genomes Project.
Database Lookup
Retrieve data from public APIs with precision and reproducibility.
BigQuery Basics
Manage datasets and run queries in BigQuery easily.
Query Data Lake
Efficiently execute SQL queries on Amazon Athena.
Find Data Lake Assets
Quickly resolve data lake asset references across AWS services.
