System tables overview
System tables provide information about:- Server states, processes, and environment.
- Server’s internal processes.
- Options used when the ClickHouse binary was built.
- Located in the
systemdatabase. - Available only for reading data.
- Can’t be dropped or altered, but can be detached.
/etc/clickhouse-server/config.d/, or setting corresponding elements in /etc/clickhouse-server/config.xml. Elements can be customized are:
database: database the system log table belongs to. This option is deprecated now. All system log tables are under databasesystem.table: table to insert data.partition_by: specify PARTITION BY expression.ttl: specify table TTL expression.flush_interval_milliseconds: interval of flushing data to disk.engine: provide full engine expression (starting withENGINE =) with parameters. This option conflicts withpartition_byandttl. If set together, the server will raise an exception and exit.
MergeTree-engine tables.
Sources of System Metrics
For collecting system metrics ClickHouse server uses:CAP_NET_ADMINcapability.- procfs (only in Linux).
CAP_NET_ADMIN capability, it tries to fall back to ProcfsMetricsProvider. ProcfsMetricsProvider allows collecting per-query system metrics (for CPU and I/O).
If procfs is supported and enabled on the system, ClickHouse server collects these metrics:
OSCPUVirtualTimeMicrosecondsOSCPUWaitMicrosecondsOSIOWaitMicrosecondsOSReadCharsOSWriteCharsOSReadBytesOSWriteBytes
OSIOWaitMicroseconds is disabled by default in Linux kernels starting from 5.14.x.
You can enable it using sudo sysctl kernel.task_delayacct=1 or by creating a .conf file in /etc/sysctl.d/ with kernel.task_delayacct = 1System tables in ClickHouse Cloud
In ClickHouse Cloud, system tables provide critical insights into the state and performance of the service, just as they do in self-managed deployments. Some system tables operate at the cluster-wide level, especially those that derive their data from Keeper nodes, which manage distributed metadata. These tables reflect the collective state of the cluster and should be consistent when queried on individual nodes. For example, theparts should be consistent irrespective of the node it is queried from:
- System tables with a
_logsuffix. - System tables that expose metrics e.g.
metrics,asynchronous_metrics,events. - System tables that expose ongoing processes e.g.
processes,merges.
system.query_log tables, which contain a row for each query executed by the node:
Querying multiple versions
We can query across these tables using themerge function. For example, the query below identifies the latest query issued to the target node in each query_log table:
Don’t rely on the numerical suffix for orderingWhile the numeric suffix on tables can suggest the order of data, it should never be relied upon. For this reason, always use the merge table function combined with a date filter when targeting specific date ranges.
Querying across nodes
To comprehensively view the entire cluster, users can leverage theclusterAllReplicas function in combination with the merge function. The clusterAllReplicas function allows querying system tables across all replicas within the “default” cluster, consolidating node-specific data into a unified result. When combined with the merge function this can be used to target all system data for a specific table in a cluster.
This approach is particularly valuable for monitoring and debugging cluster-wide operations, ensuring users can effectively analyze the health and performance of their ClickHouse Cloud deployment.
ClickHouse Cloud provides clusters of multiple replicas for redundancy and failover. This enables its features, such as dynamic autoscaling and zero-downtime upgrades. At a certain moment in time, new nodes could be in the process of being added to the cluster or removed from the cluster. To skip these nodes, add
SETTINGS skip_unavailable_shards = 1 to queries using clusterAllReplicas as shown below.query_log table - often essential to analysis.
Querying across nodes and versions
Due to system table versioning this still does not represent the full data in the cluster. When combining the above with themerge function we get an accurate result for our date range: