Re: How to add columns faster

From: Christophe Pettus <xof(at)thebuild(dot)com>
To: yudhi s <learnerdatabase99(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: How to add columns faster
Date: 2024-03-03 20:00:03
Message-ID: 1C6E9170-65F0-4F16-85E1-97C422699702@thebuild.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> On Mar 3, 2024, at 11:40, yudhi s <learnerdatabase99(at)gmail(dot)com> wrote:
> Thanks for the clarification. In case of adding the column as volatile default (like current_timestamp function as default) or say adding NOT NULL column with some conditional population of existing values will be a full table rewrite. In such scenarios, the full table rewrite operation is going to take a long time , so what will be the fastest way to achieve that with minimal to no downtime?

For other situations, you probably have to create the column as NULL-able, and then backfill it in groups of records until the whole column is populated. Remember that dropping the NULL constraint afterwards will require a full table read (although not a rewrite).

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Christophe Pettus 2024-03-03 20:03:07 Re: How to add columns faster
Previous Message yudhi s 2024-03-03 19:40:01 Re: How to add columns faster