ClickHouse
Investigate slow ClickHouse queries
ClickHouse's system.query_log and Cloud Query Insights both expose query performance. Query the log when you need exact rows or SQL, or use Query Insights for grouped latency, error, and recent-query views.
Documentation reviewed · 2 methods with sources
Ways to do it
CLI
clickhouse-client query system.query_log
Run a read-only query against the query log and order completed initial queries by duration to find recent slow work.
Read source: ClickHouse system.query_log- Requirements
- A ClickHouse client, a secure service endpoint, database credentials, SELECT access to system.query_log, and the REMOTE grant for clusterAllReplicas. In ClickHouse Cloud use the default cluster. Use --ask-password for an interactive password prompt.
- Limitations
- Cloud query-log rows are local to each node, so a direct system.query_log query can miss other replicas. The log also flushes on its configured interval and does not store query results.
Example shell
clickhouse-client --host "$CLICKHOUSE_HOST" --secure --ask-password --user "$CLICKHOUSE_USER" --query "SELECT query_id, query_duration_ms, read_rows, query FROM clusterAllReplicas('default', system.query_log) WHERE type = 'QueryFinish' AND is_initial_query = 1 AND event_time >= now() - INTERVAL 1 HOUR ORDER BY query_duration_ms DESC LIMIT 20 FORMAT JSONEachRow"Interface
Cloud Monitoring → Query insights
Select a ClickHouse Cloud service, open Monitoring, then Query insights to view latency percentiles, query volume, errors, filters, and query drill-down details.
Read source: ClickHouse Cloud Query insights- Requirements
- A ClickHouse Cloud account with access to the service and a role that can view its monitoring data.
- Limitations
- The recent-query table groups entries by normalized query hash and user over the selected time window, so it is an aggregate view rather than a raw per-row query log export.