Created
December 27, 2011 13:12
-
-
Save shyiko/1523620 to your computer and use it in GitHub Desktop.
PostgreSQL Advisory Locking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<tableid> = select oid from pg_class where relname = '<tablename>'; | |
<rowid> = select id from ( | |
select rr.id from <tablename> rr left join pg_locks pgl | |
on pgl.classid = <tableid> and pgl.objid = rr.id | |
where pgl.objid is null limit 1 | |
) iq where pg_try_advisory_lock(<tableid>, id); | |
-- select * from pg_locks where locktype = 'advisory'; | |
select pg_advisory_unlock(<tableid>, <rowid>); |
select pg_try_advisory_lock(<tableid>, id) from <tablename> where id = <rowid>;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://www.postgresql.org/docs/9.1/interactive/functions-admin.html