跳转到主要内容
在 ClickHouse Cloud 中查询此系统表中的数据分别保存在 ClickHouse Cloud 各节点的本地。因此,如需查看所有数据的完整情况,需要使用 clusterAllReplicas 函数。更多详情请参见此处

描述

包含执行查询的线程相关信息,例如线程名称、线程开始时间以及查询处理耗时。 要开始记录日志:
  1. query_thread_log 部分中配置参数。
  2. log_query_threads 设置为 1。
数据刷新周期通过 query_thread_log 服务器设置部分中的 flush_interval_milliseconds 参数进行设置。要强制刷新,请使用 SYSTEM FLUSH LOGS 查询。 ClickHouse 不会自动删除表中的数据。更多详情,请参见 Introduction 你可以使用 log_queries_probability) 设置来减少记录到 query_thread_log 表中的查询数量。

  • hostname (LowCardinality(String)) — 执行该查询的服务器主机名。
  • event_date (Date) — 线程执行完查询时的日期。
  • event_time (DateTime) — 线程执行完查询时的日期和时间。
  • event_time_microseconds (DateTime64(6)) — 线程完成查询执行时的日期和时间,精度为微秒。
  • query_start_time (DateTime) — 查询开始执行的时间。
  • query_start_time_microseconds (DateTime64(6)) — 查询开始执行的时间,精确到微秒。
  • query_duration_ms (UInt64) — 查询执行耗时。
  • read_rows (UInt64) — 读取的行数。
  • read_bytes (UInt64) — 已读取的字节数。
  • written_rows (UInt64) — 对于 INSERT 查询,表示已写入的行数。对于其他查询,该列的值为 0。
  • written_bytes (UInt64) — 对于 INSERT 查询,表示已写入的字节数。对于其他查询,此列的值为 0。
  • memory_usage (Int64) — 在该线程的上下文中,已分配内存量与已释放内存量之间的差值。
  • peak_memory_usage (Int64) — 该线程上下文中已分配内存与已释放内存之间的最大差值。
  • thread_name (LowCardinality(String)) — 线程名称。
  • thread_id (UInt64) — 内部线程 ID。
  • master_thread_id (UInt64) — 初始线程的操作系统初始 ID。
  • current_database (LowCardinality(String)) — 当前 database 的名称。
  • query (String) — 查询字符串。
  • normalized_query_hash (UInt64) — 归一化查询的哈希值——其中的常量等已被去除。
  • is_initial_query (UInt8) — 查询类型。可能的值:1 — 查询由客户端发起,0 — 查询由另一个查询为进行分布式查询执行而发起。
  • connection_address (IPv6) — 建立 connection 的客户端 IP 地址。若通过 proxy 连接,则此地址为 proxy 的地址。
  • connection_port (UInt16) — 建立 connection 时使用的客户端端口。若通过 proxy 连接,此处显示的将是 proxy 的端口。
  • user (LowCardinality(String)) — 发起当前查询的用户名。
  • query_id (String) — 查询 ID。
  • address (IPv6) — 用于发起查询的 IP 地址。若通过代理连接且设置了 auth_use_forwarded_address,此处显示的是客户端地址,而非代理地址。
  • port (UInt16) — 用于发起查询的客户端端口。若通过代理连接,且设置了 auth_use_forwarded_address,这里显示的将是客户端端口,而不是代理端口。
  • initial_user (LowCardinality(String)) — 执行初始查询的用户名 (用于分布式查询执行) 。
  • initial_query_id (String) — 初始查询 ID (用于分布式查询执行) 。
  • initial_address (IPv6) — 发起父查询的 IP 地址。
  • initial_port (UInt16) — 用于发起父级查询的客户端端口。
  • initial_query_start_time (DateTime) — 初始查询的执行开始时间。
  • initial_query_start_time_microseconds (DateTime64(6)) — 初始查询开始执行的时间
  • authenticated_user (LowCardinality(String)) — 会话中已通过身份验证的用户名。
  • interface (UInt8) — 发起查询所使用的接口。可能的值:1 — TCP,2 — HTTP。
  • is_secure (UInt8) — 用于指示连接是否安全的标志。
  • os_user (LowCardinality(String)) — 运行 clickhouse-client 的操作系统用户名称。
  • client_hostname (LowCardinality(String)) — 运行 clickhouse-client 或其他 TCP 客户端的客户机主机名。
  • client_name (LowCardinality(String)) — clickhouse-client 或其他 TCP 客户端名称。
  • client_revision (UInt32) — clickhouse-client 或其他 TCP 客户端的修订号。
  • client_version_major (UInt32) — clickhouse-client 或其他 TCP 客户端的主版本。
  • client_version_minor (UInt32) — clickhouse-client 或其他 TCP 客户端的次要版本号。
  • client_version_patch (UInt32) — clickhouse-client 或其他 TCP 客户端版本号的补丁部分。
  • script_query_number (UInt32) — 多查询脚本中的顺序查询编号。
  • script_line_number (UInt32) — 多查询脚本中当前查询起始所在的行号。
  • http_method (UInt8) — 发起该查询时使用的 HTTP 方法。可能的值:0 — 查询通过 TCP 接口发起,1 — 使用 GET 方法,2 — 使用 POST 方法。
  • http_user_agent (LowCardinality(String)) — HTTP 请求中的 UserAgent 请求头。
  • http_referer (String) — 在 HTTP 查询中传递的 Referer HTTP 请求头 (包含发起该查询的页面的完整地址或部分地址) 。
  • forwarded_for (String) — 在 HTTP 查询中传递的 X-Forwarded-For HTTP 请求头。
  • quota_key (String) — quotas 设置中指定的“配额键”。
  • distributed_depth (UInt64) — 查询在服务器之间被转发的次数。
  • revision (UInt32) — ClickHouse 修订号。
  • ProfileEvents (Map(LowCardinality(String), UInt64)) — 用于统计该线程各项指标的 ProfileEvents。其说明可在 system.events 表中找到。
别名:
  • ProfileEvents.NamesmapKeys(ProfileEvents) 的别名。
  • ProfileEvents.ValuesmapValues(ProfileEvents) 的别名。

示例

 SELECT * FROM system.query_thread_log LIMIT 1 \G
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}

另请参阅

最后修改于 2026年6月10日