Re: What is the best way to create Primary Key on a large table in Postgresql 9.5?

From: Feike Steenbergen <feikesteenbergen(at)gmail(dot)com>
To: Ravi Tammineni <rtammineni(at)partner(dot)aligntech(dot)com>
Cc: Samed YILDIRIM <samed(at)reddoc(dot)net>, "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>
Subject: Re: What is the best way to create Primary Key on a large table in Postgresql 9.5?
Date: 2016-08-24 12:08:12
Message-ID: CAK_s-G1-k0yQ-HAO+LDR7MFTbRT1vJmq-dYFrLqfiEBB8zET3g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

What we would do when having to update a large table is do it in multiple
transactions. Basically:

1. create sequence s1;
2. alter table t1 add column c1 integer default nextval('s1'); -- Ensure
new values don't need changing anymore
3. In batches of a significant but not huge amount of rows: update t1 set
c1=nextval('s1');
4. Create index
5. Convert the index into pk index

We use niceupdate (home brew tool) for this, it may suit your needs:
https://github.com/zalando/acid-tools/wiki/Niceupdate

Regards,

Feike

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message koffi BADOH 2016-08-24 16:55:01 tools to centralize postgreSQL account management
Previous Message Bruce Momjian 2016-08-23 20:20:07 Re: pg_upgrade question