Help wanted!

The following content of this documentation page has been machine-translated. But unlike other websites, it is not done on the fly. This translated text lives on GitHub repository alongside main ClickHouse codebase and waits for fellow native speakers to make it more human-readable. You can also use the original English version as a reference.

Help ClickHouse documentation by editing this page

系统。query_log

包含有关已执行查询的信息,例如,开始时间、处理持续时间、错误消息。

此表不包含以下内容的摄取数据 INSERT 查询。

您可以更改查询日志记录的设置 query_log 服务器配置部分。

您可以通过设置禁用查询日志记录 log_queries=0. 我们不建议关闭日志记录,因为此表中的信息对于解决问题很重要。

数据的冲洗周期设置在 flush_interval_milliseconds 的参数 query_log 服务器设置部分。 要强制冲洗,请使用 SYSTEM FLUSH LOGS 查询。

ClickHouse不会自动从表中删除数据。 看 导言 欲了解更多详情。

system.query_log 表注册两种查询:

  1. 客户端直接运行的初始查询。
  2. 由其他查询启动的子查询(用于分布式查询执行)。 对于这些类型的查询,有关父查询的信息显示在 initial_* 列。

每个查询创建一个或两个行中 query_log 表,这取决于状态(见 type 列)的查询:

  1. 如果查询执行成功,则两行具有 QueryStartQueryFinish 创建类型。
  2. 如果在查询处理过程中发生错误,两个事件与 QueryStartExceptionWhileProcessing 创建类型。
  3. 如果在启动查询之前发生错误,则单个事件具有 ExceptionBeforeStart 创建类型。

列:

  • type (枚举8) — Type of an event that occurred when executing the query. Values:
    • 'QueryStart' = 1 — Successful start of query execution.
    • 'QueryFinish' = 2 — Successful end of query execution.
    • 'ExceptionBeforeStart' = 3 — Exception before the start of query execution.
    • 'ExceptionWhileProcessing' = 4 — Exception during the query execution.
  • event_date (日期) — Query starting date.
  • event_time (日期时间) — Query starting time.
  • query_start_time (日期时间) — Start time of query execution.
  • query_duration_ms (UInt64) — Duration of query execution in milliseconds.
  • read_rows (UInt64) — Total number or rows read from all tables and table functions participated in query. It includes usual subqueries, subqueries for INJOIN. 对于分布式查询 read_rows 包括在所有副本上读取的行总数。 每个副本发送它的 read_rows 值,并且查询的服务器-发起方汇总所有接收到的和本地的值。 缓存卷不会影响此值。
  • read_bytes (UInt64) — Total number or bytes read from all tables and table functions participated in query. It includes usual subqueries, subqueries for INJOIN. 对于分布式查询 read_bytes 包括在所有副本上读取的行总数。 每个副本发送它的 read_bytes 值,并且查询的服务器-发起方汇总所有接收到的和本地的值。 缓存卷不会影响此值。
  • written_rows (UInt64) — For INSERT 查询,写入的行数。 对于其他查询,列值为0。
  • written_bytes (UInt64) — For INSERT 查询时,写入的字节数。 对于其他查询,列值为0。
  • result_rows (UInt64) — Number of rows in a result of the SELECT 查询,或者在一些行 INSERT 查询。
  • result_bytes (UInt64) — RAM volume in bytes used to store a query result.
  • memory_usage (UInt64) — Memory consumption by the query.
  • query (字符串) — Query string.
  • exception (字符串) — Exception message.
  • exception_code (Int32) — Code of an exception.
  • stack_trace (字符串) — 堆栈跟踪. 如果查询成功完成,则为空字符串。
  • is_initial_query (UInt8) — Query type. Possible values:
    • 1 — Query was initiated by the client.
    • 0 — Query was initiated by another query as part of distributed query execution.
  • user (字符串) — Name of the user who initiated the current query.
  • query_id (字符串) — ID of the query.
  • address (IPv6) — 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 (字符串) — ID of the initial query (for distributed query execution).
  • initial_address (IPv6) — IP address that the parent query was launched from.
  • initial_port (UInt16) — The client port that was used to make the parent query.
  • interface (UInt8) — Interface that the query was initiated from. Possible values:
    • 1 — TCP.
    • 2 — HTTP.
  • os_user (字符串) — Operating system username who runs ツ环板clientョツ嘉ッツ偲.
  • client_hostname (字符串) — Hostname of the client machine where the ツ环板clientョツ嘉ッツ偲 或者运行另一个TCP客户端。
  • client_name (字符串) — The ツ环板clientョツ嘉ッツ偲 或另一个TCP客户端名称。
  • client_revision (UInt32) — Revision of the ツ环板clientョツ嘉ッツ偲 或另一个TCP客户端。
  • client_version_major (UInt32) — Major version of the ツ环板clientョツ嘉ッツ偲 或另一个TCP客户端。
  • client_version_minor (UInt32) — Minor version of the ツ环板clientョツ嘉ッツ偲 或另一个TCP客户端。
  • client_version_patch (UInt32) — Patch component of the ツ环板clientョツ嘉ッツ偲 或另一个TCP客户端版本。
  • http_method (UInt8) — HTTP method that initiated the query. Possible values:
    • 0 — The query was launched from the TCP interface.
    • 1 — GET 方法被使用。
    • 2 — POST 方法被使用。
  • http_user_agent (字符串) — The UserAgent http请求中传递的标头。
  • quota_key (字符串) — The “quota key” 在指定 配额 设置(见 keyed).
  • revision (UInt32) — ClickHouse revision.
  • thread_numbers (数组(UInt32)) — Number of threads that are participating in query execution.
  • ProfileEvents.Names (数组(字符串)) — Counters that measure different metrics. The description of them could be found in the table 系统。活动
  • ProfileEvents.Values (数组(UInt64)) — Values of metrics that are listed in the ProfileEvents.Names 列。
  • Settings.Names (数组(字符串)) — Names of settings that were changed when the client ran the query. To enable logging changes to settings, set the log_query_settings 参数为1。
  • Settings.Values (数组(字符串)) — Values of settings that are listed in the Settings.Names 列。

示例

  1. SELECT * FROM system.query_log LIMIT 1 FORMAT Vertical;
  1. Row 1:
  2. ──────
  3. type: QueryStart
  4. event_date: 2020-05-13
  5. event_time: 2020-05-13 14:02:28
  6. query_start_time: 2020-05-13 14:02:28
  7. query_duration_ms: 0
  8. read_rows: 0
  9. read_bytes: 0
  10. written_rows: 0
  11. written_bytes: 0
  12. result_rows: 0
  13. result_bytes: 0
  14. memory_usage: 0
  15. query: SELECT 1
  16. exception_code: 0
  17. exception:
  18. stack_trace:
  19. is_initial_query: 1
  20. user: default
  21. query_id: 5e834082-6f6d-4e34-b47b-cd1934f4002a
  22. address: ::ffff:127.0.0.1
  23. port: 57720
  24. initial_user: default
  25. initial_query_id: 5e834082-6f6d-4e34-b47b-cd1934f4002a
  26. initial_address: ::ffff:127.0.0.1
  27. initial_port: 57720
  28. interface: 1
  29. os_user: bayonet
  30. client_hostname: clickhouse.ru-central1.internal
  31. client_name: ClickHouse client
  32. client_revision: 54434
  33. client_version_major: 20
  34. client_version_minor: 4
  35. client_version_patch: 1
  36. http_method: 0
  37. http_user_agent:
  38. quota_key:
  39. revision: 54434
  40. thread_ids: []
  41. ProfileEvents.Names: []
  42. ProfileEvents.Values: []
  43. Settings.Names: ['use_uncompressed_cache','load_balancing','log_queries','max_memory_usage']
  44. Settings.Values: ['0','random','1','10000000000']

另请参阅