In PostgreSQL 12+, the best practice for safely adding a NOT NULL constraint to an existing column is to add a check constraint with NOT VALID and then run VALIDATE CONSTRAINT. Explanation by ...