lock_timeout
Abort a statement that waits longer than this to acquire a lock; 0 disables.
- Default
0 (disabled)- Range
- 0 to about 24 days, in ms
- Restart needed
- No
- Default checked on
- PostgreSQL 18
What it does
Applies to each lock wait separately. Most useful for DDL: ALTER TABLE waits for an ACCESS EXCLUSIVE lock and blocks every query behind it while it waits.
Default value
0 (disabled). 0 (PostgreSQL 18).
Check the current value
SHOW lock_timeout; SELECT setting, unit, boot_val, context, source, pending_restart FROM pg_settings WHERE name = 'lock_timeout';
Change it
SET lock_timeout = '5s'; -- this session ALTER ROLE reporting SET lock_timeout = '5s'; -- new sessions of one role ALTER SYSTEM SET lock_timeout = '5s'; SELECT pg_reload_conf();
No restart. Any role can SET it for a session or with SET LOCAL for one transaction; a server-wide ALTER SYSTEM change applies after a reload (context is user).
When to change it
Set it in migration scripts (SET lock_timeout = '5s') so DDL gives up instead of queueing behind a long transaction and stalling the application.
What can go wrong
Statements fail with 'canceling statement due to lock timeout' and need a retry.
The closest setting on other engines
| Engine | Setting | Default | Restart |
|---|---|---|---|
| PostgreSQL |
lock_timeout this page
|
0 (disabled) |
No |
| MySQL |
innodb_lock_wait_timeout
|
50 |
No |
| SQL Server |
LOCK_TIMEOUT
|
-1 (wait forever) |
No |
| SQLite |
busy_timeout
|
0 |
No |
Questions about lock_timeout
What is the default value of lock_timeout in PostgreSQL?
0 (disabled). 0 (PostgreSQL 18).
Does changing lock_timeout require a restart?
No. No restart. Any role can SET it for a session or with SET LOCAL for one transaction; a server-wide ALTER SYSTEM change applies after a reload (context is user).
When should I change lock_timeout?
Set it in migration scripts (SET lock_timeout = '5s') so DDL gives up instead of queueing behind a long transaction and stalling the application.
Back to all PostgreSQL settings, or check the PostgreSQL manual for every option.
Check lock_timeout on your own server
SQLly runs the query above against PostgreSQL and the other engines in this reference, from one desktop app on macOS, Windows and Linux.