SQLSTATE 53200 ERROR Class 53: Insufficient Resources

out_of_memory Out Of Memory — SQLSTATE 53200

The server could not allocate memory for the operation.

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

Symptoms

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.

Environment

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

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.

Diagnostic Queries

Recovery

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).

Was this helpful?