Adding a non-null column without noticeable downtime - Mailing list pgsql-general

From Zev Benjamin
Subject Adding a non-null column without noticeable downtime
Date
Msg-id 530C10CF.4020101@strangersgate.com
Whole thread Raw
Responses Re: Adding a non-null column without noticeable downtime  (Zev Benjamin <zev-pgsql@strangersgate.com>)
Re: Adding a non-null column without noticeable downtime  (Sameer Kumar <sameer.kumar@ashnik.com>)
Re: Adding a non-null column without noticeable downtime  (Sergey Konoplev <gray.ru@gmail.com>)
Re: Adding a non-null column without noticeable downtime  (Vik Fearing <vik.fearing@dalibo.com>)
List pgsql-general
Hi all,

I'm sure this has been answered somewhere, but I was not able to find
anything in the list archives.

I'm conceptually trying to do
ALTER TABLE "foo" ADD COLUMN "bar" boolean NOT NULL DEFAULT False;

without taking any noticeable downtime.  I know I can divide the query
up like so:

ALTER TABLE "foo" ADD COLUMN "bar" boolean;
UPDATE foo SET bar = False; -- Done in batches
ALTER TABLE "foo" ALTER COLUMN "bar" SET DEFAULT False;
ALTER TABLE "foo" ALTER COLUMN "bar" SET NOT NULL;

The first 3 queries shouldn't impact other concurrent queries on the
system.  My question is about the sequential scan that occurs when
setting the column NOT NULL.  Will that sequential scan block other
inserts or selects on the table?  If so, can it be sped up by using an
index (which would be created concurrently)?


Thanks,
Zev


pgsql-general by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: plans for plpython in RDS?
Next
From: Frank Broniewski
Date:
Subject: Re: Hard upgrade (everything)