ERROR database configuration_error ai_generated true

ERROR: could not open extension control file "/usr/share/postgresql/16/extension/pg_stat_statements.control": No such file or directory

ID: database/pg-extension-not-found

Also available as: JSON · Markdown
92%Fix Rate
94%Confidence
58Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
16 active

Root Cause

The PostgreSQL extension package is not installed on the system. PostgreSQL extensions are distributed as separate OS packages (e.g., postgresql-16-postgis, postgresql-contrib) that must be installed before CREATE EXTENSION can find the control file. Common in Docker containers and minimal OS installations.

generic

Workarounds

  1. 95% success Install the OS package containing the extension
    On Debian/Ubuntu: apt-get install postgresql-16-<extension> (e.g., postgresql-16-postgis-3). For contrib extensions: apt-get install postgresql-contrib-16. On RHEL/CentOS: dnf install postgresql16-contrib. Then run: CREATE EXTENSION <name>; No PostgreSQL restart needed for most extensions.
  2. 92% success In Docker, add the extension package to your Dockerfile
    In your Dockerfile based on postgres:16, add: RUN apt-get update && apt-get install -y postgresql-16-<extension> && rm -rf /var/lib/apt/lists/*. Then rebuild the image. For common extensions, consider using the postgis/postgis or timescale/timescaledb images that come pre-installed.

Dead Ends

Common approaches that don't work:

  1. Copying the extension .control and .sql files manually from another PostgreSQL installation 85% fail

    Extension files must match the exact PostgreSQL version and be compiled for the target architecture. Copying files from a different version leads to ABI incompatibility, crashes, or silent data corruption. Extensions with C shared libraries will fail to load.

  2. Running CREATE EXTENSION repeatedly hoping it will work after a PostgreSQL restart 95% fail

    The extension control file is a filesystem dependency, not a PostgreSQL runtime state. Restarting PostgreSQL does not install OS packages. The file must exist on disk before CREATE EXTENSION can find it.

Error Chain

Leads to:
Preceded by:
Frequently confused with: