system.query_thread_log

[Edit this page](https://github.com/ClickHouse/ClickHouse/tree/master/docs/en/operations/system-tables/query_thread_log.md)

Querying in ClickHouse Cloud

The data in this system table is held locally on each node in ClickHouse Cloud. Obtaining a complete view of all data, therefore, requires the `clusterAllReplicas` function. See [here](/docs/operations/system-tables/overview#system-tables-in-clickhouse-cloud) for further details.

Contains information about threads that execute queries, for example, thread name, thread start time, duration of query processing.

To start logging:

1. Configure parameters in the [query\_thread\_log](/docs/operations/server-configuration-parameters/settings#query_thread_log) section.
2. Set [log\_query\_threads](/docs/operations/settings/settings#log_query_threads) to 1.

The flushing period of data is set in `flush_interval_milliseconds` parameter of the [query\_thread\_log](/docs/operations/server-configuration-parameters/settings#query_thread_log) server settings section. To force flushing, use the [SYSTEM FLUSH LOGS](/docs/sql-reference/statements/system#flush-logs) query.

ClickHouse does not delete data from the table automatically. See [Introduction](/docs/operations/system-tables/overview#system-tables-introduction) for more details.

You can use the [log\_queries\_probability](/docs/operations/settings/settings#log_queries_probability)) setting to reduce the number of queries, registered in the `query_thread_log` table.

Columns:

- `hostname` ([LowCardinality(String)](/docs/sql-reference/data-types/string)) — Hostname of the server executing the query.
- `event_date` ([Date](/docs/sql-reference/data-types/date)) — The date when the thread has finished execution of the query.
- `event_time` ([DateTime](/docs/sql-reference/data-types/datetime)) — The date and time when the thread has finished execution of the query.
- `event_time_microseconds` ([DateTime](/docs/sql-reference/data-types/datetime)) — The date and time when the thread has finished execution of the query with microseconds precision.
- `query_start_time` ([DateTime](/docs/sql-reference/data-types/datetime)) — Start time of query execution.
- `query_start_time_microseconds` ([DateTime64](/docs/sql-reference/data-types/datetime64)) — Start time of query execution with microsecond precision.
- `query_duration_ms` ([UInt64](/docs/sql-reference/data-types/int-uint#integer-ranges)) — Duration of query execution.
- `read_rows` ([UInt64](/docs/sql-reference/data-types/int-uint#integer-ranges)) — Number of read rows.
- `read_bytes` ([UInt64](/docs/sql-reference/data-types/int-uint#integer-ranges)) — Number of read bytes.
- `written_rows` ([UInt64](/docs/sql-reference/data-types/int-uint#integer-ranges)) — For `INSERT` queries, the number of written rows. For other queries, the column value is 0.
- `written_bytes` ([UInt64](/docs/sql-reference/data-types/int-uint#integer-ranges)) — For `INSERT` queries, the number of written bytes. For other queries, the column value is 0.
- `memory_usage` ([Int64](/docs/sql-reference/data-types/int-uint)) — The difference between the amount of allocated and freed memory in context of this thread.
- `peak_memory_usage` ([Int64](/docs/sql-reference/data-types/int-uint)) — The maximum difference between the amount of allocated and freed memory in context of this thread.
- `thread_name` ([String](/docs/sql-reference/data-types/string)) — Name of the thread.
- `thread_id` ([UInt64](/docs/sql-reference/data-types/int-uint)) — OS thread ID.
- `master_thread_id` ([UInt64](/docs/sql-reference/data-types/int-uint#integer-ranges)) — OS initial ID of initial thread.
- `query` ([String](/docs/sql-reference/data-types/string)) — Query string.
- `is_initial_query` ([UInt8](/docs/sql-reference/data-types/int-uint#integer-ranges)) — Query type. Possible values:
  - 1 — Query was initiated by the client.
  - 0 — Query was initiated by another query for distributed query execution.
- `connection_address` ([IPv6](/docs/sql-reference/data-types/ipv6)) — The client IP address from which the connection was made. When connected through a proxy this will be the address of the proxy.
- `connection_port` ([UInt16](/docs/sql-reference/data-types/int-uint)) — The client port from which the connection was made. When connected through a proxy this will be the port of the proxy.
- `user` ([String](/docs/sql-reference/data-types/string)) — Name of the user who initiated the current query.
- `query_id` ([String](/docs/sql-reference/data-types/string)) — ID of the query.
- `address` ([IPv6](/docs/sql-reference/data-types/ipv6)) — The IP address that was used to make the query. When connected through a proxy and [auth\_use\_forwarded\_address](/docs/operations/server-configuration-parameters/settings#auth_use_forwarded_address) is set this will be the address of the client instead of the proxy.
- `port` ([UInt16](/docs/sql-reference/data-types/int-uint#integer-ranges)) — The client port that was used to make the query. When connected through a proxy and [auth\_use\_forwarded\_address](/docs/operations/server-configuration-parameters/settings#auth_use_forwarded_address) is set this will be the port of the client instead of the proxy.
- `initial_user` ([String](/docs/sql-reference/data-types/string)) — Name of the user who ran the initial query (for distributed query execution).
- `initial_query_id` ([String](/docs/sql-reference/data-types/string)) — ID of the initial query (for distributed query execution).
- `initial_address` ([IPv6](/docs/sql-reference/data-types/ipv6)) — IP address that the parent query was launched from.
- `initial_port` ([UInt16](/docs/sql-reference/data-types/int-uint#integer-ranges)) — The client port that was used to make the parent query.
- `interface` ([UInt8](/docs/sql-reference/data-types/int-uint#integer-ranges)) — Interface that the query was initiated from. Possible values:
  - 1 — TCP.
  - 2 — HTTP.
- `os_user` ([String](/docs/sql-reference/data-types/string)) — OS's username who runs [clickhouse-client](/docs/interfaces/client).
- `client_hostname` ([String](/docs/sql-reference/data-types/string)) — Hostname of the client machine where the [clickhouse-client](/docs/interfaces/client) or another TCP client is run.
- `client_name` ([String](/docs/sql-reference/data-types/string)) — The [clickhouse-client](/docs/interfaces/client) or another TCP client name.
- `client_revision` ([UInt32](/docs/sql-reference/data-types/int-uint)) — Revision of the [clickhouse-client](/docs/interfaces/client) or another TCP client.
- `client_version_major` ([UInt32](/docs/sql-reference/data-types/int-uint)) — Major version of the [clickhouse-client](/docs/interfaces/client) or another TCP client.
- `client_version_minor` ([UInt32](/docs/sql-reference/data-types/int-uint)) — Minor version of the [clickhouse-client](/docs/interfaces/client) or another TCP client.
- `client_version_patch` ([UInt32](/docs/sql-reference/data-types/int-uint)) — Patch component of the [clickhouse-client](/docs/interfaces/client) or another TCP client version.
- `http_method` ([UInt8](/docs/sql-reference/data-types/int-uint#integer-ranges)) — 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.
- `http_user_agent` ([String](/docs/sql-reference/data-types/string)) — The `UserAgent` header passed in the HTTP request.
- `quota_key` ([String](/docs/sql-reference/data-types/string)) — The "quota key" specified in the [quotas](/docs/operations/quotas) setting (see `keyed`).
- `revision` ([UInt32](/docs/sql-reference/data-types/int-uint)) — ClickHouse revision.
- `ProfileEvents` ([Map(String, UInt64)](/docs/sql-reference/data-types/array)) — ProfileEvents that measure different metrics for this thread. The description of them could be found in the table [system.events](/docs/operations/system-tables/events).

**Example**

```
 SELECT * FROM system.query_thread_log LIMIT 1 \G
```