Re: BUG #16430: Sequence with cache > 1 makes it increment by number specified as cache

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: val(dot)janeiko(at)gmail(dot)com
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #16430: Sequence with cache > 1 makes it increment by number specified as cache
Date: 2020-05-12 15:42:45
Message-ID: 22565.1589298165@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> When using Sequence inside a plpgsql function called using SELECT func()
> using Npgsql library a sequence is incremented by the value specified in
> CACHE.

If you're reconnecting for each query, this is the expected result.
Per the manual (see Notes under CREATE SEQUENCE):

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.

If you don't like it, don't use cache settings greater than one.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Sergei Kornilov 2020-05-12 15:44:24 Re: BUG #16430: Sequence with cache > 1 makes it increment by number specified as cache
Previous Message PG Bug reporting form 2020-05-12 14:47:04 BUG #16430: Sequence with cache > 1 makes it increment by number specified as cache