Skip to content

system.query_log ​

A read-only structured request history. query_id links events from one request with its response and diagnostic records. log_queries and log_queries_min_query_duration_ms control recording.

Columns ​

Name Meaning
event_time, event_time_text Ordered event time and its text representation.
type QueryStart, QueryFinish, ExceptionBeforeStart or ExceptionWhileProcessing.
query_start_time Request start time.
query_duration_ms Request duration in milliseconds.
query_id Request identifier linking its events.
current_database Database used by the request.
query, query_kind SQL text and statement classification.
address, port Client endpoint.
user, interface Authenticated identity and TCP/HTTP interface.
result_rows Returned rows across the request statements.
exception_code, exception Permanent failure code and message; zero and empty text on success.
normalized_query_hash Normalized-SQL grouping hash.
read_rows, read_bytes Read work observed during the request.
written_rows, written_bytes Write work observed during the request.
memory_usage, peak_memory_usage Peak accounted SQL memory at terminal events.

Visibility ​

Events are recorded asynchronously. A direct single-table SELECT from system.query_log waits for previously queued events before reading. Each reading statement takes a fresh history snapshot, including inside a user transaction.

The current request's terminal event appears only after its execution. A nonzero duration threshold skips fast requests and records only qualifying terminal events; disabling logging overrides it.

Counter interpretation ​

At terminal events, both memory_usage and peak_memory_usage report peak accounted SQL heap usage. Work later rolled back can still contribute to read/write counters. result_rows counts returned rows across the request's statements.

Example ​

sql
SELECT type, exception_code
FROM system.query_log
WHERE type = 'QueryFinish'
ORDER BY event_time DESC
LIMIT 1
FORMAT csv;
text
"QueryFinish",0

Use the system qualifier through the server. See logging settings, active requests and query measurements.