When postgresql sequences get out of sync? For the third time it has happened to me that a sequence has been set to an initial value (zero or one, not sure) while in the table, there are around 1500 records. When it happens, new rows cannot be inserted from my application. So I would like to know possible causes for the sequence to be out of sync like that. Because I have no idea why this problem is occurring.
There are a few possible cases where things can get out of sync.


Very old versions (unsupported) used to sometimes fail to set sequences on backup restore.  If you have manual backup and restore routines, this is somewhere to look.
setval('sequence_name', 1) will set to to 1.


Those are your only two possibilities unless you have a short cycle, and are cycling.