system.query_log

Contains information about executed queries, for example, start time, duration of processing, error messages.

Note

This table doesn’t contain the ingested data for INSERT queries.

You can change settings of queries logging in the query_log section of the server configuration.

You can disable queries logging by setting log_queries = 0. We don’t recommend to turn off logging because information in this table is important for solving issues.

The flushing period of data is set in flush_interval_milliseconds parameter of the query_log server settings section. To force flushing, use the SYSTEM FLUSH LOGS query.

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

The system.query_log table registers two kinds of queries:

  1. Initial queries that were run directly by the client.
  2. Child queries that were initiated by other queries (for distributed query execution). For these types of queries, information about the parent queries is shown in the initial_* columns.

Each query creates one or two rows in the query_log table, depending on the status (see the type column) of the query:

  1. If the query execution was successful, two rows with the QueryStart and QueryFinish types are created.
  2. If an error occurred during query processing, two events with the QueryStart and ExceptionWhileProcessing types are created.
  3. If an error occurred before launching the query, a single event with the ExceptionBeforeStart type is created.

Columns:

  • type (Enum8) — 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 (Date) — Query starting date.
  • event_time (DateTime) — Query starting time.
  • event_time_microseconds (DateTime) — Query starting time with microseconds precision.
  • query_start_time (DateTime) — Start time of query execution.
  • query_start_time_microseconds (DateTime64) — Start time of query execution with microsecond precision.
  • query_duration_ms (UInt64) — Duration of query execution in milliseconds.
  • read_rows (UInt64) — Total number of rows read from all tables and table functions participated in query. It includes usual subqueries, subqueries for IN and JOIN. For distributed queries read_rows includes the total number of rows read at all replicas. Each replica sends it’s read_rows value, and the server-initiator of the query summarizes all received and local values. The cache volumes don’t affect this value.
  • read_bytes (UInt64) — Total number of bytes read from all tables and table functions participated in query. It includes usual subqueries, subqueries for IN and JOIN. For distributed queries read_bytes includes the total number of rows read at all replicas. Each replica sends it’s read_bytes value, and the server-initiator of the query summarizes all received and local values. The cache volumes don’t affect this value.
  • written_rows (UInt64) — 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.
  • result_rows (UInt64) — Number of rows in a result of the SELECT query, or a number of rows in the INSERT query.
  • result_bytes (UInt64) — RAM volume in bytes used to store a query result.
  • memory_usage (UInt64) — Memory consumption by the query.
  • query (String) — Query string.
  • exception (String) — Exception message.
  • exception_code (Int32) — Code of an exception.
  • stack_trace (String) — Stack trace. An empty string, if the query was completed successfully.
  • 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 (String) — Name of the user who initiated the current query.
  • query_id (String) — 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 (String) — 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 (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 (String) — Operating system username who runs clickhouse-client.
  • client_hostname (String) — Hostname of the client machine where the clickhouse-client or another TCP client is run.
  • client_name (String) — The clickhouse-client or another TCP client name.
  • client_revision (UInt32) — Revision of the clickhouse-client or another TCP client.
  • client_version_major (UInt32) — Major version of the clickhouse-client or another TCP client.
  • client_version_minor (UInt32) — Minor version of the clickhouse-client or another TCP client.
  • client_version_patch (UInt32) — Patch component of the clickhouse-client or another TCP client version.
  • http_method (UInt8) — 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 (String) — The “quota key” specified in the quotas setting (see keyed).
  • revision (UInt32) — ClickHouse revision.
  • thread_numbers (Array(UInt32)) — Number of threads that are participating in query execution.
  • ProfileEvents.Names (Array(String)) — Counters that measure different metrics. The description of them could be found in the table system.events
  • ProfileEvents.Values (Array(UInt64)) — Values of metrics that are listed in the ProfileEvents.Names column.
  • Settings.Names (Array(String)) — Names of settings that were changed when the client ran the query. To enable logging changes to settings, set the log_query_settings parameter to 1.
  • Settings.Values (Array(String)) — Values of settings that are listed in the Settings.Names column.

Example

  1. SELECT * FROM system.query_log LIMIT 1 \G
  1. Row 1:
  2. ──────
  3. type: QueryStart
  4. event_date: 2020-09-11
  5. event_time: 2020-09-11 10:08:17
  6. event_time_microseconds: 2020-09-11 10:08:17.063321
  7. query_start_time: 2020-09-11 10:08:17
  8. query_start_time_microseconds: 2020-09-11 10:08:17.063321
  9. query_duration_ms: 0
  10. read_rows: 0
  11. read_bytes: 0
  12. written_rows: 0
  13. written_bytes: 0
  14. result_rows: 0
  15. result_bytes: 0
  16. memory_usage: 0
  17. current_database: default
  18. query: INSERT INTO test1 VALUES
  19. exception_code: 0
  20. exception:
  21. stack_trace:
  22. is_initial_query: 1
  23. user: default
  24. query_id: 50a320fd-85a8-49b8-8761-98a86bcbacef
  25. address: ::ffff:127.0.0.1
  26. port: 33452
  27. initial_user: default
  28. initial_query_id: 50a320fd-85a8-49b8-8761-98a86bcbacef
  29. initial_address: ::ffff:127.0.0.1
  30. initial_port: 33452
  31. interface: 1
  32. os_user: bharatnc
  33. client_hostname: tower
  34. client_name: ClickHouse
  35. client_revision: 54437
  36. client_version_major: 20
  37. client_version_minor: 7
  38. client_version_patch: 2
  39. http_method: 0
  40. http_user_agent:
  41. quota_key:
  42. revision: 54440
  43. thread_ids: []
  44. ProfileEvents.Names: []
  45. ProfileEvents.Values: []
  46. Settings.Names: ['use_uncompressed_cache','load_balancing','log_queries','max_memory_usage','allow_introspection_functions']
  47. Settings.Values: ['0','random','1','10000000000','1']

See Also

Original article