ByteHouse 云数仓版为您提供SQL审计能力,为您提供界面化查看SQL执行日志的功能,同时为您提供详细SQL日志表,打开详细日志开关后即可查看对应详细SQL日志表数据进一步查看更细致的日志数据。本文为您介绍ByteHouse的SQL审计能力。
通过 “ByteHouse 控制台-审计日志-SQL 审计” 页面,您可以查询到执行 SQL 的历史日志。
注意
当我们为您的账号加白后,您可以在SQL审计页面的右上角打开开启详细日志开关,打开后,ByteHouse会为您在系统中创建一个query_log的表,用于写入详细的SQL执行日志数据。
警告
由于ByteHouse将您执行的SQL日志信息持续写入到bh_system.query_log表中;对于该表的增删改操作将会影响日志写入,请与ByteHouse同学确认后再执行此类操作;
列名 | 数据类型 | 字段描述 |
---|---|---|
type | Enum8,枚举值包括:
| 查询事件类型:
|
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操作) |
written_bytes | UInt64 | 写入的字节数(仅INSERT操作) |
result_rows | UInt64 | 返回结果的行数 |
result_bytes | UInt64 | 返回结果的字节数 |
memory_usage | UInt64 | 查询在每个worker,每个segment上使用的最高内存用量 |
current_database | String | 当前数据库 |
query | String | 完整的查询语句 |
normalized_query_hash | UInt64 | 规范化查询哈希值 |
query_kind | String | 查询类型(如 |
databases | Array(String) | 查询涉及到的数据库 |
tables | Array(String) | 查询涉及到的数据表 |
columns | Array(String) | 查询涉及到的数据表字段 |
partition_ids | Array(String) | 分区 |
projections | Array(String) | 查询涉及的投影(Projection)名称列表 |
materialized_views | Array(String) | 查询涉及的物化视图名称列表 |
exception_code | Int32 | 异常代码(仅当 |
exception | String | 异常信息(错误消息) |
stack_trace | String | 异常堆栈跟踪信息(需配置 |
is_initial_query | UInt8 | 是否为初始查询(0:子查询;1:用户直接发起的查询) |
user | String | 用户名 |
query_id | String | 查询ID |
interface | UInt8 | 发起查询的接口. 可能的值:
|
os_user | String | 运行客户端的操作系统用户 |
client_hostname | String | 客户端主机名 |
client_name | String | 客户端名称 |
client_revision | UInt32 | 客户端版本 |
client_version_major | UInt32 | 客户端主版本 |
client_version_minor | UInt32 | 客户端次版本号 |
client_version_patch | UInt32 | 客户端补丁版本 |
http_method | UInt8 | 发起查询的HTTP方法. 可能值: |
http_user_agent | String | 客户端的User-Agent信息 |
http_referer | String | HTTP 来源信息 |
forwarded_for | String | HTTP代理链中的客户端IP |
quota_key | String | 配额键 |
revision | UInt32 | |
ProfileEvents | Map(String, UInt64) | PrunedPartitions:
TotalPartitions:
TotalCPUTimeMs:
|
Settings | Map(String, String) | 查询生效的配置参数(覆盖默认值的部分) |
log_comment | String | 日志注释 |
thread_ids | Array(UInt64) | 参与查询的线程ID列表 |
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) | 使用数据格式参数(如:FORMAT CSV) |
used_functions | Array(String) | 使用的函数 |
used_storages | Array(String) | 使用的存储 |
used_table_functions | Array(String) | 使用的表函数 |
virtual_warehouse | String | 查询使用的计算组 |
query_plan | String | 查询的执行计划 |
字段名 | 数据类型 |
---|---|
type | Enum8 |
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 |
written_bytes | UInt64 |
result_rows | UInt64 |
result_bytes | UInt64 |
memory_usage | UInt64 |
current_database | String |
query | String |
normalized_query_hash | UInt64 |
query_kind | String |
databases | Array(String) |
tables | Array(String) |
columns | Array(String) |
partition_ids | Array(String) |
projections | Array(String) |
materialized_views | Array(String) |
exception_code | Int32 |
exception | String |
stack_trace | String |
is_initial_query | UInt8 |
user | String |
query_id | String |
interface | UInt8 |
os_user | String |
client_hostname | String |
client_name | String |
client_revision | UInt32 |
client_version_major | UInt32 |
client_version_minor | UInt32 |
client_version_patch | UInt32 |
http_method | UInt8 |
http_user_agent | String |
http_referer | String |
forwarded_for | String |
quota_key | String |
revision | UInt32 |
ProfileEvents | Map(String, UInt64) |
Settings | Map(String, String) |
log_comment | String |
thread_ids | Array(UInt64) |
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) |
virtual_warehouse | String |
query_plan | String |
字段名 | 数据类型 |
---|---|
type | Enum8 |
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 |
written_bytes | UInt64 |
result_rows | UInt64 |
result_bytes | UInt64 |
memory_usage | UInt64 |
current_database | String |
query | String |
normalized_query_hash | UInt64 |
query_kind | String |
databases | Array(String) |
tables | Array(String) |
columns | Array(String) |
partition_ids | Array(String) |
projections | Array(String) |
materialized_views | Array(String) |
exception_code | Int32 |
exception | String |
stack_trace | String |
is_initial_query | UInt8 |
user | String |
query_id | String |
interface | UInt8 |
os_user | String |
client_hostname | String |
client_name | String |
client_revision | UInt32 |
client_version_major | UInt32 |
client_version_minor | UInt32 |
client_version_patch | UInt32 |
http_method | UInt8 |
http_user_agent | String |
http_referer | String |
forwarded_for | String |
quota_key | String |
revision | UInt32 |
ProfileEvents | Map(String, UInt64) |
Settings | Map(String, String) |
log_comment | String |
thread_ids | Array(UInt64) |
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) |
virtual_warehouse | String |
query_plan | String |