Lock timeout
- SQL course
- Advanced
- Lesson 64/81
- 4 min
Learn the lock wait timeout.
Lock timeout
A lock timeout limits how long to wait for a lock. On expiry it errors.
SET lock_timeout = '5s';This query errors after 5 seconds.
Lock timeout — details
Lock timeout prevents infinite waiting. Long lock waits cancel the operation.
In PostgreSQL, SET lock_timeout = '5s' makes a transaction that waits longer than five seconds fail; the application can catch the error and inform the user.
Practice Lock timeout
Set the lock timeout to 5 seconds with SET lock_timeout = '5s'.
Starter code
-- set timeout
SETSample solution
SET lock_timeout = '5s';Expected output
Zaman aşımı ayarlandı
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Add lock_timeout
SET ____ = '5s';
SET lock_timeout = '5s';
Explanation: lock_timeout is the right answer.
2 Lock timeout: match the terms
| Term | Meaning |
|---|---|
timeout |
timeout |
5s |
duration |
error |
cancel |
wait |
limit |
3 What does a lock timeout do?
- Runs a query
- Releases a lock
- Sets a time limit Correct answer
- Adds an index
Explanation: A lock timeout sets a time limit.