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

From Tom Lane
Subject Re: What's the best way to deal with the pk_seq sequence value after a restore (bulk loading)?
Date
Msg-id 145.1267891533@sss.pgh.pa.us
Whole thread Raw
In response to What's the best way to deal with the pk_seq sequence value after a restore (bulk loading)?  ("Wang, Mary Y" <mary.y.wang@boeing.com>)
Responses Re: What's the best way to deal with the pk_seq sequence value after a restore (bulk loading)?  ("Wang, Mary Y" <mary.y.wang@boeing.com>)
List pgsql-general
"Wang, Mary Y" <mary.y.wang@boeing.com> writes:
> After a restore, I got a lot errors like this one : "duplicate key value violates unique constraint "bug_pkey"".
Afterlooking 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

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: 9.0 VACUUM FULL vs. ALTER TABLE?
Next
From: "Wang, Mary Y"
Date:
Subject: Re: What's the best way to deal with the pk_seq sequence value after a restore (bulk loading)?