
Sangeeta Shivaji Rao

Mike Peralta
ClickHouse is widely used for large-scale analytics, but once it is running in production, it can be difficult to understand how query activity translates into resource usage. Engineers investigating performance issues often struggle to determine which queries consume the most memory, run most frequently, or cause spikes in load. In practice, engineers are left querying system.query_log, tailing server logs, and piecing together information after an incident. While this can show what queries are running at a given moment, it does not provide a consistent way to compare queries across a cluster. It also does not reveal the overall impact of a query or show what it actually costs once it is finished.
Maintaining storage health is another challenge. ClickHouse writes every insert as a new data part and merges parts in the background. When ingestion outpaces merges, parts pile up, queries slow down, and inserts can eventually be rejected with “Too many parts” errors. Spotting this early usually means polling several system tables by hand.
Datadog Database Monitoring for ClickHouse provides a unified view of query performance and storage health across both ClickHouse Cloud and self-hosted deployments. It collects aggregated query metrics and execution samples, captures explain plans and query errors, and tracks parts, merges, mutations, and replication in one place, so that teams can identify inefficient queries, investigate incidents, and keep ingestion healthy.
In this post, we’ll cover how Database Monitoring for ClickHouse helps you:
Find your most expensive queries
Understanding query performance at scale requires more than reviewing individual slow queries. Engineers need to compare patterns across the cluster, including how often queries run, how long they take, and how much data they process. Without this context, teams might focus on outliers and miss the queries that drive most resource usage, such as queries that run thousands of times per hour.
Database Monitoring collects aggregated metrics for each normalized query pattern in your ClickHouse environment. This helps engineers evaluate queries by overall impact, not just latency. For example, a moderately slow query that runs frequently can have a greater effect than a single long-running query.
These metrics include execution count within a collection window, total and average duration, memory usage, and I/O activity such as rows and bytes read or written. They also include result set size, which helps teams understand how much data queries return to clients. With this data, teams can identify which query patterns drive the highest cost and prioritize optimization work.
Database Monitoring for ClickHouse brings all this together in one place, as shown in the preceding screen capture. The stacked bar charts break down sessions over time by query pattern. You can scan for spikes in load and hover over individual bars to see which query patterns were active at that moment, making it easy to correlate load spikes with specific queries. Other tables rank query patterns by their current impact.
Together, these views let you move beyond “which query is slowest” to “which query costs the most overall,” whether that’s a high-frequency moderate query or a low-frequency heavy one. The Query Metrics view lets you rank queries by the metric that actually matters: the total impact on the system. This way, you can optimize the right queries first, not just the most frequent or the slowest ones.
Reconstruct what happened during an incident
When performance issues occur, aggregated metrics are not enough. Engineers also need to understand the resource profile of each query execution—specifically, how individual queries performed at a specific point in time. To construct this profile, teams might resort to querying system.query_log across each node in the cluster, filtering through large volumes of entries, and correlating timestamps. On busy clusters, retention settings may even remove the data needed to perform a full investigation.
Database Monitoring captures query completion events, including those for short-lived queries, and retains a limited set of execution samples for each normalized query pattern. This history is stored independently of ClickHouse logs. Teams can view these samples across multiple instances and clusters in a single place, which makes it easier to investigate issues that span distributed environments.
Each query sample includes detailed execution context, including query text (with sensitive values hidden), execution duration, CPU and memory usage, and data read and written. It also includes result set size and metadata such as query ID, user, database, tables accessed, and query type. All this context gives teams a clear picture of how queries interact with the entire system.

With this data, engineers can also reconstruct incidents after they occur. They can identify which queries caused spikes in memory usage, determine whether workload changes contributed to degraded performance, and trace issues to specific users or services. Because Datadog retains this data, teams are not limited by ClickHouse log retention settings.
To investigate why a query was slow, engineers can examine the explain plans collected by Database Monitoring alongside execution metrics. Schema telemetry provides additional context on table structure, helping teams understand how sorting keys and partitioning choices may contribute to query performance. Database Monitoring also captures query errors alongside execution samples, so teams can identify which query patterns are failing, how often failures occur, and which errors are returned.

Database Investigations in Bits Chat helps teams connect this information during an investigation. It automatically correlates query samples, explain plans, workload metrics, and logs across your stack to identify likely causes and recommend steps to address them. Links to supporting evidence and live graphs help engineers evaluate the recommendations and assess whether a change improves performance.

Maintain reliable ingestion and storage health
Background operations also affect ClickHouse performance. Frequent small inserts can increase the number of parts that need to be merged, while stalled mutations and replication delays can contribute to degraded cluster health. Engineers need visibility into these operations to understand whether they are keeping pace with the workload.
Database Monitoring brings data on active and detached parts, merges, mutations, and replication queues together in a single Storage Health timeline. Teams can track rising part counts, identify merges that are not progressing, investigate failed mutations, and monitor replication backlogs and lag. This helps engineers identify ingestion and storage issues before they lead to query slowdowns or rejected inserts.

For workloads that use asynchronous inserts, Database Monitoring also shows how ClickHouse batches incoming data and flushes it to storage. Engineers can use this information to evaluate their asynchronous insert settings and understand the tradeoff between ingestion throughput and how quickly data becomes available for queries.
When an issue requires closer investigation, dedicated ClickHouse widgets on the DB Hosts page provide node-level detail on cache usage, cloud storage, replication, and system metrics. Teams can use these views to investigate a specific node alongside the broader query and storage activity in their environment.
Get started with ClickHouse Database Monitoring
Database Monitoring for ClickHouse puts query performance, execution detail, and storage health for all your ClickHouse deployments in one place, alongside the rest of your Datadog observability data. You can find your most expensive queries, understand why they’re slow or failing, keep ingestion healthy, and use Bits to get to the root cause faster.
Database Monitoring for ClickHouse is now generally available for both ClickHouse Cloud and self-hosted deployments. For setup details, see the ClickHouse Database Monitoring documentation.
If you’re new to Datadog, sign up for a 14-day free trial.
