system.query_thread_log

    To start logging:

    1. Configure parameters in the query_thread_log section.
    2. Set to 1.

    ClickHouse doesn’t delete data from the table automatically. See Introduction for more details.

    • event_date () — The date when the thread has finished execution of the query.
    • event_time (DateTime) — The date and time when the thread has finished execution of the query.
    • event_time_microsecinds () — The date and time when the thread has finished execution of the query with microseconds precision.
    • query_start_time (DateTime) — Start time of query execution.
    • query_start_time_microseconds () — Start time of query execution with microsecond precision.
    • query_duration_ms (UInt64) — Duration of query execution.
    • read_rows () — Number of read rows.
    • read_bytes (UInt64) — Number of read bytes.
    • written_rows () — For INSERT queries, the number of written rows. 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.
    • memory_usage () — The difference between the amount of allocated and freed memory in context of this thread.
    • peak_memory_usage (Int64) — The maximum difference between the amount of allocated and freed memory in context of this thread.
    • thread_name () — Name of the thread.
    • thread_number (UInt32) — Internal thread ID.
    • thread_id () — thread ID.
    • master_thread_id (UInt64) — OS initial ID of initial thread.
    • query () — Query string.
    • is_initial_query (UInt8) — 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 (String) — ID of the query.
    • address () — IP address that was used to make the query.
    • port (UInt16) — 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).
    • initial_query_id (String) — ID of the initial query (for distributed query execution).
    • initial_address () — IP address that the parent query was launched from.
    • interface (UInt8) — Interface that the query was initiated from. Possible values:
      • 1 — TCP.
      • 2 — HTTP.
    • () — OS’s username who runs clickhouse-client.
    • client_hostname () — Hostname of the client machine where the clickhouse-client or another TCP client is run.
    • client_name () — The clickhouse-client or another TCP client name.
    • client_revision () — Revision of the clickhouse-client or another TCP client.
    • client_version_major () — Major version of the clickhouse-client or another TCP client.
    • client_version_minor () — Minor version of the clickhouse-client or another TCP client.
    • client_version_patch () — Patch component of the clickhouse-client 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.
    • http_user_agent (String) — The UserAgent header passed in the HTTP request.
    • quota_key () — The “quota key” specified in the quotas setting (see keyed).
    • revision () — ClickHouse revision.
    • ProfileEvents.Names (Array(String)) — Counters that measure different metrics for this thread. The description of them could be found in the table .
    • ProfileEvents.Values (Array(UInt64)) — Values of metrics for this thread that are listed in the ProfileEvents.Names column.

    Example

    1. Row 1:
    2. ──────
    3. event_date: 2020-09-11
    4. event_time: 2020-09-11 10:08:17
    5. event_time_microseconds: 2020-09-11 10:08:17.134042
    6. query_start_time: 2020-09-11 10:08:17
    7. query_start_time_microseconds: 2020-09-11 10:08:17.063150
    8. query_duration_ms: 70
    9. read_rows: 0
    10. read_bytes: 0
    11. written_bytes: 12
    12. peak_memory_usage: 4300844
    13. thread_name: TCPHandler
    14. thread_id: 638133
    15. master_thread_id: 638133
    16. query: INSERT INTO test1 VALUES
    17. is_initial_query: 1
    18. user: default
    19. query_id: 50a320fd-85a8-49b8-8761-98a86bcbacef
    20. address: ::ffff:127.0.0.1
    21. port: 33452
    22. initial_user: default
    23. initial_query_id: 50a320fd-85a8-49b8-8761-98a86bcbacef
    24. initial_address: ::ffff:127.0.0.1
    25. initial_port: 33452
    26. interface: 1
    27. os_user: bharatnc
    28. client_hostname: tower
    29. client_name: ClickHouse
    30. client_revision: 54437
    31. client_version_major: 20
    32. client_version_minor: 7
    33. client_version_patch: 2
    34. http_method: 0
    35. http_user_agent:
    36. quota_key:
    37. revision: 54440
    38. ProfileEvents.Names: ['Query','InsertQuery','FileOpen','WriteBufferFromFileDescriptorWrite','WriteBufferFromFileDescriptorWriteBytes','ReadCompressedBytes','CompressedReadBufferBlocks','CompressedReadBufferBytes','IOBufferAllocs','IOBufferAllocBytes','FunctionExecute','CreatedWriteBufferOrdinary','DiskWriteElapsedMicroseconds','NetworkReceiveElapsedMicroseconds','NetworkSendElapsedMicroseconds','InsertedRows','InsertedBytes','SelectedRows','SelectedBytes','MergeTreeDataWriterRows','MergeTreeDataWriterUncompressedBytes','MergeTreeDataWriterCompressedBytes','MergeTreeDataWriterBlocks','MergeTreeDataWriterBlocksAlreadySorted','ContextLock','RWLockAcquiredReadLocks','RealTimeMicroseconds','UserTimeMicroseconds','SoftPageFaults','OSCPUVirtualTimeMicroseconds','OSWriteBytes','OSReadChars','OSWriteChars']
    • — Description of the query_log system table which contains common information about queries execution.

    Original article