pg advisory locks - Mailing list pgsql-general

From Arun Gokule
Subject pg advisory locks
Date
Msg-id CAEAJEXevTD_t2Umd80Q7GahWcrU7Nqc01UPGf6i7vdhJ7uzFnQ@mail.gmail.com
Whole thread Raw
Responses Re: pg advisory locks  (Arun Gokule <arun.gokule@gmail.com>)
Re: pg advisory locks  (Alban Hertroys <haramrae@gmail.com>)
List pgsql-general
Hi,

I am executing pg_advisory_locks using the following set of statements:

 SELECT pg_advisory_lock(317,2);
 UPDATE posts SET dislikers = array_remove(dislikers, 7) WHERE id = 317;
 update posts set num_dislikes = icount(dislikers), updated_at = now() where id = 317;
 WITH update_likers AS (SELECT pg_advisory_unlock(317,2)) select num_likes, num_dislikes, (7 IN (select(unnest(likers)))) as liked, (7 IN (select(unnest(dislikers)))) as disliked from posts where id = 317 LIMIT 1;

These are issued from a multithreaded app. One in 1000 queries, I get a deadlock after the execution of the above set of statements. i.e.  SELECT try_pg_advisory_lock(317,2) returns false. Is there something obvious that I am doing wrong?

Thanks,
Arun

pgsql-general by date:

Previous
From: Jeff Janes
Date:
Subject: Re: Processor usage/tuning question
Next
From: Arun Gokule
Date:
Subject: Re: pg advisory locks