Databases · Middle · Question 38 of 75

How do you add a NOT NULL column with a default to a huge table without long locks in modern PostgreSQL?

Explanation

Volatile defaults like random() still rewrite the table. For computed values, add a nullable column, backfill in batches, then add the constraint.

Further reading

Problem with a question

Databases · Middle · question 38

Test yourself

Take the Databases · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz