clickhouse 异常提示 DB::Exception: Memory limit (total) exceeded
|
1
2
3
4
5
6
7
8
|
# clickhouse-clientClickHouse client version 24.9.2.42 (official build).Connecting to localhost:9000 as user default.Password for user (default):Connecting to localhost:9000 as user default.Connected to ClickHouse server version 24.9.2.cluster_1S_2R node 2 :) Cannot load data for command line suggestions: Code: 241. DB::Exception: Received from localhost:9000. DB::Exception: Memory limit (total) exceeded: would use 7.72 GiB (attempt to allocate chunk of 4641312 bytes), current RSS 1.10 GiB, maximum: 6.96 GiB. OvercommitTracker decision: Query was selected to stop by OvercommitTracker.. (MEMORY_LIMIT_EXCEEDED) (version 24.9.2.42 (official build)) |
与内存设置相关的参数主要有:
|
1
2
3
4
|
·max_server_memory_usage·max_server_memory_usage_to_ram_ratio·max_memory_usage·max_memory_usage_for_user |
max_server_memory_usage
指定了clickhouse 可以使用的最大内存,默认值是 0。如果设置成 0 值或者没有设置,表示默认无限制。默认的 max_server_memory_usage 值计算公式为:
|
1
|
memory_amount * max_server_memory_usage_to_ram_ratio |
max_server_memory_usage_to_ram_ratio
与 max_server_memory_usage 相同,但与物理内存成比例。零表示无限制。
如果设置成 0 ,表示无限制,默认值是 0.9。在内存和交换容量较小的主机上,可能需要将max_server_memory_usage_to_ram_ratio设置得大于 1。
max_memory_usage
表示在单个 clickhouse server 中运行一个查询可以使用的最大物理内存。
默认值是0,表示没有限制。
该参数的设置没有考虑可用内存或机器总内存的大小。限制只是应用于单个clickhouse server上的单个查询。可以使用SHOW PROCESSLIST查看每个查询的当前内存消耗。此外,每次查询的内存消耗峰值都会被跟踪并写入日志。
某些聚合函数的状态不会受到内存使用情况的监控。
对于来自字符串和数组参数的聚合函数min、max、any、anyLast、argMin、argMax 的状态,不完全跟踪内存使用情况。
max_memory_usage_for_user
在单个服务器上运行用户查询时使用的最大内存量。默认情况下,该值不做限制(max_memory_usage_for_user = 0)。
如果要将名为clickhouse_read 的用户的max_memory_usage_for_user设置为 1000 字节,可以使用语句
|
1
|
ALTER USER clickhouse_read SETTINGS max_memory_usage_for_user = 1000; |
重新登录,然后使用getSetting函数来验证是否成功:
|
1
|
SELECT getSetting('max_memory_usage_for_user'); |
涉及的配置文件通常有两个,config.xml 和 users.xml。
其中 max_server_memory_usage 和 max_server_memory_usage_to_ram_ratio 位于配置文件 config.xml 中;max_memory_usage 和 max_memory_usage_for_user 位于配置文件 users.xml 中。
浙公网安备 33010602011771号