When Postgres blocks: tips for dealing with locks
citusdata.com
citusdata.com
I am extremely grateful that some people have created awesome libraries like strong migrations https://github.com/ankane/strong_migrations.
Even if you are not using rails, you can bookmark its readme, it is an awesome cheat-sheet on how to do common database migrations.
The closest tool I've found here is: https://atlasgo.io/
https://www.depesz.com/2018/04/04/waiting-for-postgresql-11-...
This was one of the huge features I was excited about when it dropped!
Updating all rows can lock reading forever, so I'd like to do:
loop
UPDATE items SET last_update = now() WHERE last_update IS NULL LIMIT 10000
commit
until no rows modified- add the column which allows null values
- backfill in batches
- use triggers to auto-populate for new inserts
- add a check constraint
- and now the hack: set the column to not null using pg_attribute.attnotnull