Re: handling concurrency right why am i wrong? - Mailing list pgsql-novice

From Tom Lane
Subject Re: handling concurrency right why am i wrong?
Date
Msg-id 18546.1296493656@sss.pgh.pa.us
Whole thread Raw
In response to handling concurrency right why am i wrong?  (Christian Brennsteiner <eingfoan@yahoo.de>)
Responses Re: handling concurrency right why am i wrong?  (Christian Brennsteiner <eingfoan@yahoo.de>)
List pgsql-novice
Christian Brennsteiner <eingfoan@yahoo.de> writes:
> i have a simple updateable view V with a status field S.
> ...
> each clients tries to ----------------- update V set S ='$MYCLIENTID' where
> S = 'TOBEPROCESSED'
> in this way i try to reserve the current available data TOBEPROCESSED for
> one client and then process it.
> when i do this i sometimes (if they overlap) get the following exception:
> Stacktrace: java.sql.SQLException: ERROR: deadlock detected

There are no "simple updateable views" in Postgres.  Your problem is
probably traceable to some aspect of the view update rule, or possibly
something about foreign keys or other actions that have to be taken
pursuant to the update on the underlying table.  But since you haven't
shown us any of the schema details, it's impossible to do more than
guess.

In general it seems like you're trying to reinvent a queuing mechanism.
You'd be better off adopting one of the existing ones, as getting this
both right and high-performing is harder than one might think.

            regards, tom lane

pgsql-novice by date:

Previous
From: Christian Brennsteiner
Date:
Subject: handling concurrency right why am i wrong?
Next
From: Leon Starr
Date:
Subject: Re: How to 'print a table' in the middle of a plpgsql function