SQLSTATE 54000 ERROR Class 54: Program Limit Exceeded

program_limit_exceeded Program Limit Exceeded — SQLSTATE 54000

A hard internal program limit was exceeded.

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

Symptoms

A hard internal program limit was exceeded.

  • The error is written to the server log and returned to the client carrying SQLSTATE 54000.
  • 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 program_limit_exceeded 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

The statement exceeded an internal limit such as expression depth or size.

Diagnostic Queries

Recovery

Steps to resolve 54000:

  1. Simplify the statement — fewer joins/expressions, smaller IN lists, or split it into parts.
  2. Raise max_stack_depth only if the OS stack limit allows it.

Reference: PostgreSQL error codes — Class 54 (Program Limit Exceeded).

Was this helpful?