You need to enable JavaScript to run this app.
导航
query_log
最近更新时间:2025.07.02 15:12:58首次发布时间:2025.07.02 15:12:58
我的收藏
有用
有用
无用
无用

系统表 system.query_log 包含已执行查询的信息,例如开始时间、处理持续时间、错误消息等。

列名

字段名称

数据类型

字段含义说明

type

Enum8('QueryStart' = 1, 'QueryFinish' = 2, 'ExceptionBeforeStart' = 3, 'ExceptionWhileProcessing' = 4)

执行查询时发生的事件的类型。

  • 'QueryStart'=1:查询执行成功开始。
  • 'QueryFinish'=2:查询执行成功结束。
  • 'ExceptionBeforeStart'=3:查询执行开始前异常。
  • 'ExceptionWhileProcessing'=4:查询执行期间异常。

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。

result_rows

UInt64

SELECT查询结果集的行数;或INSERT查询实际写入的行数。

result_bytes

UInt64

存储查询结果所占用的内存字节数。

memory_usage

UInt64

优化器 mpp 执行链路下,该参数指单个 segement 的内存占用。
对于非优化器执行链路,该参数指单个查询的内存占用。

query_memory_usage

UInt64

优化器链路 mpp 执行模式,默认配置 exchange_use_query_memory_tracker=1,query_memory_usage 记录了当前 segment 退出前,当前节点所有 sgement 相加的峰值。

total_cpu_seconds

Float64

查询语句总使用 CPU 时间,单位秒。

io_wait_seconds

Float64

查询语句 IO 等待时间,单位秒

current_database

String

当前连接的数据库名称。

query

String

原始查询语句。

normalized_query_hash

UInt64

查询语句 Hash 指纹。

query_kind

LowCardinality(String)

查询类型。

databases

Array(LowCardinality(String))

查询中存在的数据库的名称。

tables

Array(LowCardinality(String))

查询中存在的表的名称。

columns

Array(LowCardinality(String))

查询中存在的列的名称。

projections

Array(LowCardinality(String))

查询执行期间使用的投影的名称。

materialized_views

Array(LowCardinality(String))

查询执行期间使用的视图或物化视图的名称。

exception_code

Int32

异常代码。

exception

String

异常信息。

stack_trace

String

查询堆栈跟踪信息。如果查询成功完成,则为空字符串。

is_initial_query

UInt8

查询发起类型。如下值:

  • 1:查询由客户端发起。
  • 0:查询由另一个查询发起,作为分布式查询执行的一部分。

user

String

发起当前查询的用户的名称。

query_id

String

查询语句 ID。

address

IPv6

查询发起的 IP 地址。

port

UInt16

发起查询的客户端端口。

initial_user

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)

微秒精度的初始查询开始时间(用于分布式查询执行)。

interface

UInt8

发起查询的接口类型。如下值:

  • 1:TCP。
  • 2:HTTP。

os_user

String

运行client的操作系统用户名。

client_hostname

String

运行 ByteHouse 客户端或其他 TCP 客户端的客户端计算机的主机名。

client_name

String

ByteHouse 客户端或其他 TCP 客户端名称。

client_revision

UInt32

ByteHouse 客户端或其他 TCP 客户端的版本。

client_version_major

UInt32

ByteHouse 客户端或其他 TCP 客户端的主版本。

client_version_minor

UInt32

ByteHouse 客户端或其他TCP客 客户端的次要版本。

client_version_patch

UInt32

ByteHouse 客户端或其他 TCP 客户端版本的补丁组件版本

http_method

UInt8

启动查询的 HTTP 方法。如下值:

  • 0:查询是从 TTCP接口启动的。
  • 1:使用 GET 方法。
  • 2:使用 POST 方法。

http_user_agent

String

以 HTTP 请求头 UserAgent 信息。

http_referer

String

以 HTTP 请求头 Referer 信息(包含进行查询的页面的绝对或部分地址)。

forwarded_for

String

以 HTTP 请求头 X-Forwarded-For 的信息。

quota_key

String

配额设置中指定的配额键。

revision

UInt32

引擎内部版本号。

log_comment

String

日志注释。它可以设置为不超过 mmax_query_size 的任意字符串。如果未定义,则为空字符串。

thread_ids

Array(UInt64)

参与查询执行的线程 ID。

ProfileEvents

Map(String, UInt64)

关于查询测量指标。具体描述可以在表 system.events 中找到。

ProfileEventsTimeline

Map(String, UInt64)

用于记录查询相关事件的时间线信息。

Settings

Map(String, String)

运行查询时使用到设置参数。

Graphviz

Map(String, String)

当配置了 print_graph=1 时,存储优化器链路查询计划Graphviz 点字符串。

used_aggregate_functions

Array(String)

查询执行期间使用的聚合函数名称。

used_aggregate_function_combinators

Array(String)

查询执行期间使用的聚合函数组合器的规范名称。

used_database_engines

Array(String)

在查询执行期间使用的数据库引擎名称

used_data_type_families

Array(String)

在查询执行期间使用的数据类型名称。

used_dictionaries

Array(String)

在查询执行期间使用的字典名称。

used_formats

Array(String)

在查询执行期间使用的格式名称。

used_functions

Array(String)

在查询执行期间使用的函数名称。

used_storages

Array(String)

在查询执行期间使用的存储名称。

used_table_functions

Array(String)

在查询执行期间使用表函数名称。

partition_ids

Array(String)

当配置了 log_queries_with_partition_ids=1,记录当前query 查询到的表分区 ID。

segment_id

Int64

优化器链路 mpp 执行模式,当前 query 对应的执行segment id。

segment_parallel

Int64

segment 实例数量。

segment_parallel_index

Int64

segment 实例编号。

resource_group

String

在查询执行期间使用资源组名称。

fallback_reason

String

优化器链路 mpp 执行模式回退原因。

query_plan

String

JSON 格式的优化器链路查询计划

segment_profile

Array(String)

优化器执行链路下,配置 log_segment_profiles=1 时记录的 segment 的计划和执行耗时。

session_id

String

会话(session) ID。

示例

SELECT * FROM system.query_log LIMIT 1;
Row 1:
──────
type:                                  QuerySatrt      
event_date:                             2025-06-09     
event_time:                             2025-06-09 14:05:17       
event_time_microseconds:                2025-06-09 14:05:17.230230      
query_start_time:                       2025-06-09 14:05:17       
query_start_time_microseconds:          2025-06-09 14:05:17.230230      
query_duration_ms:                      0    
read_rows:                              0        
read_bytes:                             0        
written_rows:                           0      
written_bytes:                          0       
result_rows:                            0       
result_bytes:                           0       
memory_usage:                           0        
query_memory_usage:                     0    
total_cpu_seconds:                      0    
io_wait_seconds:                        0    
current_database:                       default     
query:                                  select count(1) + 123456788     
normalized_query_hash:                  9580075159047059276   
query_kind:                             Select     
databases:                              []    
tables:                                 []       
columns:                                []        
projections:                            []       
materialized_views:                     []       
exception_code:                         0    
exception:        
stack_trace:      
is_initial_query:                       1       
user:                                   default        
query_id:                               a4789c7d-edf8-44b2-97d2-05af0eaccc03       
address:                                ::ffff:127.0.0.1       
port:                                   34956        
initial_user:                           default        
initial_query_id:                       a4789c7d-edf8-44b2-97d2-05af0eaccc03      
initial_address:                        ::ffff:127.0.0.1        
initial_port:                           34956       
initial_query_start_time:               2025-06-09 14:05:17      
initial_query_start_time_microseconds:  2025-06-09 14:05:17.230230   
interface:                              1       
os_user:        
client_hostname:                        iv-ydxo6kp1j4xjd1tibrju       
client_name:                            ClickHouse       
client_revision:                        54465        
client_version_major:                   21        
client_version_minor:                   9        
client_version_patch:                   1     
http_method:                            0        
http_user_agent:        
http_referer:       
forwarded_for:        
quota_key:        
revision:                               54454       
log_comment:        
thread_ids:                             []        
ProfileEvents:                          {}        
ProfileEventsTimeline:                  {}       
Settings:                               { "allow_strict_resize": "0", "background_pool_size": "16", "background_schedule_pool_size": "16", "connect_timeout_with_failover_ms": "1000", "distributed_aggregation_memory_efficient": "0", "distributed_product_mode": "allow", "enable_eliminate_complicated_pk_fk_join": "1", "enable_eliminate_complicated_pk_fk_join_without_top_join": "1", "enable_eliminate_join_by_fk": "1", "enable_evaluate_constant_for_nondeterministic": "0", "enable_group_by_keys_pruning": "1", "enable_merge_scheduler": "0", "enable_new_ann": "1", "enable_optimizer": "1", "enable_plan_cache": "1", "enable_sharding_optimize": "0", "enable_uncompressed_cache_shard_mode": "1", "enable_windows_parallel": "1", "enable_zero_copy_read": "1", "exchange_enable_block_compress": "1", "exchange_enable_multipath_reciever": "0", "exchange_multi_path_receiver_queue_size": "20000", "exchange_remote_receiver_queue_size": "4000", "exchange_source_pipeline_threads": "32", "exchange_unordered_output_parallel_size": "16", "force_manipulate_materialize_mysql_table": "1", "input_format_skip_unknown_fields": "1", "insert_distributed_sync": "1", "join_algorithm": "parallel_hash", "local_filesystem_read_method": "pread", "log_processors_profiles": "0", "log_queries": "1", "log_query_threads": "0", "materialize_ttl_after_modify": "0", "max_block_size": "65536", "max_execution_time": "300", "max_insert_block_size": "1048576", "max_insert_block_size_bytes": "0", "max_memory_usage": "39084202393", "max_memory_usage_for_all_queries": "39084202393", "max_memory_usage_for_user": "39084202393", "max_partitions_per_insert_block": "1000", "max_query_size": "1048576", "max_rows_to_schedule_merge": "500000000", "max_threads": "32", "merge_tree_max_bytes_to_use_cache": "13743895347", "merge_tree_max_rows_to_use_cache": "1000000000000", "parallel_join_threshold": "900000", "queue_max_wait_ms": "100000", "receive_timeout": "1000000", "rewrite_complex_predicate_by_domain": "1", "slow_query_ms": "0", "strict_rows_to_schedule_merge": "50000000", "timeout_before_checking_execution_speed": "0", "total_rows_to_schedule_merge": "0", "use_uncompressed_cache": "1" }  
Graphviz:                               {}      
used_aggregate_functions:               []       
used_aggregate_function_combinators:    []         
used_database_engines:                  []            
used_data_type_families:                []            
used_dictionaries:                      []            
used_formats:                           []            
used_functions:                         []            
used_storages:                          []            
used_table_functions:                   []            
partition_ids:                          []            
segment_id:                             0       
segment_parallel:                       1       
segment_parallel_index:                 1        
resource_group:        
fallback_reason:       
query_plan:      
segment_profiles:                       []  
session_id: