altinity-expert-clickhouse-memory
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMemory Usage and OOM Diagnostics
内存使用与OOM诊断
Diagnose RAM usage, memory pressure, OOM risks, and memory allocation patterns.
诊断内存使用情况、内存压力、OOM风险以及内存分配模式。
Diagnostics
诊断步骤
Run all queries from the file checks.sql and analyze the results.
运行checks.sql文件中的所有查询并分析结果。
Problem Investigation
问题排查
High Memory from Aggregations
聚合操作导致内存占用过高
Solutions:
- Add
max_bytes_before_external_group_by - Use pragma to limit parallelism
max_threads - Restructure query to reduce group by cardinality
解决方案:
- 添加参数
max_bytes_before_external_group_by - 使用编译指令限制并行度
max_threads - 重构查询以降低分组的基数
High Memory from JOINs
JOIN操作导致内存占用过高
Solutions:
- Use
max_bytes_in_join - Consider or
join_algorithm = 'partial_merge''auto' - Ensure smaller table on right side
解决方案:
- 使用参数
max_bytes_in_join - 考虑设置或
join_algorithm = 'partial_merge''auto' - 确保较小的表位于右侧
Ad-Hoc Query Guidelines
临时查询指南
Required Safeguards
必要的安全措施
sql
-- Always time-bound log queries
where event_date >= today() - 1
-- Limit results
limit 100sql
-- 始终添加时间范围限制日志查询
where event_date >= today() - 1
-- 限制结果数量
limit 100Memory-Related Metrics
内存相关指标
- - current tracked memory
MemoryTracking - - RSS
MemoryResident - ,
OSMemoryTotal- system memoryOSMemoryFreeWithoutCached
- - 当前已追踪的内存
MemoryTracking - - 常驻内存集(RSS)
MemoryResident - ,
OSMemoryTotal- 系统内存OSMemoryFreeWithoutCached
Cross-Module Triggers
跨模块触发条件
| Finding | Load Module | Reason |
|---|---|---|
| High merge memory | | Analyze merge patterns |
| Large dictionaries | | Dictionary optimization |
| Cache too large | | Cache sizing |
| PK memory high | | ORDER BY optimization |
| Query OOMs | | Query optimization |
| 发现的问题 | 加载模块 | 原因 |
|---|---|---|
| 合并操作内存占用过高 | | 分析合并模式 |
| 字典体积过大 | | 字典优化 |
| 缓存体积过大 | | 缓存大小调整 |
| 主键内存占用过高 | | ORDER BY优化 |
| 查询出现OOM | | 查询优化 |
Settings Reference
配置参数参考
| Setting | Scope | Notes |
|---|---|---|
| Query | Per-query limit |
| User | Per-user aggregate |
| Server | Global limit |
| Server | Auto-limit as % of RAM |
| Query | Spill aggregation to disk |
| Query | Spill join to disk |
| 参数 | 作用范围 | 说明 |
|---|---|---|
| 查询 | 单查询内存限制 |
| 用户 | 单个用户的总内存限制 |
| 服务器 | 全局内存限制 |
| 服务器 | 按内存占比自动设置限制 |
| 查询 | 将聚合操作溢出到磁盘 |
| 查询 | 将JOIN操作溢出到磁盘 |