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

QuestionSystem 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 inactivesystem.parts, system.columns, system.tables
Background worksystem.merges, system.mutations, system.part_log, system.replication_queue
Replication healthsystem.replicas (absolute_delay, queue_size, is_readonly)
Live counterssystem.metrics, system.events, system.asynchronous_metrics, system.metric_log
Errors and logssystem.errors, system.text_log, system.trace_log
Dictionaries, backupssystem.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 container max_memory_usage was 0 (unlimited); do not run production like that.
  • Kill a query with KILL QUERY WHERE query_id = '...'; stop merges for maintenance with SYSTEM 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 latest image (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.*_log tables grow; set TTL and retention (they have default TTLs, but check).
  • Memory-heavy GROUP BY/JOIN queries 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

  1. Where do you check whether merges keep up with inserts?
  2. Which table shows slow queries after the fact?
  3. Which limits should every production profile define?

References

  • ClickHouse documentation, System tables; Monitoring; Settings profiles

ch-mergetree-parts · ch-replication-keeper · ch-query-optimization · pg-monitoring