// postgresql · timeouts

lock_timeout

Abort a statement that waits longer than this to acquire a lock; 0 disables.

Padrão
0 (disabled)
Range
0 to about 24 days, in ms
Restart needed
Não
Default checked on
PostgreSQL 18

O que faz

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.

Valor padrão

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

MotorConfiguraçãoPadrãoRestart
PostgreSQL lock_timeout this page 0 (disabled) Não
MySQL innodb_lock_wait_timeout 50 Não
SQL Server LOCK_TIMEOUT -1 (wait forever) Não
SQLite busy_timeout 0 Não

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.

// one client for every engine

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.