Overview
ClickHouse exposes its state through the system database: query history, parts, merges, mutations, replication queues, metrics, errors and logs. Most day-to-day operations are SQL against these tables.
Core concepts
| Question | System table |
|---|---|
| What ran, how long, how many rows/bytes read, how much memory? | system.query_log (needs SYSTEM FLUSH LOGS to see recent rows), system.processes for running queries |
| Tables, parts, sizes, active vs inactive | system.parts, system.columns, system.tables |
| Background work | system.merges, system.mutations, system.part_log, system.replication_queue |
| Replication health | system.replicas (absolute_delay, queue_size, is_readonly) |
| Live counters | system.metrics, system.events, system.asynchronous_metrics, system.metric_log |
| Errors and logs | system.errors, system.text_log, system.trace_log |
| Dictionaries, backups | system.dictionaries, system.backups |
- Limits and quotas via settings profiles and users:
max_memory_usage,max_execution_time,max_threads,max_concurrent_queries, row and result limits. In the test containermax_memory_usagewas0(unlimited); do not run production like that. - Kill a query with
KILL QUERY WHERE query_id = '...'; stop merges for maintenance withSYSTEM STOP MERGES t. - Metrics export: the built-in Prometheus endpoint (
<prometheus>config) and Grafana dashboards; alert on parts per partition, merge backlog, replication delay, readonly replicas, disk free, memory, query errors. - Upgrades: choose LTS releases for production where you need long support, test on staging with replayed queries, upgrade replicas one by one. The tests here ran on the
latestimage (26.10.4).
Worked example
Quick health queries (executed on the test server):
SELECT metric, value FROM system.metrics WHERE metric IN ('Query','MemoryTracking','PartsActive');
-- MemoryTracking ~400 MB, PartsActive 119, Query 1
SELECT table, count() AS parts, sum(rows) AS rows, formatReadableSize(sum(bytes_on_disk)) AS size
FROM system.parts WHERE active GROUP BY table ORDER BY sum(bytes_on_disk) DESC;
SELECT log_comment, read_rows, formatReadableSize(read_bytes) AS bytes, query_duration_ms
FROM system.query_log WHERE type = 'QueryFinish' AND event_time > now() - INTERVAL 1 HOUR
ORDER BY query_duration_ms DESC LIMIT 10;Replication lag:
SELECT table, is_readonly, absolute_delay, queue_size, inserts_in_queue FROM system.replicas;Pitfalls and production notes
system.*_logtables grow; set TTL and retention (they have default TTLs, but check).- Memory-heavy
GROUP BY/JOINqueries are the usual cause of OOM; enforce limits and review the top consumers. - Disk space must allow for merges; alert early.
- Run production with 3 Keeper nodes, at least 2 replicas per shard, backups, and tested restores (ch-replication-keeper, ch-backup-restore).
- Compare with monitoring views of other engines (pg-monitoring, sqlserver-monitoring-dmvs, oracle-awr-ash).
Practice questions
- Where do you check whether merges keep up with inserts?
- Which table shows slow queries after the fact?
- Which limits should every production profile define?
References
- ClickHouse documentation, System tables; Monitoring; Settings profiles
Related
ch-mergetree-parts · ch-replication-keeper · ch-query-optimization · pg-monitoring