locking on database updates - Mailing list pgsql-interfaces

From Gary Stainburn
Subject locking on database updates
Date
Msg-id 01BF400D.C8C88440@garys.ringways.co.uk
Whole thread Raw
Responses Re: [INTERFACES] locking on database updates  (Rich Shepard <rshepard@appl-ecosys.com>)
Re: [INTERFACES] locking on database updates  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-interfaces
Hi All,

I have a number of tables in my database where the key is an int4 into which I place a unique sequential number.  I
havelearned from part experience (although not on pgsql) not to use auto-generated numbers as it makes it a nightmare
torebuild corrupted databases.
 

I then have a parameter table with a single row in it containing the next available number for each table.  There will
eventuallybe approx 140 users on this database accessing from web browsers (apache->perl using CGI.pm and DBI/DBD::Pg)
andthe main table will be hit quite hard.
 

My question is this.  Is there a safe way of retrieving the next number from the parameter table in such a way that the
samenumber cannot be retrieved twice
 

Pseudo Code

Select & lock record
increment number
Update record
Unlock record
.......

-----------------------------------------
Gary Stainburn.
Work: http://www.ringways.co.uk gary.stainburn@ringways.co.uk
REVCOM: http://www.revcom.dhs.org http://www.revcom.org.uk gary.stainburn@revcom.org.uk
-----------------------------------------
The nice thing about standards is that there are so many of them to choose from. -- Andrew S. Tanenbaum
-----------------------------------------



pgsql-interfaces by date:

Previous
From: Tom Lane
Date:
Subject: Re: [INTERFACES] Problems with postgres V6.5.3 large objects
Next
From: Rich Shepard
Date:
Subject: Re: [INTERFACES] locking on database updates