// PostgreSQL error reference

PostgreSQL 54000: program limit exceeded

A hard implementation limit was hit, most often a value too large for a B-tree index entry, or too many columns or function arguments.

SQLSTATE
54000
Name
program_limit_exceeded
Category
Program Limit Exceeded
Error message
index row size 3200 exceeds btree version 4 maximum 2704 for index "documents_body_idx"
DETAIL:  Index row references tuple (12,3) in relation "documents".
HINT:  Values larger than 1/3 of a buffer page cannot be indexed.
Consider a function index of an MD5 hash of the value, or use full text indexing.

What it means

54000 (program_limit_exceeded) is raised when a statement runs into one of PostgreSQL's fixed limits. The one people meet most is the B-tree entry size: an indexed value must fit in about a third of an 8 kB page (2704 bytes for current B-tree indexes), so a unique index on a long text column fails when a big value arrives.

Other limits in this class include at most 1600 columns per table, 100 arguments per function, and 1664 entries in a select list.

Common causes

  • A B-tree index (often from a UNIQUE constraint) on a text, JSON or bytea column that can hold large values.
  • A generated query with thousands of columns or expressions.
  • Calling a function with more than 100 arguments, for example a very wide json_build_object.

How to fix it

  1. Index a hash of the value instead of the value itself; this still enforces uniqueness for practical purposes.

    DROP INDEX documents_body_idx;
    CREATE UNIQUE INDEX documents_body_md5_key ON documents (md5(body));
  2. For searching inside long text, use full text search or trigram indexes instead of a B-tree.

    CREATE INDEX documents_body_fts ON documents USING gin (to_tsvector('english', body));
  3. For very wide data, store attributes in fewer columns (jsonb), and build objects from rows (to_jsonb(t)) rather than passing hundreds of arguments.

Related errors

The code and message text are from the PostgreSQL documentation, Appendix A: PostgreSQL Error Codes. Browse the full PostgreSQL error list or search every database error.

// fewer errors, faster fixes

Work on PostgreSQL in SQLly

A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for PostgreSQL and the other databases you use.