Inspect query history
Use system.query_log to inspect finished work and system.processes to inspect requests that are still running. A query ID connects the request with response metadata and diagnostics.
Enable history
SET log_queries = 1;The setting persists for the selected database. log_queries_min_query_duration_ms can restrict history to requests meeting a duration threshold.
Read terminal events
SELECT type, exception_code
FROM system.query_log
WHERE type = 'QueryFinish'
ORDER BY event_time DESC
LIMIT 1
FORMAT csv;"QueryFinish",0A direct single-table SELECT from system.query_log waits for earlier queued events before reading. The current request's own terminal event appears only after it finishes. A duration threshold can omit short requests and their start events.
Follow a request
Use its query_id to select duration, row/byte counters and exception details. Inspect system.processes for an active request rather than expecting its terminal history record before completion.
See query_log, processes and query measurements.