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.
Postgresql – When postgresql sequences get out of sync
postgresqlsequence
Related Question
- Oracle ROWID, can we assume it is sequential in a insert-only scenario
- PostgreSQL Sequence Problems – Manually Created PIDs and Proper Sequence Resetting
- Postgresql – Moving a PostgreSQL database to a different AWS RDS instance
- Postgresql – How to deal with the inevitable scenario when a table’s bigserial runs out of ids but many of the old records are deleted
- Postgresql – Is it possible to have xid before and after wrap around with the same timestamp
- Postgresql – Is it possible to use txid_current value for sync
Best Answer
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.