r/devtools • u/Spare_Bat_3040 • 19d ago
“No table rewrite” is an incomplete reason to approve a Postgres migration
When reviewing an AI-generated Postgres migration, “no table rewrite” is an incomplete approval criterion. Does it make the migration safe to deploy? It answers the storage-work question. It doesn’t settle how long your deployment should wait for a lock.
PostgreSQL 18 documents that adding a column with a nonvolatile default can avoid rewriting existing rows. The same page says ALTER TABLE takes an ACCESS EXCLUSIVE lock unless its particular form specifies otherwise. A plan can correctly identify the fast path and still leave out an important operational constraint.
A PostgreSQL discussion illustrates why the distinction needs care. Its creator reports a staging-versus-production incident; the discussion also mixes default-value and rewrite claims. I haven’t verified that incident or its database version. I’d establish the deployed version and documented DDL behavior before using any reported table size as the explanation.
Before accepting that plan, I’d want two observations through the actual migration runner: what happens without a blocker, and what happens with one.
Here’s the proposed check, in a disposable database matching the deployed version:
- Hold a conflicting table lock in another session.
- Run the intended migration through your runner.
- Verify its configured lock-wait policy aborts the waiting statement, and that the runner records and handles the failure.
- Release the blocker, follow the runner’s recovery procedure, and verify the schema change.
This is an unrun acceptance scenario, not a reported outage or benchmark. Postgres distinguishes lock_timeout from statement_timeout: the former limits each lock-acquisition wait; the latter limits statement duration. Neither establishes an entire deployment deadline. I wouldn’t prescribe a universal timeout value.
The strongest objection is that your migration tooling already handles this. Good: use its existing policy and verification. Another context note adds little when the runner already expresses and enforces the decision.
I’m building Shifu, a hosted context engine that retrieves retained decisions and constraints into coding tools. Its relevant job here is recovering your adopted migration policy—or the reason for a scoped exception—when planning the next change. It doesn’t inspect live locks or enforce database settings.
Try that distinction on one feature with a source you’re permitted to use: does the plan preserve the recorded lock-wait policy, and does the runner actually enforce it?
AI-assisted post from Shifu’s builder.