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

From Wang, Mary Y
Subject What's the best way to deal with the pk_seq sequence value after a restore (bulk loading)?
Date
Msg-id FA20D4C4FEBFD148B1C0CB09913825FC01EBE7D3B9@XCH-SW-06V.sw.nos.boeing.com
Whole thread Raw
Responses Re: What's the best way to deal with the pk_seq sequence value after a restore (bulk loading)?  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: What's the best way to deal with the pk_seq sequence value after a restore (bulk loading)?  (Dimitri Fontaine <dfontaine@hi-media.com>)
List pgsql-general
Hi All,

After a restore, I got a lot errors like this one : "duplicate key value violates unique constraint "bug_pkey"".  After
lookingat the dump file, it has 

CREATE SEQUENCE bug_pk_seq
    INCREMENT BY 1
    MAXVALUE 2147483647
    NO MINVALUE
    CACHE 1;

ALTER TABLE
SELECT pg_catalog.setval('bug_pk_seq', 6818, true);
 setval
--------
   6818
(1 row)

Here is the bug table
CREATE TABLE bug (
    bug_id integer DEFAULT nextval('bug_pk_seq'::text) NOT NULL,
    group_id integer DEFAULT '0' NOT NULL,
    status_id integer DEFAULT '0' NOT NULL,
    priority integer DEFAULT '0' NOT NULL,
    category_id integer DEFAULT '0' NOT NULL,
    submitted_by integer DEFAULT '0' NOT NULL,
    assigned_to integer DEFAULT '0' NOT NULL,
    date integer DEFAULT '0' NOT NULL,
    summary text,
    details text,
    close_date integer,
    bug_group_id integer DEFAULT '0' NOT NULL,
    resolution_id integer DEFAULT '0' NOT NULL
);

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.  So what is the best way
toresolve this?  Should I set the value for bug_pk_seq to be 1 in the beginning of the dump file? 

Any suggestions?

Mary



pgsql-general by date:

Previous
From: Pedro Doria Meunier
Date:
Subject: Re: need some advanced books on Postgres
Next
From: Craig Ringer
Date:
Subject: Re: Optimizations