← all rules

require-timeout

warning

Locking statement without a timeout

Why it's unsafe

This statement takes a lock but no lock_timeout is set — if it queues behind a slow query, it blocks every query on the table until it acquires the lock.

Safe rewrite

Set a bounded lock_timeout first, e.g. SET lock_timeout = '5s'; (or SET LOCAL inside a transaction), so the statement fails fast instead of piling up the lock queue. statement_timeout also satisfies this.

Example

Try it in the playground →

Unsafe

ALTER TABLE users ADD COLUMN note text;

Safe

SET lock_timeout = '5s';
ALTER TABLE users ADD COLUMN note text;

Related