用途:面向 ClickHouse 运维与排障,提供从系统表诊断到处置建议的排查路径,覆盖内存、合并、mutation、查询失败与网络连通性。
主要能力与用法: OOM:通过 system.query_log 查看高 memory_usage,system.metrics 中 metric = 'MemoryTracking' 诊断;处置包括设置 max_memory_usage(如 10GB)、max_memory_usage_for_user,使用 max_bytes_before_external_group_by / max_bytes_before_external_sort 落盘,预过滤缩小 JOIN,用 SAMPLE 做近似聚合。 慢合并:查 system.merges 的 elapsed、progress、total_size_bytes_compressed,system.part_log 中 event_type = 'MergeParts' 看吞吐,system.asynchronous_metrics 的 max_parts_count_for_partition 判断分区过多;处置包括提高 background_pool_size(默认 16)、通过 system.asynchronous_metrics(ReadBufferFromFileDescriptorReadBytes)检查磁盘 I/O、批量更大插入、避免过度分区,必要时 OPTIMIZE TABLE ... FINAL(开销大,仅限非高峰)。 卡住的 mutation:查 system.mutations 中 is_done = 0 的 parts_to_do、latest_fail_reason;可用 KILL MUTATION WHERE mutation_id = '...' 取消,修复根因后重提,优先用 INSERT + ReplacingMergeTree 替代 UPDATE mutation。 查询失败:查 system.query_log 中 type = 'ExceptionWhileProcessing',按 exception_code 聚类统计;持久错误查 system.error_log(需启用错误日志)。常见错误码:60 表不存在、47 未知列、241 内存限制、159 超时、252 分区过多。 网络连通性:检查复制或分布式查询的节点间连通,确认 interserver_http_port 可达,可用 curl http://<peer>:9009 测试,并检查防火墙与 DNS。
限制:资料未提供安装方式、版本要求、权限前提与具体平台支持;部分诊断依赖 error logging 等配置开启。