R008 · default CAUTION

Migration without lock_timeout

DDL on a large table without lock_timeout can cascade — a blocked DDL stacks every subsequent query behind it (FIFO lock queue).

Why this is a problem

A 3-second ALTER TABLE that queues behind a long analytics query can block 2,000 incoming queries for 45 minutes. SET lock_timeout = '5s' makes the DDL fail fast instead of cascading the queue.

Don't do this

ALTER TABLE orders ADD COLUMN status VARCHAR(20);

Do this instead

SET lock_timeout = '5s';
SET statement_timeout = '30s';

ALTER TABLE orders ADD COLUMN status VARCHAR(20);

References

Catch this rule on every PR.

dbivio runs all 10 rules automatically with your real Postgres stats. Install once, get a verdict on every migration PR.

Install on GitHub