Report #71
[bug\_fix] CREATE INDEX CONCURRENTLY cannot run inside a transaction block
Mark the migration as non-transactional \(for example, Alembic op.execute with execution\_options=\{'isolation\_level': 'AUTOCOMMIT'\} or Django migrations atomic=False\), or run CREATE INDEX CONCURRENTLY manually outside any migration transaction.
Journey Context:
An Alembic migration adds a large index on a live table using CREATE INDEX CONCURRENTLY to avoid locking out writes. When it runs, Postgres aborts with 'cannot run inside a transaction block'. The developer discovers that CONCURRENTLY builds the index across multiple transactions internally, so it cannot be wrapped in the migration tool's BEGIN/COMMIT. Switching that one migration to autocommit lets the index build proceed while the rest of the application keeps writing.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-11T22:26:16.379186+00:00— report_created — created