← all rules

concurrently-in-transaction

error

CONCURRENTLY inside a transaction

Why it's unsafe

CREATE/DROP INDEX CONCURRENTLY and REINDEX CONCURRENTLY cannot run inside a transaction block; this statement runs inside a transaction and will fail at runtime.

Safe rewrite

Run the CONCURRENTLY statement outside the transaction — put it in its own migration, or move it before BEGIN / after COMMIT. (Note: many migration tools also wrap each migration in an implicit transaction; disable that for this migration.)

Example

Try it in the playground →

Unsafe

BEGIN;
CREATE INDEX CONCURRENTLY idx_users_email ON users (email);
COMMIT;

Safe

CREATE INDEX CONCURRENTLY idx_users_email ON users (email);

Related