SELECT blocks UPDATE

From: twoflower <standa(dot)kurik(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: SELECT blocks UPDATE
Date: 2015-08-13 13:39:42
Message-ID: 1439473182689-5862040.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

if I am reading the documentation on explicit locking
<http://www.postgresql.org/docs/current/interactive/explicit-locking.html#LOCKING-TABLES>
correctly, SELECT should never conflict with UPDATE. However, what I am
observing as a result of this monitoring query:

SELECT bl.pid AS blocked_pid,
&nbsp;&nbsp;&nbsp;&nbsp;a.usename AS blocked_user,
&nbsp;&nbsp;&nbsp;&nbsp;ka.query AS blocking_statement,
&nbsp;&nbsp;&nbsp;&nbsp;now() - ka.query_start AS blocking_duration,
&nbsp;&nbsp;&nbsp;&nbsp;kl.pid AS blocking_pid,
&nbsp;&nbsp;&nbsp;&nbsp;ka.usename AS blocking_user,
&nbsp;&nbsp;&nbsp;&nbsp;a.query AS blocked_statement,
&nbsp;&nbsp;&nbsp;&nbsp;now() - a.query_start AS blocked_duration
FROM pg_catalog.pg_locks bl
JOIN pg_catalog.pg_stat_activity a ON a.pid = bl.pid
JOIN pg_catalog.pg_locks kl ON kl.transactionid = bl.transactionid AND
kl.pid != bl.pid
JOIN pg_catalog.pg_stat_activity ka ON ka.pid = kl.pid
WHERE NOT bl.granted;

is this
*Blocking statement*: SELECT tmtranslat0_.id as id164_0_, tmtranslat1_.id as
id101_1_, tmlanguage2_.id as id73_2_, ... FROM "TRANSLATION" ...
*Blocked statement*: UPDATE "TRANSLATION" SET fk_assignment_queue_item =
1000211 WHERE id IN (47032216)

I don't remember ever having problems with things like this. I am not even
issuing SQL queries in parallel from my application (the execution is
single-threaded). Now my application is stuck on the UPDATE statement.

1) How is it possible that these two statements block?
2) What can I do about it?

Thank you.

--
View this message in context: http://postgresql.nabble.com/SELECT-blocks-UPDATE-tp5862040.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Melvin Davidson 2015-08-13 13:46:49 Re: PostgreSQL - The Best Overall Database
Previous Message John McKown 2015-08-13 13:21:44 Re: PostgreSQL - The Best Overall Database