Diagnostic Queries
Symptoms
A backend could not allocate memory while executing a query. PostgreSQL raises SQLSTATE 53200 (out_of_memory) and aborts the statement.
- A memory allocation failed during query execution.
- Common with very high
work_memand many concurrent operations. - A memory-context dump usually accompanies it in the log.
What the server log shows
ERROR: out of memory
DETAIL: Failed on request of size 8388608 in memory context "ExecutorState".
Why PostgreSQL raises this — what the manual says
Section 19.4.1 Memory (work_mem):
“Sets the base maximum amount of memory to be used by a query operation (such as a sort or hash table) before writing to temporary disk files.”
Each backend allocates from process and OS memory. A large sort/hash with a high work_mem, multiplied across operations and connections, can exhaust available memory, so the allocation fails and PostgreSQL reports 53200.
Common causes
work_memset too high for the concurrency level.- A query with many memory-hungry operations (big hashes/sorts).
- Overall server memory pressure or OS overcommit limits.
Relevant GUC parameters
| Parameter | Default | Effect |
|---|---|---|
work_mem |
4MB | Per-operation memory budget; high values multiply across operations/sessions. |
hash_mem_multiplier |
2.0 | Scales the memory available to hash-based operations. |
How to fix it
- Lower
work_mem(globally or per session) and re-test. - Optimize the query to reduce memory-intensive operations.
- Add RAM or reduce concurrency; review OS overcommit settings.
Related & next steps
Reference: PostgreSQL 18 Section 20.4 “Resource Consumption”.
Thanks — noted. This helps keep the database accurate.