Prerequisites
- Access to the production database. See Connecting to Production DB.
1. Find the blocking query
Run this query to find sessions that are waiting and what’s blocking them:pid/blocking_pid— process IDswaiting— how long the blocked query has been waitingblocked_query— the query that can’t proceedblocking_query— the last query run by the blocking session
2. Terminate the blocking session
Once you’ve identified the blockingpid, terminate it:
3. After termination
- Verify the blocked operation completes successfully
- Check application logs / Sentry for errors caused by the terminated session
- Document in the on-call log
- Notify the team
Root causes to investigate
Common reasons a session holds locks for too long:- Transaction open across external I/O — e.g. a worker that queries the DB and then makes a slow HTTP call (Expo push, Stripe, etc.) while still inside the same database transaction. The transaction never commits until the HTTP call returns.
- Missing
lock_timeouton DDL migrations — without a timeout, aDROP TABLEorALTER TABLEwill queue indefinitely behind hot-table readers, and while queued it also blocks new readers. - No
idle_in_transaction_session_timeout— connections left idle inside a transaction are never auto-killed by the DB.

