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

duplicate_object extension “…” already exists — 42710

PostgreSQL error “extension … already exists — 42710” (SQLSTATE 42710): what it means, common causes, and how to fix it.

PG 9.6, 10, 11, 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed Jun 2026 Grounded in source

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

  1. Use CREATE EXTENSION IF NOT EXISTS pgcrypto; for idempotency.
  2. Check existing extensions: SELECT extname FROM pg_extension;.
  3. To upgrade, use ALTER EXTENSION … UPDATE instead of re-creating.

Related & next steps

Reference: PostgreSQL 18 — CREATE EXTENSION.

Was this helpful?