IT lexicon › Database › Lock timeout

Lock timeout

Database På svenska → Updated: 2026-05-27

Max time a query waits to get a lock before aborting. Default often unlimited (waits forever) — production tuning recommends 5-30 sec to avoid hanging connections under contention.

PostgreSQL: SET statement_timeout = '5s'. MySQL: SET lock_wait_timeout = 5. Distinct from deadlock detection: deadlocks are detected + aborted quickly (sub-second), lock timeout is for normal contention. Online schema changes: ALTER TABLE requires AccessExclusive lock — if slow query holds lock, ALTER waits. With lock timeout, ALTER aborts instead of blocking all other traffic. Classic migration best practice: SET lock_timeout = '2s' + retry loop.

← Back to the lexicon