ClickHouse内存超限配置及其他配置优化

ClickHouse exception, code: 1002, host: ..., port: 8123; Code: 241. DB::Exception: Memory limit (total) exceeded: would use 3.30 GiB (attempt to allocate chunk of 607376896 bytes), maximum: 3.28 GiB: While executing FillingRightJoinSide. (MEMORY_LIMIT_EXCEEDED)

由于测试机内存太小导致查询报错,直接死机挂掉了。默认配置内存是10GB,我们把它限制下。

如果你的报错是9.31GiB,说明你的机器内存大于10G,但是查询使用的数据量超过了默认值。

解决办法:

修改用户配置文件 /etc/clickhouse-server/users.xml,可以针对不同用户修改配置,我们这里只修改默认用户(在profiles–>default标签修改):

<!-- 修改最大使用内存,这里默认单位是 bytes -->
<!-- Maximum memory usage for processing single query, in bytes. -->
<max_memory_usage>3221225472</max_memory_usage>

<!-- 设置下group by 的使用量 -->
<max_bytes_before_external_group_by>1610612736</max_bytes_before_external_group_by>

配置完记得重启服务进程。

其他配置说明

官方文档:https://clickhouse.com/docs/zh/operations/settings/query-complexity/

users.xml -> profiles -> default 标签:

<!-- 单次查询最大使用内存 Maximum memory usage for processing single query, in bytes. -->
<max_memory_usage>10000000000</max_memory_usage>
<!-- 当分组操作占用超xx时,缓存到磁盘,建议内存一半-->
<max_bytes_before_external_group_by>5000000000</max_bytes_before_external_group_by>
<!-- 当排序操作占用超xx时,缓存到磁盘,建议内存一半-->
<max_bytes_before_external_sort>5000000000</max_bytes_before_external_sort>
<!-- 单个用户可用最大内存 -->
<max_memory_usage_for_user>0</max_memory_usage_for_user>
<!-- 所有查询可用最大内存 -->
<max_memory_usage_for_all_queries>0</max_memory_usage_for_all_queries>


config.xml  主标签:

<!-- 允许外部连接 -->
<listen_host>::</listen_host>
<!-- 默认9000与php-fpm端口冲突 -->
<tcp_port>8124</tcp_port>
<!-- 数据存储目录 Path to data directory, with trailing slash. -->
<path>/mnt/clickhouse/</path>

参阅:

查询复杂性的限制 | ClickHouse文档

GROUP BY | ClickHouse文档

Author: thinkwei

1 thought on “ClickHouse内存超限配置及其他配置优化

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注