Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

ClickHouse 13 min read How-to mediumAdept

System Tables and a Window into the Internals of ClickHouse

ClickHouse system tables are read-only virtual tables in the system database that expose server state, settings, metrics, errors, parts and query history. Most live in memory, while log tables such as query_log, part_log and metric_log persist on MergeTree storage. A set of practical diagnostic queries shows how to use them: system.settings for non-default values, query_log with normalizedQueryHash and ProfileEvents for slow, memory-heavy and failed queries, system.errors for frequent error codes with traces, and part_log to confirm inserts are producing parts. These queries can serve as a starting toolkit for troubleshooting and understanding cluster usage.

Related posts

  • Common issues you can solve using advanced monitoring dashboards

    ClickHouse mediumAdept

    ClickHouse ships a built-in Advanced Dashboard at /dashboard that charts query, MergeTree, OS and S3/cache metrics. Its panels are SQL queries over system.metric_log and system.asynchronous_metric_log. Setup means enabling those logs on self-hosted servers and creating a dashboard user with SELECT on the system tables plus REMOTE and CREATE TEMPORARY TABLE grants. Custom charts can be persisted in a separate dashboards table and merged with the defaults. Example diagnoses: unbatched inserts show as Max Parts for Partition spiking while Inserted Rows/sec stays low, and a Selected Rows/sec spike traced through system.query_log reveals a poor primary key (151M vs 6M rows read for the same query).

  • Essential Monitoring Queries - part 2 - SELECT Queries

    ClickHouse mediumAdept

    A set of SQL queries against ClickHouse system tables (system.parts, system.query_log, system.processes, system.stack_trace) for monitoring and troubleshooting SELECT workloads: cluster size overview, most expensive queries, ProfileEvents diffs between two query versions, hourly duration trends, per-client query counts, and diagnosing TOO_MANY_SIMULTANEOUS_QUERIES. Setting send_logs_level = 'trace' in clickhouse-client exposes per-query execution logs; in the UK price paid example, adding a projection ordered by town and price cut marks read from 3401 to 266 and latency from 1.2s to 0.028s. Queries use clusterAllReplicas for ClickHouse Cloud and can be adapted for self-managed clusters.

  • A simple guide to ClickHouse query optimization: part 1

    ClickHouse mediumAdept

    Slow ClickHouse queries can be diagnosed with system.query_log (duration, rows read, memory, CPU, cache metrics) and the EXPLAIN statement, illustrated on the NYC Taxi dataset in the ClickHouse Playground. A table created with an inferred schema (all Nullable columns, empty ORDER BY) forces every example query into a full scan of 329 million rows taking over a second and roughly 400–550 MiB of memory. Turning off the filesystem cache makes timings reproducible. The first part of the series then moves to basic optimizations and choosing primary keys so ClickHouse can skip data instead of scanning it.

  • ClickHouse and OpenTelemetry

    ClickHouse mediumAdept

    ClickHouse now officially supports the OpenTelemetry Collector exporter for ClickHouse, which has reached beta for logs and traces. The exporter ships a "one size fits most" default schema. For production, ClickHouse recommends disabling automatic table creation, because concurrent exporters race to create tables, and defining your own tables or materialized views keyed to your query patterns. The LogHouse schema behind ClickHouse's 43 PB internal logging platform serves as the worked example. It orders by (PodName, Timestamp), uses LowCardinality for string columns under about 10k distinct values, applies ZSTD(1) because data lives on S3, and puts Bloom-filter indexes on map keys and values, which are not yet tuned.

  • Essential Monitoring Queries - part 1 - INSERT Queries

    ClickHouse mediumAdept

    ClickHouse system tables such as part_log, query_log, asynchronous_insert_log, asynchronous_metric_log and parts can be queried with SQL to monitor and troubleshoot INSERT workloads. Ready-to-use queries cover new part creation rate, bulk insert counts versus rows written, insert duration percentiles, per-insert memory and CPU, MaxPartCountForPartition, parts per partition, and part-level errors. Comparing insert request counts to rows written, or watching part counts climb, gives early warning of small-insert patterns and high-cardinality partition keys that lead to 'Too many parts' errors. Duration and resource metrics are only accurate for synchronous inserts, not async_insert or the Buffer engine, and alerting on these queries through tools like Grafana is recommended.

The quest for software engineering knowledge.

Look:
Layout: