Database / Supabase Intermediate to Advanced Interview Questions
What happens when a long-running migration locks a table that's still receiving live writes?
Most schema-altering statements (like ALTER TABLE) need an ACCESS EXCLUSIVE lock, the strongest lock Postgres has, for at least a brief moment to safely change the table's structure. While that lock is held, every other query trying to read or write that table — including simple SELECTs — has to wait in a queue behind it, not just other writes.
If the migration itself is slow (rewriting a huge table, or building an index the blocking way), that queue of waiting queries can grow for the entire duration, and application requests hitting that table will appear to hang until the migration finishes or times out. In the worst case, a migration that acquires its lock but then has to wait behind an existing long-running query already holding a weaker lock on the same table can itself stall indefinitely, while every subsequent query queues up behind it in turn — a cascading pile-up sometimes called a "lock queue" incident.
This is exactly why migrations against live, high-traffic tables favor non-blocking techniques (adding nullable columns, CREATE INDEX CONCURRENTLY, batched backfills) over a single heavy statement, and why setting a conservative lock_timeout before running a risky migration is a common safeguard — it fails the migration attempt quickly and lets you retry, rather than letting it silently queue behind production traffic for minutes.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
