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

slug: /en/operations/system-tables/querythreadlog Contains information about threads that execute queries, for example, thread name, thread start time, duration of query processing. To start logging: Configure parameters in the section. Set to 1. 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. You can use the setting to reduce the number of queries, registered in the `querythreadlog` table. Columns: `hostname` () Hostname of the server executing the query. `event_date` () The date when the thread has finished execution of the query. `event_time` () The date and time when the thread has finished execution of the query. `eventtimemicroseconds` () The date and time when the thread has finished execution of the query with microseconds precision. `querystarttime` () Start time of query execution. `querystarttime_microseconds` () Start time of query execution with microsecond precision. `querydurationms` () Duration of query execution. `read_rows` () Number of read rows. `read_bytes` () Number of read bytes. `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. For other queries, the column value is 0. `memory_usage` () The difference between the amount of allocated and freed memory in context of this thread. `peakmemoryusage` () The maximum difference between the amount of allocated and freed memory in context of this thread. `thread_name` () Name of the thread. `thread_id` () OS thread ID. `masterthreadid` () OS initial ID of initial thread. `query` () Query string. `isinitialquery` () Query type. Possible values: 1 Query was initiated by the client. 0 Query was initiated by another query for 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

`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. `interface` () Interface that the query was initiated from. Possible values: 1 TCP. 2 HTTP. `os_user` () OSs 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` () 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` () The `UserAgent` header passed in the HTTP request. `quota_key` () The quota key specified in the setting (see `keyed`). `revision` () ClickHouse revision. `ProfileEvents` () ProfileEvents that measure different metrics for this thread. The description of them could be found in the table . Example ``` sql SELECT * FROM system.querythreadlog LIMIT 1 \G ``` ``` text Row 1: hostname: clickhouse.eu-central1.internal event_date: 2020-09-11 event_time: 2020-09-11 10:08:17 eventtimemicroseconds: 2020-09-11 10:08:17.134042 querystarttime: 2020-09-11 10:08:17 querystarttime_microseconds: 2020-09-11 10:08:17.063150 querydurationms: 70 read_rows: 0 read_bytes: 0 written_rows: 1 written_bytes: 12 memory_usage: 4300844 peakmemoryusage: 4300844 thread_name: TCPHandler thread_id: 638133 masterthreadid: 638133 query: INSERT INTO test1 VALUES isinitialquery: 1 user: default query_id: 50a320fd-85a8-49b8-8761-98a86bcbacef address: ::ffff:127.0.0.1 port: 33452 initial_user: default initialqueryid: 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 clientversionmajor: 20 clientversionminor: 7 clientversionpatch: 2 http_method: 0 httpuseragent: quota_key: revision: 54440 ProfileEvents: {'Query':1,'SelectQuery':1,'ReadCompressedBytes':36,'CompressedReadBufferBlocks':1,'CompressedReadBufferBytes':10,'IOBufferAllocs':1,'IOBufferAllocBytes':89,'ContextLock':15,'RWLockAcquiredReadLocks':1} ``` See Also Description of the `query_log` system table which contains common information about queries execution. This table contains information about each view executed during a query.