SQLSTATE 42704 ERROR Class 42: Syntax Error or Access Rule Violation

undefined_object extension “…” does not exist — 42704

PostgreSQL error "extension "…" does not exist" (SQLSTATE 42704): what it means, common causes, and how to fix it.

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

Diagnostic Queries

Symptoms

A statement referenced an extension that is not installed in the current database. PostgreSQL raises SQLSTATE 42704 (undefined_object).

  • The named extension isn’t installed here.
  • Common in ALTER EXTENSION/DROP EXTENSION.
  • Extensions are per-database.

What the server log shows

ERROR:  extension "pg_trgm" does not exist

Why PostgreSQL raises this — what the manual says

the DROP EXTENSION reference (Description):

“DROP EXTENSION removes extensions from the database.”

Extensions are installed per database via CREATE EXTENSION. Referencing one that was never installed (or installed in a different database) cannot be resolved, so PostgreSQL reports 42704.

Common causes

  • The extension was never installed in this database.
  • A typo in the extension name.
  • Connected to the wrong database.

How to fix it

  1. Install it: CREATE EXTENSION pg_trgm; (if the contrib package is present).
  2. List installed extensions: \dx or query pg_extension.
  3. Use DROP EXTENSION IF EXISTS for idempotency; verify the database.

Related & next steps

Reference: PostgreSQL 18 — DROP EXTENSION.

Was this helpful?