The mistake
On a table that existed before the migration: CREATE INDEX without CONCURRENTLY; adding a CHECK or FOREIGN KEY constraint with a full check; column type changes and volatile defaults that rewrite the table; NOT NULL added to an existing table; and no lock_timeout.
Why it is dangerous
A plain CREATE INDEX holds a SHARE lock for the whole build: every INSERT, UPDATE and DELETE waits, which on a large table means minutes of failed or stuck writes. Adding a CHECK constraint scans every row under an ACCESS EXCLUSIVE lock. ADD COLUMN ... NOT NULL without a default fails on any table that has rows. Without a lock_timeout, a migration that waits behind a long transaction makes every new query on that table queue behind it, stalling all traffic to the table.
How to fix it
Build indexes with CREATE INDEX CONCURRENTLY (outside a transaction block). Add constraints as NOT VALID and VALIDATE CONSTRAINT separately. Set a lock_timeout at the top of migrations that touch existing tables so they give up quickly and can be retried:
SET lock_timeout = '5s';
CREATE INDEX CONCURRENTLY IF NOT EXISTS orders_user_id_idx ON orders (user_id);
ALTER TABLE orders ADD CONSTRAINT orders_user_fk
FOREIGN KEY (user_id) REFERENCES users (id) NOT VALID;
ALTER TABLE orders VALIDATE CONSTRAINT orders_user_fk;
What this checker looks for
This page runs pg-launch-check, which reads
SQL migrations, schema.prisma and app code (Prisma, Drizzle, pg, SQLAlchemy, Django). The rules most relevant to this page:
| Rule | What it finds |
|---|---|
PGL002 | CREATE INDEX without CONCURRENTLY on an existing table |
PGL003 | Constraint added with a full check while holding a lock |
PGL004 | Table rewrite while holding an ACCESS EXCLUSIVE lock |
PGL005 | NOT NULL added to an existing table |
PGL006 | Migration without lock_timeout |
Every finding has a rule id, a severity, file:line, the offending line (secrets masked),
why it matters and how to fix it. Run pg-launch-check rules for the full list.