Skip to main content

SKY-Q506 · Quality, structure and performance

Concurrent PostgreSQL index command inside a transaction

Medium

The script opens an explicit transaction and requests a concurrent index build or drop before it ends. PostgreSQL rejects that command.

Languages
PostgreSQL
Quality gate
listed, not counted by the gate (full and diff scans). This PostgreSQL finding is report-only.
Finding type
review
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

The migration stops before it can build or remove the index. A migration runner can also supply an outer transaction.

What Skylos flags

migration.sql · SQLReported on line 2
BEGIN;CREATE INDEX CONCURRENTLY orders_id ON orders(id);COMMIT;
pyproject.toml · TOML
[tool.skylos.sql]dialect = "postgresql"

What Skylos leaves alone

migration.sql · SQL
CREATE INDEX CONCURRENTLY orders_id ON orders(id);

pyproject.toml: same as in the flagged example.

Why Skylos leaves it alone

Run the concurrent command outside the explicit transaction. Check whether the migration runner wraps it in another transaction.

How Skylos decides

  1. Skylos follows BEGIN, START TRANSACTION, COMMIT, ROLLBACK and transaction chaining within one session.
  2. Savepoints keep the outer transaction open.

How to fix it

Run the concurrent command outside the explicit transaction. Check whether the migration runner wraps it in another transaction.

migration.sql · SQL · the fix, against the flagged file
Removed: BEGIN;CREATE INDEX CONCURRENTLY orders_id ON orders(id);Removed: COMMIT;

When it can be wrong

  • A transaction opened by a migration runner is outside the scanned SQL.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • Review the statement in the context of its migration.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.