HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

When postgresql sequences get out of sync?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
postgresqlgetwhensequencesoutsync

Problem

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.

Solution

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.

Context

StackExchange Database Administrators Q#47719, answer score: 3

Revisions (0)

No revisions yet.