更新时间:2024-11-29 GMT+08:00
ClickHouse客户端执行SQL查询时报内存不足问题
问题现象
ClickHouse会限制group by使用的内存量,在使用ClickHouse客户端执行SQL查询时报如下错误:
Progress: 1.83 billion rows, 85.31 GB (68.80 million rows/s., 3.21 GB/s.) 6%Received exception from server: Code: 241. DB::Exception: Received from localhost:9000, 127.0.0.1. DB::Exception: Memory limit (for query) exceeded: would use 9.31 GiB (attempt to allocate chunk of 1048576 bytes), maximum: 9.31 GiB: (while reading column hits):
解决方法
- 在执行SQL语句前,执行如下命令。注意执行前保证集群有足够内存可以设置。
SET max_memory_usage = 128000000000; #128G
- 如果没有上述大小内存可用,ClickHouse可以通过如下设置将“溢出”数据到磁盘。建议将max_memory_usage设置为max_bytes_before_external_group_by大小的两倍。
set max_bytes_before_external_group_by=20000000000; #20G set max_memory_usage=40000000000; #40G
父主题: 作业开发类