SQLSTATE 53200 ERROR Class 53: Insufficient Resources

out_of_memory out of memory — 53200

PostgreSQL error "out of memory" (SQLSTATE 53200): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

Diagnostic Queries

Symptoms

A backend could not allocate the memory it needed for an operation. PostgreSQL raises SQLSTATE 53200 (out_of_memory) and usually logs a memory-context dump showing where memory went.

  • Often during large sorts, hash joins, or huge result materialization.
  • The log includes a TopMemoryContext breakdown.
  • May be a single oversized query rather than a global shortage.

What the server log shows

ERROR:  out of memory
DETAIL:  Failed on request of size 1073741824 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 memory governed partly by work_mem per operation. A query that demands more than the OS can give (or an over-large work_mem multiplied across operations) exhausts memory and aborts with 53200.

Common causes

  • A single query with a huge sort, hash join, or result set.
  • An over-large work_mem multiplied across many concurrent operations.
  • OS memory pressure, tight cgroup limits, or disabled overcommit.

Relevant GUC parameters

Parameter Default Effect
work_mem 4MB Memory per sort/hash operation before spilling to disk.
maintenance_work_mem 64MB Memory for VACUUM, CREATE INDEX, and similar.
hash_mem_multiplier 2.0 Multiplies work_mem for hash-based operations (PG15+).

How to fix it

  1. Lower a too-aggressive work_mem, or set it per-session for big queries only.
  2. Reduce result size with filtering/pagination; avoid materializing huge sets client-side.
  3. Check OS memory and overcommit settings; ensure swap and limits are sane.

Diagnostic query

-- Inspect current memory-related settings
SELECT name, setting, unit FROM pg_settings
WHERE name IN ('work_mem','maintenance_work_mem','hash_mem_multiplier','shared_buffers');

Related & next steps

Reference: PostgreSQL 18 Section 20.4 “Resource Consumption”.

Was this helpful?