Re: Request for Insights on ID Column Migration Approach - Mailing list pgsql-general

From Tom Lane
Subject Re: Request for Insights on ID Column Migration Approach
Date
Msg-id 729478.1727476655@sss.pgh.pa.us
Whole thread Raw
In response to Request for Insights on ID Column Migration Approach  (Aditya Singh <aditya.singh@lji.io>)
List pgsql-general
"Peter J. Holzer" <hjp-pgsql@hjp.at> writes:
> As you can see, adding the primary key takes just as much time as
> creating the unique index. So it doesn't look like PostgreSQL is able to
> take advantage of the existing index (which makes sense since it still
> has to create a new index).

No, but you can attach an existing unique index as a primary key:

regression=# create table t1 (f1 int not null);
CREATE TABLE
regression=# create unique index t1_f1 on t1(f1);
CREATE INDEX
regression=# alter table t1 add primary key using index t1_f1;
ALTER TABLE

If you build the unique index concurrently, this needn't involve
much downtime.

            regards, tom lane



pgsql-general by date:

Previous
From: yudhi s
Date:
Subject: Re: Suggestion for memory parameters
Next
From: Durgamahesh Manne
Date:
Subject: Regarding use of single column as primary key on partitioned table