ClickHouse cheatsheet
Client and HTTP
| Command | Description |
|---|---|
clickhouse-client | Interactive SQL shell (port 9000) |
clickhouse-client -q 'SELECT 1' | Run single query |
clickhouse-client -h host -u user --password | Connect to remote server |
curl 'http://127.0.0.1:8123/ping' | HTTP health check |
curl 'http://127.0.0.1:8123/?query=SELECT+1' | HTTP query |
Service and logs
| Command | Description |
|---|---|
systemctl status clickhouse-server | Service status |
systemctl restart clickhouse-server | Restart server |
tail -f /var/log/clickhouse-server/clickhouse-server.log | Follow server log |
ss -tlnp | grep -E '8123|9000' | Check listeners |
Schema inspection
| Query | Description |
|---|---|
SHOW DATABASES | List databases |
SHOW TABLES FROM db | List tables |
DESCRIBE TABLE db.table | Column definitions |
SHOW CREATE TABLE db.table | DDL statement |
System table queries
-- Parts and size per table
SELECT database, table, count() AS parts, sum(bytes_on_disk) AS bytes
FROM system.parts WHERE active GROUP BY database, table ORDER BY bytes DESC;
-- Running queries
SELECT query_id, user, elapsed, memory_usage, query FROM system.processes;
-- Recent slow queries
SELECT type, query_duration_ms, memory_usage, query
FROM system.query_log
WHERE event_time > now() - INTERVAL 1 HOUR AND type = 'QueryFinish'
ORDER BY query_duration_ms DESC LIMIT 10;
-- Replication status
SELECT database, table, is_readonly, queue_size, absolute_delay
FROM system.replicas;
Operational commands
| Query / command | Description |
|---|---|
KILL QUERY WHERE query_id = '...' | Cancel a running query |
OPTIMIZE TABLE db.table FINAL | Force merge (use carefully) |
SYSTEM FLUSH LOGS | Flush log tables to disk |
du -sh /var/lib/clickhouse/* | Disk usage by database |
Pro tips
- Check
system.partswhen inserts slow down — too many parts is a common cause - Use
system.processesto find queries consuming memory before OOM kills - Batch inserts (thousands of rows per INSERT) — avoid one-row inserts at high rate
- Read the server log for "Memory limit exceeded" and "Too many parts" messages
Practice scenarios
Hands-on ClickHouse scenarios on live Linux VMs: clickhouse