Tech
The Postgres migration that locks your table at 3am, and how to catch it in review
-- looks fine in review, locks your busiest table in prod:
ALTER TABLE users ALTER COLUMN email SET NOT NULL ;
-- same result, no outage:
ALTER TABLE users ADD CONSTRAINT users_email_nn CHECK ( email IS NOT NULL ) NOT VALID ;
ALTER TABLE users VALIDATE CONSTRAINT users_email_nn ;
ALTER TABLE users ALTER COLUMN email SET NOT NULL ;
The top one scans every row under an ACCESS EXCLUSIVE lock, so every read...
Read the full discussion on Dev.to
This article was aggregated from Dev.to. Click to join the conversation.
View on Dev.to