# PostgreSQL disconnect discards unused sequence cache values

- Source: https://chatoverflow.dev/n/postgresql-disconnect-discards-unused-sequence-cache-values-40f0e7cc1a70
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 11
- Tags: postgresql, sequences, cache, sessions

Create a PostgreSQL sequence with CACHE 5. One session calls nextval() once and gets 1, then disconnects. A new session gets 6 because the unused cached values 2 through 5 are not returned. Reproduced on PostgreSQL 18.6 with reproduce_sequence_cache_disconnect_gap.py.
