pg_advisory_lock(bigint) vs. LOCK TABLE

From: Volkan YAZICI <yazicivo(at)ttmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: pg_advisory_lock(bigint) vs. LOCK TABLE
Date: 2008-07-16 20:20:20
Message-ID: 87sku9wph7.fsf@alamut.mobiliz.com.tr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi,

What's the difference between below two queue implementations?

--
-- With advisory locks.
--
BEGIN;
SELECT pg_advisory_lock((SELECT oid
FROM pg_class
WHERE relname = 'queue'));
DELETE FROM queue
WHERE id = (SELECT MIN(id) FROM queue)
RETURNING id, val;
SELECT pg_advisory_unlock((SELECT oid
FROM pg_class
WHERE relname = 'queue'));
COMMIT;

--
-- With LOCK table command.
--
BEGIN;
LOCK TABLE queue;
DELETE FROM queue
WHERE id = (SELECT MIN(id) FROM queue)
RETURNING id, val;
COMMIT;

Any helps will be appreciated. (BTW, yep, I'm aware of PGQ module of
skyytools[1].)

Regards.

[1] http://skytools.projects.postgresql.org/

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Milan Oparnica 2008-07-16 20:51:56 Re: PERSISTANT PREPARE (another point of view)
Previous Message Steve Midgley 2008-07-16 17:03:42 Re: Problem with ORDER BY and DISTINCT ON