Re: pg_dump & restore question regarding creating with serial - Mailing list pgsql-novice

From Josh Berkus
Subject Re: pg_dump & restore question regarding creating with serial
Date
Msg-id 200210041214.23306.josh@agliodbs.com
Whole thread Raw
In response to pg_dump & restore question regarding creating with serial  (Pam Wampler <Pam_Wampler@taylorwhite.com>)
List pgsql-novice
Pam,

> I am trying to make a copy of one database to another.  I have done the
> pg_dump and then psql -f filename into new database-- but when I look at a
> table that has been created with (id serial primary key) -- -- on the new
> database the id does not start at 1 but the number greater than the last id
> of the original table.  How can I make the id start at 1  -- I would have
> thought that the initial load into the new database would be an exact
> replica of the original database?

It *is* an exact replica ... including having the sequence for the table be at
whatever number the original database is at.  This is intentional and desired
behaviour.

>  id           | integer                     | not null default
> nextval('"inv_trans_id_seq"'::text)

After rebuilding the database, run:
SELECT SETVAL('inv_trans_id_seq', 1);

HOWEVER, I think you need some comprehension of Postgres sequences.
Fortunately, Justin has created a excellent animated flash tutorial on
sequences; see:
http://techdocs.postgresql.org/college/001_sequences/index.php

--
Josh Berkus
josh@agliodbs.com
Aglio Database Solutions
San Francisco

pgsql-novice by date:

Previous
From: Pam Wampler
Date:
Subject: pg_dump & restore question regarding creating with serial
Next
From: Pam Wampler
Date:
Subject: pg_dump & restore question regarding creating with seri al