Re: What is the best way to create Primary Key on a large table in Postgresql 9.5? - Mailing list pgsql-admin

From Feike Steenbergen
Subject Re: What is the best way to create Primary Key on a large table in Postgresql 9.5?
Date
Msg-id CAK_s-G1-k0yQ-HAO+LDR7MFTbRT1vJmq-dYFrLqfiEBB8zET3g@mail.gmail.com
Whole thread Raw
In response to Re: What is the best way to create Primary Key on a large table in Postgresql 9.5?  (Ravi Tammineni <rtammineni@partner.aligntech.com>)
List 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:

Regards,

Feike

pgsql-admin by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: pg_upgrade question
Next
From: koffi BADOH
Date:
Subject: tools to centralize postgreSQL account management