Andy Chambers <achambers(at)mcna(dot)net> writes:
> When testing the failover procedure, we noticed that when the new master
> comes up, some sequences have moved forward (by between 30 and 40). I see
> there's a "cache" option when creating the sequence but we're not using
> that.
> Is this to be expected?
Yes. This is an artifact of an optimization that reduces the number of
WAL records generated by nextval() calls --- server processes will write
WAL records that say they've consumed multiple sequence values ahead of
where they actually have.
AFAICS this is not distinguishably different from the case where a
transaction consumes that number of sequence values and then rolls back,
so I don't see much wrong with that optimization.
regards, tom lane