> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> System table containing information about threads that execute queries, for example, thread name, thread start time, duration of query processing.

# system.query_thread_log

<Info>
  **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](/reference/system-tables/overview#system-tables-in-clickhouse-cloud) for further details.
</Info>

<h2 id="description">
  Description
</h2>

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](/reference/settings/server-settings/settings#query_thread_log) section.
2. Set [log\_query\_threads](/reference/settings/session-settings#log_query_threads) to 1.

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

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

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

<h2 id="columns">
  Columns
</h2>

* `hostname` ([LowCardinality(String)](/reference/data-types/lowcardinality)) — Hostname of the server executing the query.
* `event_date` ([Date](/reference/data-types/date)) — The date when the thread has finished execution of the query.
* `event_time` ([DateTime](/reference/data-types/datetime)) — The date and time when the thread has finished execution of the query.
* `event_time_microseconds` ([DateTime64(6)](/reference/data-types/datetime64)) — The date and time when the thread has finished execution of the query with microseconds precision.
* `query_start_time` ([DateTime](/reference/data-types/datetime)) — Start time of query execution.
* `query_start_time_microseconds` ([DateTime64(6)](/reference/data-types/datetime64)) — Start time of query execution with microsecond precision.
* `query_duration_ms` ([UInt64](/reference/data-types/int-uint)) — Duration of query execution.
* `read_rows` ([UInt64](/reference/data-types/int-uint)) — Number of read rows.
* `read_bytes` ([UInt64](/reference/data-types/int-uint)) — Number of read bytes.
* `written_rows` ([UInt64](/reference/data-types/int-uint)) — For INSERT queries, the number of written rows. For other queries, the column value is 0.
* `written_bytes` ([UInt64](/reference/data-types/int-uint)) — For INSERT queries, the number of written bytes. For other queries, the column value is 0.
* `memory_usage` ([Int64](/reference/data-types/int-uint)) — The difference between the amount of allocated and freed memory in context of this thread.
* `peak_memory_usage` ([Int64](/reference/data-types/int-uint)) — The maximum difference between the amount of allocated and freed memory in context of this thread.
* `thread_name` ([LowCardinality(String)](/reference/data-types/lowcardinality)) — Name of the thread.
* `thread_id` ([UInt64](/reference/data-types/int-uint)) — Internal thread ID.
* `master_thread_id` ([UInt64](/reference/data-types/int-uint)) — OS initial ID of initial thread.
* `current_database` ([LowCardinality(String)](/reference/data-types/lowcardinality)) — Name of the current database.
* `query` ([String](/reference/data-types/string)) — Query string.
* `normalized_query_hash` ([UInt64](/reference/data-types/int-uint)) — The hash of normalized query - with wiped constants, etc.
* `is_initial_query` ([UInt8](/reference/data-types/int-uint)) — 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](/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](/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` ([LowCardinality(String)](/reference/data-types/lowcardinality)) — Name of the user who initiated the current query.
* `query_id` ([String](/reference/data-types/string)) — ID of the query.
* `address` ([IPv6](/reference/data-types/ipv6)) — IP address that was used to make the query. When connected through a proxy and `auth_use_forwarded_address` is set, this will be the address of the client instead of the proxy.
* `port` ([UInt16](/reference/data-types/int-uint)) — The client port that was used to make the query. When connected through a proxy and `auth_use_forwarded_address` is set, this will be the port of the client instead of the proxy.
* `initial_user` ([LowCardinality(String)](/reference/data-types/lowcardinality)) — Name of the user who ran the initial query (for distributed query execution).
* `initial_query_id` ([String](/reference/data-types/string)) — ID of the initial query (for distributed query execution).
* `initial_address` ([IPv6](/reference/data-types/ipv6)) — IP address that the parent query was launched from.
* `initial_port` ([UInt16](/reference/data-types/int-uint)) — The client port that was used to make the parent query.
* `initial_query_start_time` ([DateTime](/reference/data-types/datetime)) — Start time of the initial query execution.
* `initial_query_start_time_microseconds` ([DateTime64(6)](/reference/data-types/datetime64)) — Start time of the initial query execution
* `authenticated_user` ([LowCardinality(String)](/reference/data-types/lowcardinality)) — Name of the user who was authenticated in the session.
* `interface` ([UInt8](/reference/data-types/int-uint)) — Interface that the query was initiated from. Possible values: 1 — TCP, 2 — HTTP.
* `is_secure` ([UInt8](/reference/data-types/int-uint)) — The flag which shows whether the connection was secure.
* `os_user` ([LowCardinality(String)](/reference/data-types/lowcardinality)) — OSs username who runs clickhouse-client.
* `client_hostname` ([LowCardinality(String)](/reference/data-types/lowcardinality)) — Hostname of the client machine where the clickhouse-client or another TCP client is run.
* `client_name` ([LowCardinality(String)](/reference/data-types/lowcardinality)) — The clickhouse-client or another TCP client name.
* `client_agent` ([LowCardinality(String)](/reference/data-types/lowcardinality)) — The AI coding agent that invoked the client (for example, `claude-code` or `cursor`), detected from environment variables. Empty if no agent was detected.
* `client_revision` ([UInt32](/reference/data-types/int-uint)) — Revision of the clickhouse-client or another TCP client.
* `client_version_major` ([UInt32](/reference/data-types/int-uint)) — Major version of the clickhouse-client or another TCP client.
* `client_version_minor` ([UInt32](/reference/data-types/int-uint)) — Minor version of the clickhouse-client or another TCP client.
* `client_version_patch` ([UInt32](/reference/data-types/int-uint)) — Patch component of the clickhouse-client or another TCP client version.
* `script_query_number` ([UInt32](/reference/data-types/int-uint)) — A sequential query number in a multi-query script.
* `script_line_number` ([UInt32](/reference/data-types/int-uint)) — A line number in a multi-query script where the current query starts.
* `http_method` ([UInt8](/reference/data-types/int-uint)) — 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` ([LowCardinality(String)](/reference/data-types/lowcardinality)) — The UserAgent header passed in the HTTP request.
* `http_referer` ([String](/reference/data-types/string)) — HTTP header `Referer` passed in the HTTP query (contains an absolute or partial address of the page making the query).
* `forwarded_for` ([String](/reference/data-types/string)) — HTTP header `X-Forwarded-For` passed in the HTTP query.
* `quota_key` ([String](/reference/data-types/string)) — The 'quota key' specified in the quotas setting.
* `distributed_depth` ([UInt64](/reference/data-types/int-uint)) — How many times a query was forwarded between servers.
* `revision` ([UInt32](/reference/data-types/int-uint)) — ClickHouse revision.
* `ProfileEvents` ([Map(LowCardinality(String), UInt64)](/reference/data-types/map)) — ProfileEvents that measure different metrics for this thread. The description of them could be found in the table system.events.

**Aliases:**

* `ProfileEvents.Names` — Alias for `mapKeys(ProfileEvents)`.
* `ProfileEvents.Values` — Alias for `mapValues(ProfileEvents)`.

<h2 id="example">
  Example
</h2>

```sql theme={null}
 SELECT * FROM system.query_thread_log LIMIT 1 \G
```

```text theme={null}
Row 1:
──────
hostname:                      clickhouse.eu-central1.internal
event_date:                    2020-09-11
event_time:                    2020-09-11 10:08:17
event_time_microseconds:       2020-09-11 10:08:17.134042
query_start_time:              2020-09-11 10:08:17
query_start_time_microseconds: 2020-09-11 10:08:17.063150
query_duration_ms:             70
read_rows:                     0
read_bytes:                    0
written_rows:                  1
written_bytes:                 12
memory_usage:                  4300844
peak_memory_usage:             4300844
thread_name:                   TCPHandler
thread_id:                     638133
master_thread_id:              638133
query:                         INSERT INTO test1 VALUES
is_initial_query:              1
user:                          default
query_id:                      50a320fd-85a8-49b8-8761-98a86bcbacef
address:                       ::ffff:127.0.0.1
port:                          33452
initial_user:                  default
initial_query_id:              50a320fd-85a8-49b8-8761-98a86bcbacef
initial_address:               ::ffff:127.0.0.1
initial_port:                  33452
interface:                     1
os_user:                       bharatnc
client_hostname:               tower
client_name:                   ClickHouse
client_revision:               54437
client_version_major:          20
client_version_minor:          7
client_version_patch:          2
http_method:                   0
http_user_agent:
quota_key:
revision:                      54440
ProfileEvents:        {'Query':1,'SelectQuery':1,'ReadCompressedBytes':36,'CompressedReadBufferBlocks':1,'CompressedReadBufferBytes':10,'IOBufferAllocs':1,'IOBufferAllocBytes':89,'ContextLock':15,'RWLockAcquiredReadLocks':1}
```

<h2 id="see-also">
  See Also
</h2>

* [system.query\_log](/reference/system-tables/query_log) — Description of the `query_log` system table which contains common information about queries execution.
* [system.query\_views\_log](/reference/system-tables/query_views_log) — This table contains information about each view executed during a query.
