Out Of Memory — SQLSTATE 53200

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 29 May 2025 · Reproduced live with the SQL on this page.

! Symptoms Free

The server could not allocate memory for the operation.

  • The error is written to the server log and returned to the client carrying SQLSTATE 53200.
  • Any driver (libpq, JDBC, psycopg, npgsql, pgx) surfaces this code in its error object so you can branch on it programmatically.
  • PL/pgSQL can trap it by name: EXCEPTION WHEN out_of_memory THEN.

1 Environment & reproduce Free

Severity: ERROR  |  PostgreSQL versions: 12, 13, 14, 15, 16, 17

Most often seen under load or on under-provisioned servers; correlate it with system metrics (CPU, memory, disk, connection count) at the time of the error.

? Root cause Free

A backend requested more memory than the OS would give — often during large sorts/hashes or with many concurrent connections.

Common causes:

  • work_mem too high multiplied across many nodes and connections.
  • A very large hash or sort.
  • A memory leak in an extension.
  • OS overcommit limits or too many backends.

3 Recovery & verify Free

Steps to resolve 53200:

  1. Lower work_mem and maintenance_work_mem — remember work_mem is per sort/hash node per query.
  2. Reduce concurrent connections with pooling.
  3. Inspect the failing plan for huge in-memory operations; add indexes or rewrite.
  4. Check OS vm.overcommit, RAM/swap, and the system log for the OOM killer.

Reference: PostgreSQL error codes — Class 53 (Insufficient Resources).