// PostgreSQL error reference

PostgreSQL XX000: internal error

PostgreSQL hit a condition its developers treat as can't-happen. Often a race with concurrent DDL, sometimes a bug or corruption. Note the details.

SQLSTATE
XX000
Name
internal_error
Category
Internal Error
Error message
cache lookup failed for relation 16397

What it means

XX000 (internal_error) is the code for internal errors raised with elog(ERROR, ...), which PostgreSQL uses for conditions that shouldn't occur in normal operation. Messages are terse and technical, such as cache lookup failed for relation 16397, could not find pathkey item to sort or unexpected chunk number.

Some are triggered by a table or function being dropped while another session was using it. Others point to a bug in PostgreSQL or an extension, or to data corruption, especially when they repeat on the same object.

Common causes

  • Concurrent DDL: an object dropped or recreated while another session's query referred to it by OID.
  • A bug in PostgreSQL or an extension, often fixed in a later minor release.
  • Corrupted catalog or table data after a hardware or storage failure.

How to fix it

  1. Retry the statement. If it was a race with DDL, it succeeds once the other change has finished.

  2. Check that the server runs the latest minor release for its major version; minor releases fix many internal errors.

    SELECT version();
  3. If the error repeats on one table, check it for corruption (the amcheck extension verifies B-tree indexes and, since PostgreSQL 14, heap tables with pg_amcheck), and restore from backup if needed.

    CREATE EXTENSION IF NOT EXISTS amcheck;
    SELECT bt_index_check('orders_pkey');
  4. If you can reproduce it, report it to the PostgreSQL bugs list with the version, the full error with \set VERBOSITY verbose, and a script.

Related errors

More internal error 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.