From: Tom Lane <tgl@sss.pgh.pa.us>
To: Laerson keler <laerson.keler@lkmc.com.br>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #6258: Lock Sequence
Date: Mon, 17 Oct 2011 15:43:09 -0400
Message-ID: <18368.1318880589@sss.pgh.pa.us> (raw)
In-Reply-To: <CAFk5V3O4NYQx+XQKVtmMdYY-U44oCEqBQG28tghjOGDMr-x8gQ@mail.gmail.com>
References: <201110171308.p9HD81vP028182@wwwmaster.postgresql.org>
<14643.1318866768@sss.pgh.pa.us>
<CAFk5V3O4NYQx+XQKVtmMdYY-U44oCEqBQG28tghjOGDMr-x8gQ@mail.gmail.com>
Laerson keler <laerson.keler@lkmc.com.br> writes:
> 2011/10/17 Tom Lane <tgl@sss.pgh.pa.us>
>> "Laerson Keler" <laerson.keler@lkmc.com.br> writes:
>> Why did you do that, that is what were you trying to accomplish? It
>> never did block nextval() on the sequence, for example.
> Tom Lane, good afternoon, I block the sequence not to miss the sequel, for
> it not to be skipped if the insert to fail. My logic involves two triggers,
> one before and one after. I give the first one in last_value select for
> update in the sequence and insert after I run a select next_val ('sequence')
> to place in the next issue, so the sequence in my table is no failure.
Well, that's a cute idea, but the fact is that it was always quite
unsafe because it had no interlock against nextval(). Moreover, you
still did not have a guarantee of no holes in the assigned ID values,
because the transaction could still fail after the AFTER trigger runs.
There really is not any way to generate guaranteed-hole-free sequences
using sequence objects. If you have to have that, I'd suggest locking
the table against other writes and then fetching MAX(id) + 1. It's not
very fast, and it's not at all concurrent, but that's the price of
ensuring no holes. Personally I'd rethink how badly you need that
property.
regards, tom lane
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, laerson.keler@lkmc.com.br
Subject: Re: BUG #6258: Lock Sequence
In-Reply-To: <18368.1318880589@sss.pgh.pa.us>
References: <201110171308.p9HD81vP028182@wwwmaster.postgresql.org> <14643.1318866768@sss.pgh.pa.us> <CAFk5V3O4NYQx+XQKVtmMdYY-U44oCEqBQG28tghjOGDMr-x8gQ@mail.gmail.com> <18368.1318880589@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