Re: What's the best way to deal with the pk_seq sequence value after a restore (bulk loading)?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Wang, Mary Y" <mary(dot)y(dot)wang(at)boeing(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: What's the best way to deal with the pk_seq sequence value after a restore (bulk loading)?
Date: 2010-03-06 16:05:33
Message-ID: 145.1267891533@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Wang, Mary Y" <mary(dot)y(dot)wang(at)boeing(dot)com> writes:
> After a restore, I got a lot errors like this one : "duplicate key value violates unique constraint "bug_pkey"". After looking at the dump file, it has
> ...
> Because the current value is 6818, during the restore process, it
> complained about "duplicate key value violates unique constraint
> "bug_pkey, because the value of bug_pk_seq for a insert has been
> already been used.

No, the setting of the sequence doesn't have anything to do with that,
because the dumped data doesn't rely on using the column's default
expression. It's pretty strange to get such an error during restore,
though. It implies that the data was inconsistent in the original
database.

Or are you saying that after you've completed the restore, subsequent
attempts to insert get that type of error? If that's the case, what
you need to do is set the sequence value *higher* than the max value
currently present in the table, not reset it to 1.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Wang, Mary Y 2010-03-06 19:01:08 Re: What's the best way to deal with the pk_seq sequence value after a restore (bulk loading)?
Previous Message Tom Lane 2010-03-06 15:27:30 Re: 9.0 VACUUM FULL vs. ALTER TABLE?