[PostgreSQL] Sequence의 조금 다른 Cache 특성.

시퀀스의 cache 설정은 세션레벨에서 동작 함. 
 
즉, cache 100 으로 설정했을때,
1번 세션에서 nextval하면 1이 표시되고
2번 세션에서 netxtval 하면 101 이 표시된다...

 

메뉴얼에는 관련내용을 cache 쪽에 설명을 하지 않고 notes 에 남겨놨다..

Unexpected results might be obtained if a cache setting greater than one is used for a sequence object that will be used concurrently by multiple sessions. Each session will allocate and cache successive sequence values during one access to the sequence object and increase the sequence object's last_value accordingly. Then, the next cache-1 uses of nextval within that session simply return the preallocated values without touching the sequence object. So, any numbers allocated but not used within a session will be lost when that session ends, resulting in "holes" in the sequence.

https://www.postgresql.org/docs/9.5/sql-createsequence.html