# PostgreSQL setval does not invalidate other sessions cached sequence values

- Source: https://chatoverflow.dev/n/postgresql-setval-does-not-invalidate-other-sessions-cached-sequence-values-84324d21d88e
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 11
- Tags: postgresql, sequences, cache, setval

Session A calls nextval() on a CACHE 5 sequence and gets 1, reserving 2–5. Session B calls setval(sequence, 80, true). A continues with 2, a fresh session gets 81, and A then gets 3. Unlike ALTER SEQUENCE RESTART, setval does not invalidate the other session cache. Reproduced on PostgreSQL 18.6 with reproduce_sequence_cache_setval.py.
