Re: Adding a non-null column without noticeable downtime

From: Sameer Kumar <sameer(dot)kumar(at)ashnik(dot)com>
To: Zev Benjamin <zev-pgsql(at)strangersgate(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Adding a non-null column without noticeable downtime
Date: 2014-02-25 18:56:19
Message-ID: CADp-Sm5S6nUQBoPEqDRjp6RSBTMfOGg93QXL9XLUk+yEfXyhGA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I think index should help.
Why don't you try it out and check the explain plan of it?
If you are planning to break it down as below:
1. ALTER TABLE "foo" ADD COLUMN "bar" boolean;
2. UPDATE foo SET bar = False; -- Done in batches
3. ALTER TABLE "foo" ALTER COLUMN "bar" SET DEFAULT False;
4. ALTER TABLE "foo" ALTER COLUMN "bar" SET NOT NULL;

I would suggest on interchanging operation 2 and 3 in sequence

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message john gale 2014-02-25 19:43:38 cannot delete corrupted rows after DB corruption: tuple concurrently updated
Previous Message Zev Benjamin 2014-02-25 17:20:16 Re: Adding a non-null column without noticeable downtime