I thought I understood "select ... for update," but maybe not.
We have a number of separate databases and a unique integer identifier that's supposed to be global across all databases. A single "archive" database is used to issue the next available ID when a process wants to create a new object. The sequence of operations goes like this (pseudo-code):
/* start a transaction *
begin;
/* see if an objectid has been returned for re-use */
select objectid from archive where db_id is null limit 1 for update
/* no ID available? issue a new one */
if (objectid is null)
new_id = select nextval('object_id_sequence')
insert into archive(objectid, db_id) values('new_id', 'new_id')
/* ID available? claim it */
else
update archive set db_id = this_db_id where objectid
commit
The problem is that very occasionally the same ID will be issued twice. I don't see how this can be. Doesn't the "for update" guarantee that no other process can claim that same row?
Thanks,
Craig
--
Sent via pgsql-admin mailing list (pgsql-admin@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin