ban-concurrent-index-creation-in-transaction
#
problemWhile regular index creation can happen inside a transaction, this is not allowed when the CONCURRENTLY
option is used.
https://www.postgresql.org/docs/current/sql-createindex.html#SQL-CREATEINDEX-CONCURRENTLY
#
solutionRemove surrounding transaction markers if any.
For migrations that are implicitly wrapped in a transaction, ensure that the CREATE INDEX
command is the only command in the migration to allow migration tool to detect that no transaction is needed.
Instead of:
Use:
If you use a migration tool, it may be configured to automatically wrap commands in transactions; if that's the case, check if it supports running commands in a non-transactional context.
For example, with alembic
:
Or alternatively:
golang-migrate
wraps migrations in transactions but is clever enough to perform the migration if the migration file does not contain further commands next to the CREATE INDEX
command.
#
linkshttps://www.postgresql.org/docs/current/sql-createindex.html#SQL-CREATEINDEX-CONCURRENTLY