lock_timeout
Fact — official short description: “Sets the maximum allowed duration of any wait for a lock.”
Identity
Lifecycle
| Fact | Value |
|---|---|
| First observed | PG9.3 |
| Present in | PG9.3–19 Beta 3 |
| Removed in | No |
| Introduction commit | d43837d03067 — Add lock_timeout configuration parameter. |
| Commit date | 2013-03-16 |
| Discussion | — |
Default history
| Versions | Raw boot_val |
Unit | Human value |
|---|---|---|---|
| PG9.3–19 Beta 3 | 0 |
ms |
0 ms |
How it works
lock_timeout sets the maximum allowed duration of any wait for a lock. 0 disables the timeout. The timer applies separately to each lock acquisition, not to total statement runtime; a statement_timeout at the same or lower value will fire first.
lock_timeout is a USER-context setting. An authorized role can change it for a session, while ALTER ROLE or ALTER DATABASE can establish a default for future sessions.
Timeouts overlap: the first applicable deadline wins, while client, pooler, TCP, and server cancellation behavior determines whether work is retried, canceled, or the session is closed.
Tuning advice
Advice. These are workload-specific starting points and must be validated with measurements.
| Workload | Guidance |
|---|---|
| OLTP | Set lock_timeout from the service latency and failure budget, preferably per role or application. Test retries and cancellation paths before enforcing a cluster-wide value. |
| OLAP | Analytical work usually needs a larger or job-specific lock_timeout; preserve a finite guardrail for abandoned work without killing legitimate long scans. |
| Small nodes | Use a conservative finite lock_timeout only when the client or operating system handles termination correctly; verify that maintenance still has a dedicated exception. |
Pigsty
Values use the fixed 8-vCPU, 32-GiB, 100-GiB SSD fixture and render the current Pigsty templates for PG19 Beta 3; this does not assert current Pigsty support for that historical or beta release.
| Template | Effective value | Versus upstream boot | Source expression |
|---|---|---|---|
| OLTP | Unmodified | — | — |
| OLAP | Unmodified | — | — |
| CRIT | Unmodified | — | — |
| TINY | Unmodified | — | — |
Advice — pending human review. Fact from the current Pigsty template projection: OLTP: PG9.3–19 Beta 3 unmodified; OLAP: PG9.3–19 Beta 3 unmodified; CRIT: PG9.3–19 Beta 3 unmodified; TINY: PG9.3–19 Beta 3 unmodified. No Pigsty-specific rationale is inferred from an absent override.
Common pitfalls
- Changing lock_timeout in one session and assuming role defaults, database defaults, or other pooled sessions changed with it.
- Forgetting that zero usually disables the timeout or delegates behavior to the operating system.
- Setting overlapping deadlines without deciding which layer owns retries, cancellation, and connection disposal.
- Changing lock_timeout globally without a rollback plan and a client or operational compatibility test.
Related parameters
statement_timeout · transaction_timeout · idle_in_transaction_session_timeout · idle_session_timeout · deadlock_timeout