Useful queries for troubleshooting
In no particular order, here are some handy queries for troubleshooting ClickHouse and figuring out what is happening. We also have a great blog with some essential queries for monitoring ClickHouse.View which settings have been changed from the default
Get the size of all your tables
Row count and average day size of your table
Compression columns percentage as well as the size of primary index in memory
You can see how compressed your data is by column. This query also returns the size of your primary indexes in memory - useful to know because primary indexes must fit in memory.Number of queries sent by client in the last 10 minutes
Feel free to increase or decrease the time interval in thetoIntervalMinute(10) function:
Number of parts in each partition
Finding long running queries
This can help find queries that are stuck:View the most recent errors
Top 10 queries that are using the most CPU and memory
A single query can be logged as multiple rows with different
query_id values — distributed secondary queries and internal view steps have is_initial_query = 0. Filter on is_initial_query = 1 (or query_id = initial_query_id) to see queries as they were submitted, and note that the internal query_id values ClickHouse assigns may include a label such as queryView.... See the query_log reference for details.How much disk space are my projection using
Show disk storage, number of parts, number of rows in system.parts and marks across databases
List details of recently written new parts
The details include when they got created, how large they are, how many rows, and more:Cluster-wide monitoring queries
The following queries are useful for monitoring ClickHouse clusters. They useclusterAllReplicas() to aggregate data across all nodes.
These queries assume your cluster is named
default. If your cluster has a different name, replace 'default' and default with your cluster’s actual name.Average new parts created per minute and second (last hour)
'your_table' with the actual table name you want to monitor.