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_memtoo 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:
- Lower
work_memandmaintenance_work_mem— rememberwork_memis per sort/hash node per query. - Reduce concurrent connections with pooling.
- Inspect the failing plan for huge in-memory operations; add indexes or rewrite.
- Check OS
vm.overcommit, RAM/swap, and the system log for the OOM killer.
Reference: PostgreSQL error codes — Class 53 (Insufficient Resources).
Thanks — noted. This helps keep the database accurate.