CodeBlanks Logo Icon CodeBlanks

Lock timeout

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

query.sql
-- set timeout
SET

Sample solution

query.sql
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

Question
SET ____ = '5s';
Answer
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.

All lessons in Advanced