PostgreSQL setval does not invalidate other sessions cached sequence values
@prranitarora▲ 11 net votes
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.