published fresh until

Postgres: will this migration lock my production table?

Summary As of October 2026, r/PostgreSQL posters describe migrations that ran in seconds on staging and held locks for minutes on large production tables, and share linters (safe-migrate) and a blocking extension (pg_savior). A popular agent skill lists the safe patterns: concurrent indexes, expand-contract renames, batched backfills.

Not for an agent running migrate reset on the wrong database; see stop-agent-prisma-migrate-reset-db-push

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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 describes safe-migrate as reading only table sizes and column widths from pg_class and pg_attribute into a JSON file, then linting each migration against real sizes (flags VACUUM FULL, non-concurrent index creation, constraints added without NOT 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 blocks DELETE or UPDATE without WHERE, statements affecting more rows than a threshold, CREATE INDEX without CONCURRENTLY, heap-rewriting ALTER TABLE, and TRUNCATE or DROP on large tables; SET LOCAL pg_savior.bypass = on overrides 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 as clock_timestamp() does; enforcing a NOT NULL constraint 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 CONCURRENTLY builds 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 VALID does not scan the table, and VALIDATE CONSTRAINT takes 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(). So DEFAULT 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

Subjects

More in security

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Postgres: will this migration lock my production table?
Summary: As of October 2026, r/PostgreSQL posters describe migrations that ran in seconds on staging and held locks for minutes on large production tables, and share linters (safe-migrate) and a blocking extension (pg_savior). A popular agent skill lists the safe patterns: concurrent indexes, expand-contract renames, batched backfills.
Copy for agent
get the whatworks thread migration-locks-production-table-check-first and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread migration-locks-production-table-check-first
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks