Skip to main content
These queries read the system tables of the server you are connected to and look at the last hour or the last day; adjust the intervals to your needs. To cover every server of a cluster, see Run the queries on all servers of a cluster. For queries that inspect tables, parts and running queries, see Useful queries for troubleshooting. The log tables used here (system.query_log, system.metric_log, system.part_log, system.text_log, system.asynchronous_metric_log) are enabled in the default server configuration. They are sorted by event_date first (system.asynchronous_metric_log by metric first), which is why the queries filter on event_date in addition to event_time: the server then reads only the recent data.

Server start time

An unexpectedly small uptime means that the server was restarted. For the history of starts, search the server log in system.text_log:
The server writes Starting ClickHouse followed by its version, revision and build identifier when it starts. Every row is one start of the server, so two rows close to each other mean a restart. The last messages before a stop are not a reliable marker: a server that is terminated abruptly does not write them.

Failed queries by error

A query that fails is written to system.query_log with the type ExceptionBeforeStart or ExceptionWhileProcessing:
Example output from a test instance:
normalized_query_hash is the same for queries that differ only in literal values, so query_patterns tells you whether one statement fails repeatedly or many different ones fail. The query log is a better source for alerts than the counters of system.errors, which also count exceptions that the server handled internally: see Why does system.errors show errors for queries that succeeded?.

Queries that exceeded the memory limit

Error code 241 is MEMORY_LIMIT_EXCEEDED. This query groups such failures by hour and by query pattern and returns one query_id per group to look at:
Replace 241 with another code to track a different error, for example 202 for TOO_MANY_SIMULTANEOUS_QUERIES. See Memory limit exceeded for query for what to do about the error itself.

Peak CPU usage

system.metric_log stores, for every collection interval, how much each profile event grew. The interval is collect_interval_milliseconds in the metric_log section of the server configuration, 1000 (one second) by default. OSCPUVirtualTimeMicroseconds is the CPU time used by the server, so dividing it by the length of the interval in microseconds gives the number of CPU cores that were busy during the interval:
Compare peak_cpu_cores with the number of cores available to the server. If your server collects the metrics at another interval, change the first line of the query: with the wrong value the result is off by the ratio of the two intervals, for example twice too high for a two-second interval.

CPU wait

OSCPUWaitMicroseconds is the time that threads were ready to run but waited for a CPU core. Collection intervals in which the threads of the server waited, in total, for longer than the interval lasts (more than one second with the default interval) indicate that the server had more work than cores:

Memory tracked by the server

MemoryTracking is the total amount of memory tracked by the server.

Memory used compared with the memory available

system.asynchronous_metric_log keeps the history of the metrics that the server calculates periodically. MemoryResident is the physical memory used by the server process. CGroupMemoryTotal is the memory limit of the cgroup (container) the server runs in, and is zero or absent when there is no such limit, in which case OSMemoryTotal, the memory of the host, applies:

Load average

LoadAverage15 is the load of the whole host averaged over 15 minutes; LoadAverage1 and LoadAverage5 are also available:

Failed merges and mutations

Every merge and every mutation of a part is recorded in system.part_log. A non-zero error is the code of the exception that stopped it:
Background operations are retried, so one cause can produce many rows. For a mutation that keeps failing, see How to find the oldest unfinished mutation and kill stuck mutations.

Run the queries on all servers of a cluster

Each server has its own system tables. To query all of them at once, wrap the table in clusterAllReplicas and add hostName() to the result. In ClickHouse Cloud the cluster is named default; on a self-managed cluster use the name from system.clusters: