Report #65609
[bug\_fix] Timeout acquiring advisory lock in migration tool
Query pg\_locks to find the PID holding the advisory lock \(objid corresponds to the migration tool's magic number\), terminate that backend using pg\_terminate\_backend\(\), then re-run the migration; alternatively, configure the migration tool to use a lock timeout or disable advisory locking for short maintenance windows.
Journey Context:
A DevOps engineer runs a deployment pipeline using Flyway or ActiveRecord migrations against a production Postgres cluster. The migration step hangs for 60 seconds then exits with "Timeout trying to acquire advisory lock". The engineer checks pg\_stat\_activity and sees the migration connection in state: active, waiting. They query pg\_locks: SELECT \* FROM pg\_locks WHERE locktype = 'advisory' AND granted = true; This reveals a PID from yesterday's aborted deployment that crashed without releasing the lock \(the process died but Postgres held the lock until TCP keepalive timed out or the backend was cleaned up\). The engineer terminates the stale backend: SELECT pg\_terminate\_backend\(12345\); where 12345 is the blocking PID. The migration immediately acquires the advisory lock and proceeds. To prevent recurrence, they ensure applications use connection cleanup in finally blocks, and they set a reasonable lock\_timeout in migration scripts so they fail fast rather than hang the CI/CD pipeline for minutes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T16:36:23.979170+00:00— report_created — created