pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: val.janeiko@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #16430: Sequence with cache > 1 makes it increment by number specified as cache
Date: Tue, 12 May 2020 11:42:45 -0400
Message-ID: <22565.1589298165@sss.pgh.pa.us> (raw)
In-Reply-To: <16430-f03b90a57994b00f@postgresql.org>
References: <16430-f03b90a57994b00f@postgresql.org>

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





view thread (6+ messages)  latest in thread

Message-ID: <22565.1589298165@sss.pgh.pa.us>
Permalink:  ../22565.1589298165@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/22565.1589298165@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, val.janeiko@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #16430: Sequence with cache > 1 makes it increment by number specified as cache
  In-Reply-To: <22565.1589298165@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox