choosing the right locking mode

From: rihad <rihad(at)mail(dot)ru>
To: pgsql-general(at)postgresql(dot)org
Subject: choosing the right locking mode
Date: 2008-04-03 16:44:55
Message-ID: 47F50987.1010603@mail.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Given this type query:

UPDATE bw_pool
SET user_id=?
WHERE bw_id=
(SELECT MIN(bw_id) FROM bw_pool WHERE user_id IS NULL)
RETURNING bw_id

The idea is to "single-threadedly" get at the next available empty slot,
no matter how many such queries run in parallel. So far I've been
semi-successfully using LOCK TABLE bw_pool before the UPDATE, but it
deadlocks sometimes. Maybe I could use some less restrictive locking
mode and prevent possible collisions at the same time?

Thanks.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message D'Arcy J.M. Cain 2008-04-03 16:46:30 Re: modules
Previous Message Joshua D. Drake 2008-04-03 16:41:57 Re: modules