Project: ClickHouse (App Definition and Development / Database)
File: query_log.md

slug: /en/operations/system-tables/query_log Contains information about executed queries, for example, start time, duration of processing, error messages. :::note This table does not contain the ingested data for `INSERT` queries. ::: You can change settings of queries logging in the section of the server configuration. You can disable queries logging by setting . We do not recommend to turn off logging because information in this table is important for solving issues. The flushing period of data is set in `flushintervalmilliseconds` parameter of the server settings section. To force flushing, use the query. ClickHouse does not delete data from the table automatically. See for more details. The `system.query_log` table registers two kinds of queries: Initial queries that were run directly by the client. Child queries that were initiated by other queries (for distributed query execution). For these types of queries, information about the parent queries is shown in the `initial_*` columns. Each query creates one or two rows in the `query_log` table, depending on the status (see the `type` column) of the query: If the query execution was successful, two rows with the `QueryStart` and `QueryFinish` types are created. If an error occurred during query processing, two events with the `QueryStart` and `ExceptionWhileProcessing` types are created. If an error occurred before launching the query, a single event with the `ExceptionBeforeStart` type is created. You can use the setting to reduce the number of queries, registered in the `query_log` table. You can use the setting to log formatted queries to the `formatted_query` column. Columns: `hostname` () Hostname of the server executing the query. `type` () Type of an event that occurred when executing the query. Values: `'QueryStart' = 1` Successful start of query execution. `'QueryFinish' = 2` Successful end of query execution. `'ExceptionBeforeStart' = 3` Exception before the start of query execution. `'ExceptionWhileProcessing' = 4` Exception during the query execution. `event_date` () Query starting date. `event_time` () Query starting time. `eventtimemicroseconds` () Query starting time with microseconds precision. `querystarttime` () Start time of query execution. `querystarttime_microseconds` () Start time of query execution with microsecond precision. `querydurationms` () Duration of query execution in milliseconds. `readrows` () Total number of rows read from all tables and table functions participated in query. It includes usual subqueries, subqueries for `IN` and `JOIN`. For distributed queries `readrows` includes the total number of rows read at all replicas. Each replica sends its `read_rows` value, and the server-initiator of the query summarizes all received and local values. The cache volumes do not affect this value. `readbytes` () Total number of bytes read from all tables and table functions participated in query. It includes usual subqueries, subqueries for `IN` and `JOIN`. For distributed queries `readbytes` includes the total number of rows read at all replicas. Each replica sends its `read_bytes` value, and the server-initiator of the query summarizes all received and local

The cache volumes do not affect this value. `written_rows` () For `INSERT` queries, the number of written rows. For other queries, the column value is 0. `written_bytes` () For `INSERT` queries, the number of written bytes (uncompressed). For other queries, the column value is 0. `result_rows` () Number of rows in a result of the `SELECT` query, or a number of rows in the `INSERT` query. `result_bytes` () RAM volume in bytes used to store a query result. `memory_usage` () Memory consumption by the query. `current_database` () Name of the current database. `query` () Query string. `formatted_query` () Formatted query string. `normalizedqueryhash` () Identical hash value without the values of literals for similar queries. `query_kind` () Type of the query. `databases` (()) Names of the databases present in the query. `tables` (()) Names of the tables present in the query. `columns` (()) Names of the columns present in the query. `partitions` (()) Names of the partitions present in the query. `projections` () Names of the projections used during the query execution. `views` (()) Names of the (materialized or live) views present in the query. `exception_code` () Code of an exception. `exception` () Exception message. `stack_trace` () . An empty string, if the query was completed successfully. `isinitialquery` () Query type. Possible values: 1 Query was initiated by the client. 0 Query was initiated by another query as part of distributed query execution. `user` () Name of the user who initiated the current query. `query_id` () ID of the query. `address` () IP address that was used to make the query. `port` () The client port that was used to make the query. `initial_user` () Name of the user who ran the initial query (for distributed query execution). `initialqueryid` () ID of the initial query (for distributed query execution). `initial_address` () IP address that the parent query was launched from. `initial_port` () The client port that was used to make the parent query. `initialquerystart_time` () Initial query starting time (for distributed query execution). `initialquerystarttimemicroseconds` () Initial query starting time with microseconds precision (for distributed query execution). `interface` () Interface that the query was initiated from. Possible values: 1 TCP. 2 HTTP. `os_user` () Operating system username who runs . `client_hostname` () Hostname of the client machine where the or another TCP client is run. `client_name` () The or another TCP client name. `client_revision` () Revision of the or another TCP client. `clientversionmajor` () Major version of the or another TCP client. `clientversionminor` () Minor version of the or another TCP client. `clientversionpatch` () Patch component of the or another TCP client version. `http_method` (UInt8) HTTP method that initiated the query. Possible values: 0 The query was launched from the TCP interface. 1 `GET` method was used. 2 `POST` method was used. `httpuseragent` () HTTP header `UserAgent` passed in the HTTP

`http_referer` () HTTP header `Referer` passed in the HTTP query (contains an absolute or partial address of the page making the query). `forwarded_for` () HTTP header `X-Forwarded-For` passed in the HTTP query. `quota_key` () The `quota key` specified in the setting (see `keyed`). `revision` () ClickHouse revision. `ProfileEvents` () ProfileEvents that measure different metrics. The description of them could be found in the table `Settings` () Settings that were changed when the client ran the query. To enable logging changes to settings, set the `logquerysettings` parameter to 1. `log_comment` () Log comment. It can be set to arbitrary string no longer than . An empty string if it is not defined. `thread_ids` () Thread ids that are participating in query execution. These threads may not have run simultaneously. `peakthreadsusage` () Maximum count of simultaneous threads executing the query. `usedaggregatefunctions` () Canonical names of `aggregate functions`, which were used during query execution. `usedaggregatefunction_combinators` () Canonical names of `aggregate functions combinators`, which were used during query execution. `useddatabaseengines` () Canonical names of `database engines`, which were used during query execution. `useddatatype_families` () Canonical names of `data type families`, which were used during query execution. `used_dictionaries` () Canonical names of `dictionaries`, which were used during query execution. `used_formats` () Canonical names of `formats`, which were used during query execution. `used_functions` () Canonical names of `functions`, which were used during query execution. `used_storages` () Canonical names of `storages`, which were used during query execution. `usedtablefunctions` () Canonical names of `table functions`, which were used during query execution. `querycacheusage` () Usage of the during query execution. Values: `'Unknown'` = Status unknown. `'None'` = The query result was neither written into nor read from the query cache. `'Write'` = The query result was written into the query cache. `'Read'` = The query result was read from the query cache. Example ``` sql SELECT * FROM system.querylog WHERE type = 'QueryFinish' ORDER BY querystart_time DESC LIMIT 1 FORMAT Vertical; ``` ``` text Row 1: hostname: clickhouse.eu-central1.internal type: QueryFinish event_date: 2021-11-03 event_time: 2021-11-03 16:13:54 eventtimemicroseconds: 2021-11-03 16:13:54.953024 querystarttime: 2021-11-03 16:13:54 querystarttime_microseconds: 2021-11-03 16:13:54.952325 querydurationms: 0 read_rows: 69 read_bytes: 6187 written_rows: 0 written_bytes: 0 result_rows: 69 result_bytes: 48256 memory_usage: 0 current_database: default query: DESCRIBE TABLE system.query_log formatted_query: normalizedqueryhash: 8274064835331539124 query_kind: databases: [] tables: [] columns: [] projections: [] views: [] exception_code: 0 exception: stack_trace: isinitialquery: 1 user: default query_id: 7c28bbbb-753b-4eba-98b1-efcbe2b9bdf6 address: ::ffff:127.0.0.1 port: 40452 initial_user: default initialqueryid: 7c28bbbb-753b-4eba-98b1-efcbe2b9bdf6 initial_address: ::ffff:127.0.0.1 initial_port: 40452 initialquerystart_time: 2021-11-03 16:13:54 initialquerystarttimemicroseconds: 2021-11-03 16:13:54.952325 interface: 1 os_user: sevirov client_hostname: clickhouse.eu-central1.internal client_name: ClickHouse client_revision: 54449 clientversionmajor: 21 clientversionminor: 10 clientversionpatch: 1 http_method: 0 httpuseragent: http_referer: forwarded_for: quota_key: revision: 54456 log_comment: thread_ids: [30776,31174] ProfileEvents: {'Query':1,'NetworkSendElapsedMicroseconds':59,'NetworkSendBytes':2643,'SelectedRows':69,'SelectedBytes':6187,'ContextLock':9,'RWLockAcquiredReadLocks':1,'RealTimeMicroseconds':817,'UserTimeMicroseconds':427,'SystemTimeMicroseconds':212,'OSCPUVirtualTimeMicroseconds':639,'OSReadChars':894,'OSWriteChars':319} Settings: {'loadbalancing':'random','maxmemory_usage':'10000000000'} usedaggregatefunctions: [] usedaggregatefunction_combinators: [] useddatabaseengines: [] useddatatype_families: [] used_dictionaries: [] used_formats: [] used_functions: [] used_storages: [] usedtablefunctions: [] querycacheusage: None ``` See Also This table contains information about each query execution thread.