Re: Converting non-null unique idx to pkey

From: "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com>
To: "Ed L(dot)" <pgsql(at)bluepolka(dot)net>
Cc: Postgres-General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Converting non-null unique idx to pkey
Date: 2007-08-21 19:45:55
Message-ID: dcc563d10708211245n1e0da70byc29270c234fb4bec@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 8/21/07, Ed L. <pgsql(at)bluepolka(dot)net> wrote:
>
> I'm preparing a fairly large 7.4.6 DB for trigger-based
> replication. I'm looking for ways to minimize my impact on the
> existing schema & data and uptime. This replication solution
> requires every table to have a primary key. Rather than adding
> a new key column and index for the pkey, it's appealing to just
> to reuse existing unique indices on non-null columns. Are there
> are any known or obvious gotchas associated with transforming a
> unique index on a non null column into a primary key via this
> sql?

What replication system is this? Slony only requires a unique key on
a not null column. If that's what you're using, see if alter it to
not null will get around this. Note you may have to update any null
values to something else first.

If you have a large db in 7.4.6, you should do two things.

1: Update to 7.4.19 or whatever the latest flavor of 7.4 is, right
now. There are a few known data eating bugs in 7.4.6.
2: Start planning a migration to 8.2.4 now. Start implementing it as
soon after that as you can.
3: Slony allows you to migrate from old to new versions, but only the
older versions of slony support 7.4.

>
> update pg_index
> set indisprimary = 't'
> where indexrelid = <my non-null unique index oid>

I wouldn't bet on that working right. Others know the internals of
the db better than me, but that looks like a foot gun.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tony Caduto 2007-08-21 19:51:15 Re: Need help doing a PostgreSQL vs Firebird feature comparison
Previous Message Ed L. 2007-08-21 19:45:12 Re: history table