<p>I ran into the problem that my primary key sequence is not in sync with my table rows. </p>

<p>That is, when I insert a new row I get a duplicate key error because the sequence implied in the serial datatype returns a number that already exists.</p>

<p>It seems to be caused by import/restores not maintaining the sequence properly.</p>

Try
reindex
.
UPDATE: As pointed out in the comments, this was in reply to the original question.