Re: lock in access exclusive and sequence question - Mailing list pgsql-general

From Richard Huxton
Subject Re: lock in access exclusive and sequence question
Date
Msg-id 004501c0bda7$9e4cdf40$1001a8c0@archonet.com
Whole thread Raw
In response to lock in access exclusive and sequence question  ("Creager, Robert S" <CreagRS@LOUISVILLE.STORTEK.COM>)
List pgsql-general
From: "Creager, Robert S" <CreagRS@LOUISVILLE.STORTEK.COM>

> I'm creating a script which will re-claim sequence numbers in a table by
> 'packing' the existing sequence numbers.  My questions is if I lock the
> table in access exclusive mode, and an insert into that table occurs after
> the lock, with the insert be blocked before or after the nextval is
chosen?

If you do something like INSERT INTO foo VALUES (nextval('foo_seq')) it
seems to be before the nextval is chosen (based on testing against 7.1). I
don't know that this is guaranteed to remain the case, but it would seem
unlikely to change.

However - just doing a SELECT nextval('foo_seq') is unblocked so it will
depend how inserts/updates are performed.

I suppose you might also have a case where rules/triggers or the like could
evaluate a nextval() before an insert (triggers yes, rules probably not
*although that's just guesswork*)

Have you considered just extending the sequence numbers so you don't run
out? There's an example in my PostgreSQL notes linked from
techdocs.postgresql.org and also IIRC might well be in the pgsql cookbook.

HTH

- Richard Huxton


pgsql-general by date:

Previous
From: Peter T Mount
Date:
Subject: Re: JBuilder4 JDBC Explorer
Next
From: Peter T Mount
Date:
Subject: RE: JBuilder4 JDBC Explorer