Re: Adding a non-null column without noticeable downtime

From: Zev Benjamin <zev-pgsql(at)strangersgate(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Adding a non-null column without noticeable downtime
Date: 2014-02-25 19:46:31
Message-ID: 530CF317.8050804@strangersgate.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

EXPLAIN does not appear to work on ALTER TABLE statements:

=> EXPLAIN ALTER TABLE "foo" ALTER COLUMN "bar" SET NOT NULL;
ERROR: syntax error at or near "ALTER"
LINE 1: explain ALTER TABLE "foo" ALTER COLUMN "bar" SET NOT NULL;
^

Zev

On 02/25/2014 01:56 PM, Sameer Kumar wrote:
> 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

Browse pgsql-general by date

  From Date Subject
Next Message Eliot Gable 2014-02-25 20:13:25 Re: JSON vs Text + Regexp Index Searching
Previous Message john gale 2014-02-25 19:43:38 cannot delete corrupted rows after DB corruption: tuple concurrently updated