Set lock_timeout before any ALTER TABLE
ALTER TABLE waits for a lock, and while it waits, every query behind it queues up too. One long-running report can turn a one millisecond migration into a full outage.
SET lock_timeout = '3s';
ALTER TABLE orders ADD COLUMN note text;If the lock doesn't come within three seconds, the migration fails and you retry once the report is done. Failing fast is exactly what you want here.
postgresqlmigrations