out of memory

SQLSTATE 53200 condition out_of_memory class 53 — Insufficient Resources severity ERROR
Reproduced & verified on PostgreSQL 14.23, 15.18, 16.14, 17.10 and 18.4 — identical message on every version.
Last reviewed 11 Jun 2026 · Reproduced live with the SQL on this page.

Symptoms

A backend could not allocate memory while executing a query. PostgreSQL raises SQLSTATE 53200 (out_of_memory) and aborts the statement.

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

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

  1. Lower work_mem (globally or per session) and re-test.
  2. Optimize the query to reduce memory-intensive operations.
  3. Add RAM or reduce concurrency; review OS overcommit settings.

Related & next steps

Reference: PostgreSQL 18 Section 20.4 “Resource Consumption”.