max_server_memory_usage
The maximum amount of memory the server is allowed to use, expressed in bytes.The maximum memory consumption of the server is further restricted by setting
max_server_memory_usage_to_ram_ratio.0 (default) means the server may consume all available memory (excluding further restrictions imposed by max_server_memory_usage_to_ram_ratio).
max_server_memory_usage_to_ram_ratio
The maximum amount of memory the server is allowed to use, expressed as a ratio to all available memory. For example, a value of0.9 (default) means that the server may consume 90% of the available memory.
Allows lowering the memory usage on low-memory systems.
On hosts with low RAM and swap, you may possibly need setting max_server_memory_usage_to_ram_ratio set larger than 1.
This ratio is applied in two ways:
- At startup (and on configuration reload) it caps the server’s hard memory limit at this fraction of the total physical RAM, as described above.
- At runtime, the background memory worker periodically recomputes the hard memory limit as
(resident memory + system available memory) * max_server_memory_usage_to_ram_ratio, so the server leaves headroom for other processes running on the same host. When running inside a cgroup with a finite memory limit, the cgroup’s available memory is used instead of the host-wide value. As other processes grow and the available memory shrinks, the server’s hard limit follows it down, capping growth before the host (or the cgroup) runs out of memory.
0 disables both the startup cap and the runtime adjustment. The runtime adjustment is also a no-op on non-Linux systems and in clickhouse-keeper, which does not expose this setting. To keep the static startup/reload cap but disable the runtime adjustment (the behavior of previous versions), set memory_worker_dynamic_hard_limit to 0.
The maximum memory consumption of the server is further restricted by setting
max_server_memory_usage.