PostgreSQL and Ruby on Rails locks and migrations

Here are two excellent posts on PostgreSQL locks. My particular interest was locks in relation to adding a column to a table in a Rails migration in a busy system. TLDR: Adding a column needs a lock on the table even if there is no default and no not null constraint. If the table is busy, your alter table statement might take a while to get a lock. While it’s waiting, it can cause other queries to also wait. In a busy system, you might not be able to get the lock you need to add the column, and if you increase your lock timeout to wait longer to get a lock, you might impact production systems (e.g. web traffic, background jobs, etc.) http://www.joshuakehn.com/2017/9/9/postgresql-alter-table-and-long-transactions.html https://medium.com/doctolib/stop-worrying-about-postgresql-locks-in-your-rails-migrations-3426027e9cc9