What this thread does
The problem in plain words
The agent writes a correct migration that is dangerous at scale: an exclusive lock or a table rewrite on a big table, or a DELETE without WHERE. Staging has a few thousand rows, so nothing looks wrong.
What people report
- A r/PostgreSQL post (dsecurity49, June 2026) says a migration that ran fine on staging took production down for about 20 minutes; the author blames
ADD COLUMN ... DEFAULT NOW()rewriting 80 million rows under an exclusive lock. That explanation conflicts with the Postgres docs (see Sources): a non-volatile default such as now() is not a rewrite on current versions, so the real cause is unclear. In that June 2026 post, the author describessafe-migrateas reading only table sizes and column widths frompg_classandpg_attributeinto a JSON file, then linting each migration against real sizes (flagsVACUUM FULL, non-concurrent index creation, constraints added withoutNOT VALID, type changes that rewrite,DROP TABLE CASCADE, hidden dynamic SQL). Their own description: still rough. - A r/PostgreSQL post (vira28, Aug 2026), by a former Cloudflare DBA lead, presents
pg_savior, a Postgres extension that blocksDELETEorUPDATEwithoutWHERE, statements affecting more rows than a threshold,CREATE INDEXwithoutCONCURRENTLY, heap-rewritingALTER TABLE, andTRUNCATEorDROPon large tables;SET LOCAL pg_savior.bypass = onoverrides it. Limits stated by the author: it is a seatbelt, estimates are approximate, it needs an extension (so not managed services), it is pre-1.0, and tested on PG 14 to 17.
Both are third-party tools I did not run.
The safe patterns an agent skill encodes
The database-migrations skill in ECC (MIT, commit 76aaa77df6, path .kiro/skills/database-migrations/SKILL.md) is a collection skill, not an authority, but its rules match common Postgres practice:
- One migration per change; schema and data migrations separate; migrations immutable once deployed; production is forward-only (roll back with a new migration).
- New columns nullable or with a default; a non-volatile default (including
now()) needs no table rewrite on current Postgres, while a volatile one such asclock_timestamp()does; enforcing aNOT NULLconstraint scans existing rows rather than rewriting the table. CREATE INDEX CONCURRENTLY(cannot run inside a transaction block, so your tool needs a special case).- Rename a column with expand and contract: add the new column, backfill in its own migration, deploy code reading and writing both, stop using the old one, drop it later. Remove a column only after no code references it.
- Backfill in batches, not one giant
UPDATE. - Test against production-sized data.
Wording to give your agent
"Write the migration as a file. Before showing it, list for each statement whether it takes a lock or rewrites the table on Postgres [version] and how big the table is. Use CREATE INDEX CONCURRENTLY, add columns nullable first, split backfill into batches, and use expand and contract for renames. Do not run it; show me the SQL."
Caveats
I did not test any tool or the skill. For testing a migration against real data in a disposable copy, see the Neon branch thread.
Sources
Primary sources: PostgreSQL documentation, ALTER TABLE and CREATE INDEX (checked 15 November 2026).
- Confirms:
CREATE INDEX CONCURRENTLYbuilds without blocking inserts, updates or deletes, cannot run inside a transaction block, and if it fails leaves an invalid index to drop or reindex;ADD CONSTRAINT ... NOT VALIDdoes not scan the table, andVALIDATE CONSTRAINTtakes only a SHARE UPDATE EXCLUSIVE lock; changing a column type normally rewrites the table and its indexes (unless the types are binary coercible), which can take long and need up to double the disk space; a volatile default, a stored generated column or an identity column rewrites the whole table. - Contradicts the Reddit explanation: the ALTER TABLE page says a non-volatile default is evaluated once and stored in metadata with no rewrite, and its own example is
ADD COLUMN mtime timestamp with time zone DEFAULT now(). SoDEFAULT NOW()alone should not rewrite 80 million rows on a current Postgres; corrected above. The outage may have come from another statement, an old Postgres version or waiting on a lock; the post does not show which. The docs page I read does not mention version 11, so the "11 and later" cut-off in the skill's rules is not confirmed there. - The authors' posts linked above describe the two third-party tools (
safe-migrate,pg_savior); the ECC skill linked above supplies the rules beyond the PostgreSQL points above, including batching and expand-and-contract advice, rather than documented PostgreSQL policy.
Started from a post by @vira28, packaged by the editor. Original post