Query History
History, failed, expensive, and slow query pages read from system.query_log — configure retention, grants, and default user exclusions.
The query history pages (/history-queries, /failed-queries,
/expensive-queries, /slow-queries) read from system.query_log. This table
is built into ClickHouse and records every completed query.
Requirements
system.query_log must be enabled in your ClickHouse configuration. It is
enabled by default in most installations. If the table is empty or missing,
history pages show no data.
The configured CLICKHOUSE_USER needs SELECT on system.query_log:
GRANT SELECT ON system.query_log TO monitoring_user;Configure
Set retention
ClickHouse flushes query log entries every 7.5 seconds by default and retains
them for 30 days. To change retention, set flush_interval_milliseconds and
partition_by / ttl in system.query_log config:
<!-- config.xml or conf.d/query_log.xml -->
<query_log>
<database>system</database>
<table>query_log</table>
<flush_interval_milliseconds>7500</flush_interval_milliseconds>
<ttl>event_date + INTERVAL 14 DAY DELETE</ttl>
</query_log>Shorter retention reduces disk usage but limits how far back history pages can look.
Filter out monitoring users
By default, history pages show queries from all users including the monitoring
user itself. This creates noise. Filter out specific users using
CLICKHOUSE_EXCLUDE_USER_DEFAULT:
CLICKHOUSE_EXCLUDE_USER_DEFAULT=monitoring,healthcheckSet this to a comma-separated list of usernames to exclude from history page defaults. Users can still remove the filter in the UI.
docker run -d \
-e CLICKHOUSE_HOST='http://ch-1:8123' \
-e CLICKHOUSE_USER='monitoring' \
-e CLICKHOUSE_PASSWORD='' \
-e CLICKHOUSE_EXCLUDE_USER_DEFAULT='monitoring,healthcheck' \
-p 3000:3000 \
ghcr.io/chmonitor/chmonitor:vX.Y.Zenv:
- name: CLICKHOUSE_HOST
value: "http://ch-1:8123"
- name: CLICKHOUSE_USER
value: "monitoring"
- name: CLICKHOUSE_PASSWORD
value: ""
- name: CLICKHOUSE_EXCLUDE_USER_DEFAULT
value: "monitoring,healthcheck"What each history page shows
| Page | Route | Source | Description |
|---|---|---|---|
| History | /history-queries | system.query_log | All completed queries, filterable by user, database, and time. |
| Failed | /failed-queries | system.query_log | Queries that ended with an exception. |
| Expensive | /expensive-queries | system.query_log | Queries ranked by memory usage or read bytes. |
| Slow | /slow-queries | system.query_log | Queries ranked by elapsed time. |
Notes
- History pages respect the global time range selector.
- If
system.query_logis partitioned by day, queries crossing midnight may appear split across rows. - The AI agent can analyze query history and surface patterns or anomalies — see AI Agent.