

Duplicate key violates unique constraint - gduplessy
http://gduplessy.com/2011/09/02/duplicate-key-violates-unique-constant.html

======
ilikepi
Did you do any research to determine why MAX(id) was greater than NEXTVAL()
for the sequence? That would be useful knowledge to add to your post (and,
presumably, for you to have).

~~~
prebholz
I see this every once and a while with Oracle when a production database is
exported and imported into another environment without using CONSISTENT=Y
(with the old exp command) or without using a FLASHBACK_TIME with the newer
expdp command.

The problem is that sequences are exported first so if any more rows are
inserted into tables using those sequences during the export process the
tables and sequences in the export will be out of sync. Adding CONSISTENT=Y or
a FLASHBACK_TIME allows you to export from a single point in time.

Edit: Since the OP was regarding PostgreSQL (which I'm unfamiliar with) I did
a quick google search that landed me on the pg_dump documentation. According
to the document exports should be consistent.
<http://www.postgresql.org/docs/9.0/static/app-pgdump.html>

