PG Bug reporting form <noreply@postgresql.org> writes:
> It has been observed that the sequences are starting with a gap of around 30
> ( more or less) the next day. The sequences are generated sequentially
> (continuous with no gaps) on/within the same day. However once the
> application/server is stopped and restarted the next day , the sequence
> starts with a gap ( mostly around 30 or may be 10 , 20 etc).
This is expected behavior, as a result of optimization to reduce the
amount of WAL traffic generated by nextval calls. The optimization
is not user-adjustable (cf. SEQ_LOG_VALS in sequence.c).
It's not particularly worth doing something about it, because if your
application requires a gapless sequence, you cannot use Postgres
sequence objects to get that anyway. Transactions that roll back
after executing a nextval() will also cause gaps.
regards, tom lane