Fixing the Exception Memory limit (total) exceeded error when running a query
Written by
Updated at December 17, 2025
Issue description
When running a ClickHouse® query, you get this error:
DB::Exception: Memory limit (total) exceeded: would use XX.XX GiB (attempt to allocate chunk of ******** bytes), maximum: **.* GiB. (MEMORY_LIMIT_EXCEEDED), Stack trace (when copying this message, always include the lines below)
Solution
This error indicates that the database query size exceeds the user RAM limit. You can increase this limit on the Users tab in your management consolemax_memory_usage parameter.
Warning
The max_memory_usage limit value must not exceed that of max_server_memory_usage.
If user management via SQL is enabled in the cluster, you can set this parameter:
- At the session level, via
set max_memory_usage. - For all users by default, by creating one settings profile
.
If the issue persists
If the above actions did not help, create a support ticket
- Yandex Managed Service for ClickHouse® cluster ID.
- Database query code.
- Full text of the error message.