Contains information about queries execution. For each query, you can see processing start time, duration of processing, error message and other information.
Contains information about execution of queries. For each query, you can see processing start time, duration of processing, error messages and other information.
!!! note
!!! note
The table doesn't contain input data for `INSERT` queries.
The table doesn't contain input data for `INSERT` queries.
ClickHouse creates this table only if the [query_log](server_settings/settings.md#server_settings-query-log) server parameter is specified. This parameter sets the logging rules, such as the logging interval or the name of the table the queries will be logged in.
ClickHouse creates this table only if the [query_log](server_settings/settings.md#server_settings-query-log) server parameter is specified. This parameter sets the logging rules. For example, a logging interval or name of a table the queries will be logged in.
To enable query logging, set the [log_queries](settings/settings.md#settings-log-queries) parameter to 1. For details, see the [Settings](settings/settings.md) section.
To enable query logging, set the parameter [log_queries](settings/settings.md#settings-log-queries) to 1. For details, see the [Settings](settings/settings.md) section.
The `system.query_log` table registers two kinds of queries:
The `system.query_log` table registers two kinds of queries:
1. Initial queries, that were run directly by the client.
1. Initial queries that were run directly by the client.
2. Child queries that were initiated by other queries (for distributed query execution). For such queries, information about parent queries is shown in the `initial_*` columns.
2. 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.
Columns:
Columns:
...
@@ -379,27 +379,29 @@ Columns:
...
@@ -379,27 +379,29 @@ Columns:
- 4 — Exception during the query execution.
- 4 — Exception during the query execution.
-`event_date` (Date) — Event date.
-`event_date` (Date) — Event date.
-`event_time` (DateTime) — Event time.
-`event_time` (DateTime) — Event time.
-`query_start_time` (DateTime) — Time of the query processing start.
-`query_start_time` (DateTime) — Start time of query processing.
-`query_duration_ms` (UInt64) — Duration of the query processing.
-`query_duration_ms` (UInt64) — Duration of query processing.
-`read_rows` (UInt64) — Number of read rows.
-`read_rows` (UInt64) — Number of read rows.
-`read_bytes` (UInt64) — Number of read bytes.
-`read_bytes` (UInt64) — Number of read bytes.
-`written_rows` (UInt64) — For `INSERT` queries, number of written rows. For other queries, the column value is 0.
-`written_rows` (UInt64) — For `INSERT` queries, the number of written rows. For other queries, the column value is 0.
-`written_bytes` (UInt64) — For `INSERT` queries, number of written bytes. For other queries, the column value is 0.
-`written_bytes` (UInt64) — For `INSERT` queries, the number of written bytes. For other queries, the column value is 0.
-`result_rows` (UInt64) — Number of rows in a result.
-`result_rows` (UInt64) — Number of rows in the result.
-`result_bytes` (UInt64) — Number of bytes in a result.
-`result_bytes` (UInt64) — Number of bytes in the result.
-`memory_usage` (UInt64) — Memory consumption by the query.
-`memory_usage` (UInt64) — Memory consumption by the query.
-`query` (String) — Query string.
-`query` (String) — Query string.
-`exception` (String) — Exception message.
-`exception` (String) — Exception message.
-`stack_trace` (String) — Stack trace (a list of methods called before the error occurred). An empty string, if the query is completed successfully.
-`stack_trace` (String) — Stack trace (a list of methods called before the error occurred). An empty string, if the query is completed successfully.
-`is_initial_query` (UInt8) — Flag that indicates whether the query is initiated by the client (1), or by another query for distributed query execution (0).
-`is_initial_query` (UInt8) — Kind of query. Possible values:
-`user` (String) — Name of the user initiated the current query.
- 1 — Query was initiated by the client.
- 0 — Query was initiated by another query for distributed query execution.
-`user` (String) — Name of the user who initiated the current query.
-`query_id` (String) — ID of the query.
-`query_id` (String) — ID of the query.
-`address` (FixedString(16)) — IP address the query was initiated from.
-`address` (FixedString(16)) — IP address the query was initiated from.
-`port` (UInt16) — A server port that was used to receive the query.
-`port` (UInt16) — The server port that was used to receive the query.
-`initial_user` (String) — Name of the user who run the parent query (for distributed query execution).
-`initial_user` (String) — Name of the user who ran the parent query (for distributed query execution).
-`initial_query_id` (String) — ID of the parent query.
-`initial_query_id` (String) — ID of the parent query.
-`initial_address` (FixedString(16)) — IP address that the parent query was launched from.
-`initial_address` (FixedString(16)) — IP address that the parent query was launched from.
-`initial_port` (UInt16) — A server port that was used to receive the parent query from the client.
-`initial_port` (UInt16) — The server port that was used to receive the parent query from the client.
-`interface` (UInt8) — Interface that the query was initiated from. Possible values:
-`interface` (UInt8) — Interface that the query was initiated from. Possible values:
- 1 — TCP.
- 1 — TCP.
- 2 — HTTP.
- 2 — HTTP.
...
@@ -410,12 +412,12 @@ Columns:
...
@@ -410,12 +412,12 @@ Columns:
-`client_version_major` (UInt32) — Major version of the [clickhouse-client](../interfaces/cli.md).
-`client_version_major` (UInt32) — Major version of the [clickhouse-client](../interfaces/cli.md).
-`client_version_minor` (UInt32) — Minor version of the [clickhouse-client](../interfaces/cli.md).
-`client_version_minor` (UInt32) — Minor version of the [clickhouse-client](../interfaces/cli.md).
-`client_version_patch` (UInt32) — Patch component of the [clickhouse-client](../interfaces/cli.md) version.
-`client_version_patch` (UInt32) — Patch component of the [clickhouse-client](../interfaces/cli.md) version.
-`http_method` (UInt8) — HTTP method initiated the query. Possible values:
-`http_method` (UInt8) — HTTP method that initiated the query. Possible values:
- 0 — The query was launched from the TCP interface.
- 0 — The query was launched from the TCP interface.
- 1 — `GET` method is used.
- 1 — `GET` method was used.
- 2 — `POST` method is used.
- 2 — `POST` method was used.
-`http_user_agent` (String) — The `UserAgent` header passed in the HTTP request.
-`http_user_agent` (String) — The `UserAgent` header passed in the HTTP request.
-`quota_key` (String) — The quota key specified in [quotas](quotas.md) setting.
-`quota_key` (String) — The quota key specified in the [quotas](quotas.md) setting.
-`revision` (UInt32) — ClickHouse revision.
-`revision` (UInt32) — ClickHouse revision.
-`thread_numbers` (Array(UInt32)) — Number of threads that are participating in query execution.
-`thread_numbers` (Array(UInt32)) — Number of threads that are participating in query execution.
-`ProfileEvents.Names` (Array(String)) — Counters that measure the following metrics:
-`ProfileEvents.Names` (Array(String)) — Counters that measure the following metrics:
...
@@ -424,21 +426,21 @@ Columns:
...
@@ -424,21 +426,21 @@ Columns:
- Number of network errors.
- Number of network errors.
- Time spent on waiting when the network bandwidth is limited.
- Time spent on waiting when the network bandwidth is limited.
-`ProfileEvents.Values` (Array(UInt64)) — Values of metrics that are listed in the `ProfileEvents.Names` column.
-`ProfileEvents.Values` (Array(UInt64)) — Values of metrics that are listed in the `ProfileEvents.Names` column.
-`Settings.Names` (Array(String)) — Names of settings that were changed when the client run a query. To enable logging of settings changing, set the `log_query_settings` parameter to 1.
-`Settings.Names` (Array(String)) — Names of settings that were changed when the client ran the query. To enable logging changes to settings, set the `log_query_settings` parameter to 1.
-`Settings.Values` (Array(String)) — Values of settings that are listed in the `Settings.Names` column.
-`Settings.Values` (Array(String)) — Values of settings that are listed in the `Settings.Names` column.
Each query creates one or two rows in the `query_log` table, depending on the status of the query:
Each query creates one or two rows in the `query_log` table, depending on the status of the query:
1. If the query execution is successful, two events with types 1 and 2 are created (see the `type` column).
1. If the query execution is successful, two events with types 1 and 2 are created (see the `type` column).
2. If the error occurred during the query processing, two events with types 1 and 4 are created.
2. If an error occurred during query processing, two events with types 1 and 4 are created.
3. If the error occurred before the query launching, a single event with type 3 is created.
3. If an error occurred before launching the query, a single event with type 3 is created.
By default, logs are added into the table at intervals of 7,5 seconds. You can set this interval in the [query_log](server_settings/settings.md#server_settings-query-log) server setting (see the `flush_interval_milliseconds` parameter). To flush the logs forcibly from the memory buffer into the table, use the `SYSTEM FLUSH LOGS` query.
By default, logs are added to the table at intervals of 7.5 seconds. You can set this interval in the [query_log](server_settings/settings.md#server_settings-query-log) server setting (see the `flush_interval_milliseconds` parameter). To flush the logs forcibly from the memory buffer into the table, use the `SYSTEM FLUSH LOGS` query.
When the table is deleted manually, it will be automatically created on the fly. Note that all the previous logs will be deleted.
When the table is deleted manually, it will be automatically created on the fly. Note that all the previous logs will be deleted.
!!! note
!!! note
The storage period for logs is unlimited; the logs aren't automatically deleted from the table. You need to organize the removing of non-actual logs yourself.
The storage period for logs is unlimited. Logs aren't automatically deleted from the table. You need to organize the removal of outdated logs yourself.
You can specify an arbitrary partitioning key for the `system.query_log` table in the [query_log](server_settings/settings.md#server_settings-query-log) server setting (see the `partition_by` parameter).
You can specify an arbitrary partitioning key for the `system.query_log` table in the [query_log](server_settings/settings.md#server_settings-query-log) server setting (see the `partition_by` parameter).