Resolve a query memory limit error
A memory-limit error means a request exceeded its accounted SQL memory budget. Inspect both the effective setting and the workload before increasing that budget. The limit is distinct from total process memory and response-size limits.
SELECT name, value, "default"
FROM system.settings
WHERE name IN ('max_memory_usage', 'max_response_bytes')
FORMAT csv;Identify the expensive operation
Find the request's terminal event in system.query_log using its query identifier. Review peak memory, returned rows and the SQL text. If the statement sorts or groups a large input, narrow the input and projection. If the consumer requests a large export, split it into explicitly ordered ranges and verify every range.
max_memory_usage covers the request across its statements. Dividing one SQL batch into separate requests can change that scope, but it also changes transaction and temporary-table behavior.
Change a ceiling deliberately
A server XML ceiling can only be tightened by a database setting. SET max_memory_usage persists for the selected database, requires autocommit with no active transactions there, and affects later requests. Zero removes only the additional database ceiling.
See max_memory_usage, request limits and query history.