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

From: Ravi Tammineni <rtammineni(at)partner(dot)aligntech(dot)com>
To: 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-18 21:19:24
Message-ID: BN1PR02MB2318313D3F51BCC4B6B0CF280150@BN1PR02MB231.namprd02.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Hi Samed,

Thanks for the response.

But my question is, I have to add a new id column to the existing table, populate the data and then convert that column into primary key column. I am running the following command but its taking forever.

ALTER TABLE tblclinchecklog ADD COLUMN id serial primary key;

Is there a better way? Like

1> Add column

2> Create sequence

3> Update the table

4> Create index

5> Convert the index into pk index

Thanks
ravi

From: Samed YILDIRIM [mailto:samed(at)reddoc(dot)net]
Sent: Thursday, August 18, 2016 2:05 PM
To: Ravi Tammineni <rtammineni(at)partner(dot)aligntech(dot)com>; pgsql-admin(at)postgresql(dot)org
Subject: Re: [ADMIN] What is the best way to create Primary Key on a large table in Postgresql 9.5?

Hi Ravi,

You can use CREATE INDEX with CONCURRENTLY keyword. It will not lock your table during the process.

Best regards.

İyi çalışmalar.
Samed YILDIRIM

19.08.2016, 00:01, "Ravi Tammineni" <rtammineni(at)partner(dot)aligntech(dot)com<mailto:rtammineni(at)partner(dot)aligntech(dot)com>>:
I have to create a primary key on a large table (~100Million records). What is the best and fastest way to create pkey? This column is a sequence column and i don't want to lock the table because this is highly transactional database.

Thanks

ravi

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message David G. Johnston 2016-08-18 21:48:18 Re: What is the best way to create Primary Key on a large table in Postgresql 9.5?
Previous Message David G. Johnston 2016-08-18 21:16:54 Re: What is the best way to create Primary Key on a large table in Postgresql 9.5?