Re: BUG #16430: Sequence with cache > 1 makes it increment by number specified as cache - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #16430: Sequence with cache > 1 makes it increment by number specified as cache
Date
Msg-id 22565.1589298165@sss.pgh.pa.us
Whole thread Raw
In response to BUG #16430: Sequence with cache > 1 makes it increment by number specified as cache  (PG Bug reporting form <noreply@postgresql.org>)
List pgsql-bugs
PG Bug reporting form <noreply@postgresql.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



pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #16430: Sequence with cache > 1 makes it increment by number specified as cache
Next
From: Sergei Kornilov
Date:
Subject: Re: BUG #16430: Sequence with cache > 1 makes it increment by number specified as cache