Add a FK to a big production table without blocking
A large production table needs a foreign key. The plain add takes an exclusive lock — reads and writes are blocked while it scans. The trick is two steps: first hang the key with «don't validate yet» (instant, doesn't block writers), then run validation against the old rows in a separate command (no write locks).
Build parents and children, insert a few rows. Add a foreign key children_parent_id_fkey to children from column parent_id to parents(id) without immediate validation. Then run validation against this same key — it should end up marked as validated.
Just CREATE/ALTER/DROP — no trailing SELECT needed.
Sign in to see submission history
Sign inSign in to use AI Mentor
Sign inNo starting schema
This task starts with no tables — you'll create them via CREATE TABLE.