Fixing the request execution error: Exception Memory limit (total) exceeded
Written by
Updated at November 27, 2023
Issue description
When executing a query in ClickHouse, you get this error:
DB::Exception: Memory limit (total) exceeded: would use XX.XX GiB (attempt to allocate chunk of XXXXXXXX bytes), maximum: XX.X 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's RAM limit. You can increase it via the UI, on the Users tab. You need to change the max_memory_usage
parameter.
Note that this limit should not exceed the max_server_memory_usage
parameter.
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 didn't help, create a request for support
When creating the request, provide the following information:
- ID of a Managed Service for Clickhouse cluster
- Database query code
- Full text of the error message.