Diagnostic Queries
Symptoms
REINDEX … CONCURRENTLY was issued inside a transaction block. Like other concurrent index operations, it commits in phases and cannot run inside an outer transaction, so PostgreSQL raises SQLSTATE 25001 (active_sql_transaction).
- REINDEX CONCURRENTLY issued after
BEGIN. - Common in migration tools that wrap statements.
- Must run standalone with autocommit.
What the server log shows
ERROR: REINDEX CONCURRENTLY cannot run inside a transaction block
Why PostgreSQL raises this — what the manual says
the REINDEX reference (Notes):
“Another difference is that a regular REINDEX TABLE or REINDEX INDEX command can be performed within a transaction block, but REINDEX CONCURRENTLY cannot.”
The concurrent rebuild commits between phases so it never holds a long lock. Running inside an outer transaction would prevent those intermediate commits, so PostgreSQL rejects it with 25001.
Common causes
- Issuing REINDEX CONCURRENTLY after
BEGIN. - A migration framework wrapping statements in transactions.
- Autocommit disabled on the connection.
How to fix it
- Run it standalone with autocommit on.
- Mark the step as non-transactional in migration tools.
- Use plain
REINDEXif a brief lock is acceptable and you must stay in a transaction.
Related & next steps
Reference: PostgreSQL 18 — REINDEX.
Thanks — noted. This helps keep the database accurate.