From: | Chris Angelico <rosuav(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: How to don't update sequence on rollback of a transaction |
Date: | 2012-08-02 16:30:09 |
Message-ID: | CAPTjJmrc=0CQWU7L2Z1L+pYrOOQp=HxCCvNmA4EQAaSOh=BqMw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Fri, Aug 3, 2012 at 1:08 AM, Frank Lanitz <frank(at)frank(dot)uvena(dot)de> wrote:
> My understanding of all was that it includes sequences. Obviously, I'm
> wrong... but how to do it right?
Sequences are fast and lock-free, but don't guarantee absence of gaps.
Quite a few things can unexpectedly advance a sequence (including
master-slave failover in replication - I've noticed IDs jump by about
32).
What should happen when two transactions simultaneously want a new ID?
Should the second block, waiting for the first one to commit or roll
back? Or will you allow the gaps, just as long as they get filled in
later?
The easiest way is probably to have a dedicated table of available
numbers, and use DELETE ... RETURNING to get the next one.
ChrisA
From | Date | Subject | |
---|---|---|---|
Next Message | Ingmar Brouns | 2012-08-02 16:47:22 | The semantics of (NULL,NULL) vs NULL |
Previous Message | Bruce Momjian | 2012-08-02 16:07:16 | Re: "seeking help to collect some postgres meta data" |