We have a very large table (1 Million records) in some cases and we need to add boolean fields to it which have default values. If we add only column it takes 3 minutes and we add 3 columns in the same statement it takes same time.
$ALTER TABLE Job ADD COLUMN test BOOLEAN NOT NULL default false;
ALTER TABLE
Time: 186506.603 ms
$ALTER TABLE Job ADD COLUMN test BOOLEAN NOT NULL default false ,
ADD COLUMN test1 BOOLEAN NOT NULL default false,
ADD COLUMN test2 BOOLEAN NOT NULL default false;
ALTER TABLE
Time: 179055.546 ms
We are on Postgres 9.1 . Is there a postgres feature allows to add multiple boolean fields with default values in one shot? This is for a database change management /upgrade solution . Is it better than using temp table to copy and insert to add multiple boolean fields with default values to a table ? The temp table approach is described in this blog: http://blog.codacy.com/2015/05/14/how-to-update-large-tables-in-postgresql/