Re: Request for Insights on ID Column Migration Approach

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Peter J(dot) Holzer" <hjp-pgsql(at)hjp(dot)at>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Request for Insights on ID Column Migration Approach
Date: 2024-09-27 22:37:35
Message-ID: 729478.1727476655@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Peter J. Holzer" <hjp-pgsql(at)hjp(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Durgamahesh Manne 2024-09-28 04:25:57 Regarding use of single column as primary key on partitioned table
Previous Message Peter J. Holzer 2024-09-27 22:27:42 Re: Request for Insights on ID Column Migration Approach