SQLSTATE 25001 ERROR Class 25: Invalid Transaction State

active_sql_transaction CREATE INDEX CONCURRENTLY cannot run inside a transaction block — 25001

PostgreSQL error "CREATE INDEX CONCURRENTLY cannot run inside a transaction block" (SQLSTATE 25001): 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

CREATE INDEX CONCURRENTLY was issued inside a transaction block. Because it commits in multiple phases to avoid locking writes, it cannot run inside an outer transaction. PostgreSQL raises SQLSTATE 25001 (active_sql_transaction).

  • Common in migration tools that wrap each step in a transaction.
  • Applies to REINDEX CONCURRENTLY and DROP INDEX CONCURRENTLY too.
  • Must be executed standalone with autocommit.

What the server log shows

ERROR:  CREATE INDEX CONCURRENTLY cannot run inside a transaction block

Why PostgreSQL raises this — what the manual says

the CREATE INDEX reference (Building Indexes Concurrently):

“Another difference is that a regular CREATE INDEX command can be performed within a transaction block, but CREATE INDEX CONCURRENTLY cannot.”

The concurrent build commits between internal phases so it never holds a long write lock. Running inside an outer transaction would prevent those intermediate commits, so PostgreSQL rejects it with 25001.

Common causes

  • A migration framework wrapping statements in a transaction by default.
  • Issuing the command after BEGIN.
  • Autocommit disabled on the connection.

How to fix it

  1. Run it outside a transaction (autocommit on).
  2. In migration tools, mark the step as non-transactional (e.g. disable the wrapping transaction for that migration).
  3. If a concurrent build fails midway, drop the leftover INVALID index and retry.

Diagnostic query

-- Find invalid indexes left by a failed concurrent build
SELECT c.relname FROM pg_index i
JOIN pg_class c ON c.oid = i.indexrelid
WHERE NOT i.indisvalid;

Related & next steps

Reference: PostgreSQL 18 — CREATE INDEX.

Was this helpful?