Postgres Migration Safety Checker
Paste a migration. See which statements will lock or rewrite a live table, fail on a table that has data, or break the app while it deploys, with a safe rewrite for each one.
Runs entirely in your browser. Your SQL is never uploaded; we only count anonymous page visits and button clicks (GoatCounter, no cookies). Rules target PostgreSQL 11+ and were verified against PostgreSQL 16.
Catch this on every pull request, automatically
The same rules as a free GitHub Action. It checks only the migrations a pull request changes, marks the risky lines in the diff and leaves one comment with the safe version. No account, no signup, works on private repos, adds about a second to the job.
.github/workflows/migrations.yml.
Want Claude Code to write migrations like this in the first place? The free postgres-safe-migrations skill teaches it these rules.
What it checks
| Statement | What goes wrong | Safe version |
|---|---|---|
CREATE INDEX | Blocks every write to the table until the index is built | CREATE INDEX CONCURRENTLY, outside a transaction |
ADD COLUMN … DEFAULT gen_random_uuid() | Volatile default rewrites the whole table under the strongest lock | Add the column, set the default, backfill in batches |
ADD COLUMN … NOT NULL with no default | Fails outright on any table that has rows | Constant default, or nullable then backfill |
ALTER COLUMN … TYPE | Rewrites the table and every index | New column, backfill, switch reads |
SET NOT NULL | Full-table scan while reads and writes are blocked | CHECK … NOT VALID, VALIDATE, then SET NOT NULL |
ADD FOREIGN KEY / CHECK | Validates every row while blocking writes | NOT VALID, then VALIDATE CONSTRAINT later |
REFERENCES with no index on the column | Every delete on the parent scans the whole child table (100 deletes: 7.87 s vs 3.66 ms on 2M rows) | Index the foreign key column |
ADD UNIQUE / PRIMARY KEY | Builds an index while the table is unusable | Unique index CONCURRENTLY, then USING INDEX |
RENAME, DROP COLUMN, DROP TABLE | Old app instances fail during a rolling deploy | Expand and contract; drop after code stops using it |
CONCURRENTLY in a transaction | Postgres rejects it; the migration fails | Own migration with the transaction turned off |
VACUUM FULL, CLUSTER, REINDEX, REFRESH | Rewrites or blocks the table or view | pg_repack, CONCURRENTLY variants |
UPDATE / DELETE backfills | Locks every touched row until the migration commits | Batches of a few thousand rows, from a script |
No lock_timeout | A quick ALTER waits behind a slow query and every request queues behind it | SET lock_timeout = '3s' at the top |
Why "it worked in dev" isn't enough
Most dangerous migrations run in milliseconds on a development database with ten rows. In production, the same statement can hold an ACCESS EXCLUSIVE lock for minutes, or wait behind one long query while every request piles up behind it. The checker reads your SQL statically, so it catches these before they run against real data.
It doesn't know your table sizes or traffic, so treat a finding as "check this", not "this will definitely cause an outage". Statements on a table created earlier in the same migration are treated as safe, since that table is empty.