Racing DEADLOCK on PostgreSQL 9.3

From: Nick Dro <postgresql(at)walla(dot)co(dot)il>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Racing DEADLOCK on PostgreSQL 9.3
Date: 2018-04-25 06:21:25
Message-ID: ^FE3BFDB238CE4E66D89474824607C15731984009@walla.co.il
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

<div dir='rtl'><div dir="ltr">Hi,</div>
<div dir="ltr">I have a stock table.</div>
<div dir="ltr">&nbsp;</div>
<div dir="ltr">One of the users in the system ran this query:&nbsp; update stock set quantity=quantity-5 where stockid=100&nbsp; (from his client application).</div>
<div dir="ltr">On the same time I ran from pg-admin this query:</div>
<div dir="ltr">&nbsp;</div>
<div dir="ltr">do $$<br />begin<br />alter table stock disable trigger stock_aftertrigger;<br />update stock set stock=0 where stockid=106;<br />alter table stock enable trigger stock_aftertrigger;<br />end; $$</div>
<div dir="ltr">&nbsp;</div>
<div dir="ltr">What actualy happened is that both queries were stuck on waiting (after 3 minutes I decided to investagate as there quries should be extremly fast!).</div>
<div dir="ltr">I ran also this query:</div>
<div dir="ltr">&nbsp;</div>
<div dir="ltr">
<div>SELECT<br /> pid,<br /> now() - pg_stat_activity.query_start AS duration,<br /> query,<br /> state, *<br />FROM pg_stat_activity<br />WHERE waiting</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>and both users were on waiting. When I stopped my query the other user got imiddiate result, then I reran mine which also finished immidiatly.</div>
<div>I don't understand why both queries were stuck, the logic thing is that one ran and the other one is waiting (if locks aquired etc) it doesnt make senece that both queries are on waiting. waiting for what exactly?</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>Any thoughts on this issue?</div>
</div></div>

Attachment Content-Type Size
unknown_filename text/html 1.5 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Munro 2018-04-25 06:23:26 Re: Excessive PostmasterIsAlive calls slow down WAL redo
Previous Message Heikki Linnakangas 2018-04-25 06:19:52 Re: Fsync request queue