Diagnostic Queries
Symptoms
A CREATE EXTENSION named an extension that is already installed in the database. PostgreSQL raises SQLSTATE 42710 (duplicate_object).
- The extension already exists in this database.
- Common in migration scripts run more than once.
- Use IF NOT EXISTS for idempotency.
What the server log shows
ERROR: extension "pgcrypto" already exists
Why PostgreSQL raises this — what the manual says
the CREATE EXTENSION reference (Description):
“There must not be an extension of the same name already loaded.”
Each extension can be installed once per database (tracked in pg_extension). Re-creating one that already exists collides with the installed object, so PostgreSQL reports 42710.
Common causes
- Re-running a migration/setup script that installs the extension.
- The extension was already installed by another process.
- Template database already including the extension.
How to fix it
- Use
CREATE EXTENSION IF NOT EXISTS pgcrypto;for idempotency. - Check existing extensions:
SELECT extname FROM pg_extension;. - To upgrade, use
ALTER EXTENSION … UPDATEinstead of re-creating.
Related & next steps
Reference: PostgreSQL 18 — CREATE EXTENSION.
Thanks — noted. This helps keep the database accurate.