pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
regression, deadlock in high frequency single-row UPDATE
34+ messages / 8 participants
[nested] [flat]

Commits from this thread:
  2016-02-26 c9578135f7  Add isolationtester spec for old heapam.c bug
  2014-12-26 0e5680f473 0e3a1f71df 048912386d  Grab heavyweight tuple lock only before sleeping
* regression, deadlock in high frequency single-row UPDATE
@ 2014-07-31 23:30  Andrew Sackville-West <awest@janrain.com>
  0 siblings, 2 replies; 34+ messages in thread

From: Andrew Sackville-West @ 2014-07-31 23:30 UTC (permalink / raw)
  To: pgsql-bugs

Hi,

I've discussed this problem on irc a couple of times and think I've
found a regression that plagues our application, introduced in some
version newer than 9.1.9, and still present in 9.3.5.

Multiple instances of the *exact* same single row update:

UPDATE
       "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag
SET
        last_issued=DEFAULT
FROM
        "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc
WHERE
        oc.id = ag.client_id
        AND ag.entity_name = 'user'
        AND ag.entity_id = 129
        AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f'
RETURNING
        ag.id
;

if performed with sufficient concurrency will produce a deadlock.

I've attached a snippet of logs, all uncommented lines from
postgresql.conf, and the table definitions of the involved
tables. This first instance of the deadlock appears in line 142; I
left a bunch of lead-in in case it's relevant.

I think this is a regression as we only see the behavior under
postgres 9.3.x (reproduced locally on 9.3.4 and 9.3.5 in a VMWare VM
running Ubuntu 11.04, but also evident in 9.3.3 on Amazon RDS). I am
unable to reproduce in the earlier versions I've been able to test against
(9.0.something and 9.1.9).

To reproduce the problem, I have to fork about 100 api calls against
our application, with the results you see in the logs. The queries in
the log are the *only* activity in the application and database at the
time and I have not filtered the logs at all, other than snipping to a
reasonable window around the problem. I can produce more extensive
logs if needed, but there really is nothing else.

I have not been able to reproduce the deadlock by making concurrent
UPDATEs via what amounts to a bash fork-bomb w/ psql, but I suspect my
methodology might be too crude there. The application is able to spin
up a large number of lightweight threads fairly quickly and presumably
attain the needed level of concurrency.

Thanks,

A

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

deadlock_log (text/plain, 55.5K) download 2014-07-30 09:41:53 PDT PID:4727 XID:0 LOG: statement: SET standard_conforming_strings TO on;SET datestyle TO ISO 2014-07-30 09:41:53 PDT PID:4727 XID:0 LOG: duration: 0.309 ms 2014-07-30 09:41:53 PDT PID:4725 XID:0 LOG: statement: SET standard_conforming_strings TO on;SET datestyle TO ISO 2014-07-30 09:41:53 PDT PID:4725 XID:0 LOG: duration: 0.227 ms 2014-07-30 09:41:53 PDT PID:4724 XID:0 LOG: statement: SET standard_conforming_strings TO on;SET datestyle TO ISO 2014-07-30 09:41:53 PDT PID:4724 XID:0 LOG: duration: 0.318 ms 2014-07-30 09:41:53 PDT PID:4729 XID:0 LOG: statement: SET standard_conforming_strings TO on;SET datestyle TO ISO 2014-07-30 09:41:53 PDT PID:4729 XID:0 LOG: duration: 0.210 ms 2014-07-30 09:41:53 PDT PID:4730 XID:0 LOG: statement: SET standard_conforming_strings TO on;SET datestyle TO ISO 2014-07-30 09:41:53 PDT PID:4730 XID:0 LOG: duration: 0.269 ms 2014-07-30 09:41:53 PDT PID:4727 XID:0 LOG: statement: SET client_encoding TO utf8 2014-07-30 09:41:53 PDT PID:4727 XID:0 LOG: duration: 0.071 ms 2014-07-30 09:41:53 PDT PID:4725 XID:0 LOG: statement: SET client_encoding TO utf8 2014-07-30 09:41:53 PDT PID:4725 XID:0 LOG: duration: 0.068 ms 2014-07-30 09:41:53 PDT PID:4729 XID:0 LOG: statement: SET client_encoding TO utf8 2014-07-30 09:41:53 PDT PID:4729 XID:0 LOG: duration: 0.075 ms 2014-07-30 09:41:53 PDT PID:4724 XID:0 LOG: statement: SET client_encoding TO utf8 2014-07-30 09:41:53 PDT PID:4724 XID:0 LOG: duration: 0.110 ms 2014-07-30 09:41:53 PDT PID:4725 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:53 PDT PID:4727 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:53 PDT PID:4730 XID:0 LOG: statement: SET client_encoding TO utf8 2014-07-30 09:41:53 PDT PID:4730 XID:0 LOG: duration: 0.114 ms 2014-07-30 09:41:53 PDT PID:4724 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:53 PDT PID:4724 XID:0 LOG: duration: 3.396 ms 2014-07-30 09:41:53 PDT PID:4730 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:53 PDT PID:4728 XID:0 LOG: statement: SET standard_conforming_strings TO on;SET datestyle TO ISO 2014-07-30 09:41:53 PDT PID:4728 XID:0 LOG: duration: 0.395 ms 2014-07-30 09:41:53 PDT PID:4729 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:53 PDT PID:4728 XID:0 LOG: statement: SET client_encoding TO utf8 2014-07-30 09:41:53 PDT PID:4728 XID:0 LOG: duration: 0.123 ms 2014-07-30 09:41:53 PDT PID:4728 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:53 PDT PID:4728 XID:0 LOG: duration: 3.318 ms 2014-07-30 09:41:53 PDT PID:4727 XID:0 LOG: duration: 18.022 ms 2014-07-30 09:41:53 PDT PID:4725 XID:0 LOG: duration: 20.795 ms 2014-07-30 09:41:53 PDT PID:4730 XID:0 LOG: duration: 14.789 ms 2014-07-30 09:41:53 PDT PID:4729 XID:0 LOG: duration: 13.943 ms 2014-07-30 09:41:53 PDT PID:4731 XID:0 LOG: statement: SET standard_conforming_strings TO on;SET datestyle TO ISO 2014-07-30 09:41:53 PDT PID:4731 XID:0 LOG: duration: 0.304 ms 2014-07-30 09:41:53 PDT PID:4731 XID:0 LOG: statement: SET client_encoding TO utf8 2014-07-30 09:41:53 PDT PID:4731 XID:0 LOG: duration: 0.063 ms 2014-07-30 09:41:53 PDT PID:4731 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:53 PDT PID:4731 XID:0 LOG: duration: 2.902 ms 2014-07-30 09:41:53 PDT PID:4716 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('2rbwfyzt43caf7u5', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:53 PDT PID:4715 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:53 PDT PID:4716 XID:0 LOG: duration: 7.380 ms 2014-07-30 09:41:53 PDT PID:4715 XID:0 LOG: duration: 7.373 ms 2014-07-30 09:41:53 PDT PID:4717 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('dakk4ujk973vmnxa', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:53 PDT PID:4718 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:53 PDT PID:4717 XID:0 LOG: duration: 1.267 ms 2014-07-30 09:41:53 PDT PID:4718 XID:0 LOG: duration: 0.852 ms 2014-07-30 09:41:53 PDT PID:4719 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:53 PDT PID:4720 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:53 PDT PID:4721 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:53 PDT PID:4722 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:53 PDT PID:4726 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:53 PDT PID:4723 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:53 PDT PID:4724 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:53 PDT PID:4728 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:53 PDT PID:4727 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:53 PDT PID:4725 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:53 PDT PID:4730 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:53 PDT PID:4729 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:53 PDT PID:4731 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:53 PDT PID:4715 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('f8fxwchxw967ja5n', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:53 PDT PID:4718 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('f8sj4nf38d6jf3vq', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:53 PDT PID:4719 XID:0 LOG: duration: 40.852 ms 2014-07-30 09:41:53 PDT PID:4715 XID:0 LOG: duration: 18.684 ms 2014-07-30 09:41:53 PDT PID:4718 XID:0 LOG: duration: 18.113 ms 2014-07-30 09:41:53 PDT PID:4717 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:53 PDT PID:4717 XID:0 LOG: duration: 0.349 ms 2014-07-30 09:41:53 PDT PID:4716 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:53 PDT PID:4716 XID:0 LOG: duration: 0.382 ms 2014-07-30 09:41:53 PDT PID:4733 XID:0 LOG: statement: SET standard_conforming_strings TO on;SET datestyle TO ISO 2014-07-30 09:41:53 PDT PID:4733 XID:0 LOG: duration: 5.118 ms 2014-07-30 09:41:53 PDT PID:4734 XID:0 LOG: statement: SET standard_conforming_strings TO on;SET datestyle TO ISO 2014-07-30 09:41:53 PDT PID:4736 XID:0 LOG: statement: SET standard_conforming_strings TO on;SET datestyle TO ISO 2014-07-30 09:41:53 PDT PID:4733 XID:0 LOG: statement: SET client_encoding TO utf8 2014-07-30 09:41:53 PDT PID:4733 XID:0 LOG: duration: 0.125 ms 2014-07-30 09:41:53 PDT PID:4734 XID:0 LOG: duration: 1.169 ms 2014-07-30 09:41:53 PDT PID:4736 XID:0 LOG: duration: 1.111 ms 2014-07-30 09:41:53 PDT PID:4733 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:53 PDT PID:4733 XID:0 LOG: duration: 3.475 ms 2014-07-30 09:41:53 PDT PID:4732 XID:0 LOG: statement: SET standard_conforming_strings TO on;SET datestyle TO ISO 2014-07-30 09:41:53 PDT PID:4736 XID:0 LOG: statement: SET client_encoding TO utf8 2014-07-30 09:41:53 PDT PID:4736 XID:0 LOG: duration: 0.094 ms 2014-07-30 09:41:53 PDT PID:4732 XID:0 LOG: duration: 0.626 ms 2014-07-30 09:41:53 PDT PID:4734 XID:0 LOG: statement: SET client_encoding TO utf8 2014-07-30 09:41:53 PDT PID:4734 XID:0 LOG: duration: 0.219 ms 2014-07-30 09:41:53 PDT PID:4736 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:53 PDT PID:4732 XID:0 LOG: statement: SET client_encoding TO utf8 2014-07-30 09:41:53 PDT PID:4732 XID:0 LOG: duration: 0.122 ms 2014-07-30 09:41:53 PDT PID:4736 XID:0 LOG: duration: 4.150 ms 2014-07-30 09:41:53 PDT PID:4734 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:53 PDT PID:4734 XID:0 LOG: duration: 3.539 ms 2014-07-30 09:41:53 PDT PID:4732 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:53 PDT PID:4732 XID:0 LOG: duration: 7.804 ms 2014-07-30 09:41:53 PDT PID:4738 XID:0 LOG: statement: SET standard_conforming_strings TO on;SET datestyle TO ISO 2014-07-30 09:41:53 PDT PID:4738 XID:0 LOG: duration: 0.449 ms 2014-07-30 09:41:53 PDT PID:4737 XID:0 LOG: statement: SET standard_conforming_strings TO on;SET datestyle TO ISO 2014-07-30 09:41:53 PDT PID:4737 XID:0 LOG: duration: 0.259 ms 2014-07-30 09:41:53 PDT PID:4735 XID:0 LOG: statement: SET standard_conforming_strings TO on;SET datestyle TO ISO 2014-07-30 09:41:53 PDT PID:4735 XID:0 LOG: duration: 0.480 ms 2014-07-30 09:41:53 PDT PID:4738 XID:0 LOG: statement: SET client_encoding TO utf8 2014-07-30 09:41:53 PDT PID:4738 XID:0 LOG: duration: 0.074 ms 2014-07-30 09:41:53 PDT PID:4737 XID:0 LOG: statement: SET client_encoding TO utf8 2014-07-30 09:41:53 PDT PID:4737 XID:0 LOG: duration: 0.104 ms 2014-07-30 09:41:53 PDT PID:4739 XID:0 LOG: statement: SET standard_conforming_strings TO on;SET datestyle TO ISO 2014-07-30 09:41:53 PDT PID:4739 XID:0 LOG: duration: 0.331 ms 2014-07-30 09:41:53 PDT PID:4738 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:53 PDT PID:4735 XID:0 LOG: statement: SET client_encoding TO utf8 2014-07-30 09:41:53 PDT PID:4735 XID:0 LOG: duration: 0.135 ms 2014-07-30 09:41:53 PDT PID:4738 XID:0 LOG: duration: 3.674 ms 2014-07-30 09:41:53 PDT PID:4739 XID:0 LOG: statement: SET client_encoding TO utf8 2014-07-30 09:41:53 PDT PID:4739 XID:0 LOG: duration: 0.143 ms 2014-07-30 09:41:53 PDT PID:4737 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:53 PDT PID:4737 XID:0 LOG: duration: 3.995 ms 2014-07-30 09:41:53 PDT PID:4735 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:53 PDT PID:4735 XID:0 LOG: duration: 3.503 ms 2014-07-30 09:41:53 PDT PID:4739 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:53 PDT PID:4739 XID:0 LOG: duration: 2.830 ms 2014-07-30 09:41:53 PDT PID:4717 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:53 PDT PID:4716 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:53 PDT PID:4733 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:53 PDT PID:4719 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('m789teb7pe4erpwu', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:53 PDT PID:4736 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:53 PDT PID:4732 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:53 PDT PID:4734 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:53 PDT PID:4718 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:53 PDT PID:4718 XID:0 LOG: duration: 0.445 ms 2014-07-30 09:41:53 PDT PID:4738 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:53 PDT PID:4715 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:53 PDT PID:4715 XID:0 LOG: duration: 0.253 ms 2014-07-30 09:41:53 PDT PID:4718 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:53 PDT PID:4719 XID:0 LOG: duration: 12.996 ms 2014-07-30 09:41:53 PDT PID:4715 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:53 PDT PID:4737 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:53 PDT PID:4719 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:53 PDT PID:4719 XID:0 LOG: duration: 0.376 ms 2014-07-30 09:41:53 PDT PID:4735 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:53 PDT PID:4719 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:53 PDT PID:4739 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:54 PDT PID:4729 XID:25780 ERROR: deadlock detected 2014-07-30 09:41:54 PDT PID:4729 XID:25780 DETAIL: Process 4729 waits for ShareLock on transaction 25779; blocked by process 4727. 2014-07-30 09:41:54 PDT PID:4729 XID:25780 HINT: See server log for query details. 2014-07-30 09:41:54 PDT PID:4729 XID:25780 STATEMENT: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:54 PDT PID:4729 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:54 PDT PID:4729 XID:0 LOG: duration: 0.865 ms 2014-07-30 09:41:54 PDT PID:4729 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:55 PDT PID:4731 XID:25781 ERROR: deadlock detected 2014-07-30 09:41:55 PDT PID:4731 XID:25781 DETAIL: Process 4731 waits for ShareLock on transaction 25779; blocked by process 4727. 2014-07-30 09:41:55 PDT PID:4731 XID:25781 HINT: See server log for query details. 2014-07-30 09:41:55 PDT PID:4731 XID:25781 STATEMENT: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:55 PDT PID:4722 XID:0 LOG: duration: 2047.311 ms 2014-07-30 09:41:55 PDT PID:4727 XID:0 LOG: duration: 2042.021 ms 2014-07-30 09:41:55 PDT PID:4716 XID:0 LOG: duration: 1796.127 ms 2014-07-30 09:41:55 PDT PID:4717 XID:0 LOG: duration: 1798.057 ms 2014-07-30 09:41:55 PDT PID:4722 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('3njjbdymr6rt4yna', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:55 PDT PID:4716 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('ac5wdak8e3d9brph', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:55 PDT PID:4717 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('7sa56tqda9sycnrx', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:55 PDT PID:4731 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:55 PDT PID:4731 XID:0 LOG: duration: 0.276 ms 2014-07-30 09:41:55 PDT PID:4727 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('jqq8wc7zhtrffuru', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:55 PDT PID:4724 XID:0 LOG: duration: 2061.442 ms 2014-07-30 09:41:55 PDT PID:4726 XID:0 LOG: duration: 2063.663 ms 2014-07-30 09:41:55 PDT PID:4731 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:55 PDT PID:4722 XID:0 LOG: duration: 10.416 ms 2014-07-30 09:41:55 PDT PID:4716 XID:0 LOG: duration: 4.895 ms 2014-07-30 09:41:55 PDT PID:4717 XID:0 LOG: duration: 3.979 ms 2014-07-30 09:41:55 PDT PID:4727 XID:0 LOG: duration: 3.065 ms 2014-07-30 09:41:55 PDT PID:4720 XID:0 LOG: duration: 2071.239 ms 2014-07-30 09:41:55 PDT PID:4721 XID:0 LOG: duration: 2069.597 ms 2014-07-30 09:41:55 PDT PID:4728 XID:0 LOG: duration: 2065.082 ms 2014-07-30 09:41:55 PDT PID:4736 XID:0 LOG: duration: 1815.498 ms 2014-07-30 09:41:55 PDT PID:4728 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('xys7vzs94huex2y7', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:55 PDT PID:4733 XID:0 LOG: duration: 1821.035 ms 2014-07-30 09:41:55 PDT PID:4721 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('srqvfyvm5hjbqjgh', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:55 PDT PID:4724 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('nj9gmnsm6gvracn8', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:55 PDT PID:4736 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('a5bp927ef8wtmyzq', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:55 PDT PID:4722 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:55 PDT PID:4722 XID:0 LOG: duration: 0.402 ms 2014-07-30 09:41:55 PDT PID:4727 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:55 PDT PID:4735 XID:0 LOG: duration: 1804.859 ms 2014-07-30 09:41:55 PDT PID:4727 XID:0 LOG: duration: 0.314 ms 2014-07-30 09:41:55 PDT PID:4734 XID:0 LOG: duration: 1822.148 ms 2014-07-30 09:41:55 PDT PID:4716 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:55 PDT PID:4716 XID:0 LOG: duration: 0.209 ms 2014-07-30 09:41:55 PDT PID:4733 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('c6q4y7d8sje5nrfn', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:55 PDT PID:4717 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:55 PDT PID:4717 XID:0 LOG: duration: 0.207 ms 2014-07-30 09:41:55 PDT PID:4726 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('zdhr775vbuut7jaw', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:55 PDT PID:4722 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:55 PDT PID:4727 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:55 PDT PID:4716 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:55 PDT PID:4724 XID:0 LOG: duration: 16.024 ms 2014-07-30 09:41:55 PDT PID:4728 XID:0 LOG: duration: 20.277 ms 2014-07-30 09:41:55 PDT PID:4726 XID:0 LOG: duration: 6.604 ms 2014-07-30 09:41:55 PDT PID:4733 XID:0 LOG: duration: 8.228 ms 2014-07-30 09:41:55 PDT PID:4736 XID:0 LOG: duration: 17.109 ms 2014-07-30 09:41:55 PDT PID:4721 XID:0 LOG: duration: 18.528 ms 2014-07-30 09:41:55 PDT PID:4720 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('t9xhe6f3pea76fn3', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:55 PDT PID:4717 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:55 PDT PID:4735 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('hsw4d44texh95tqh', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:55 PDT PID:4735 XID:0 LOG: duration: 2.891 ms 2014-07-30 09:41:55 PDT PID:4734 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('ep2n66dqv7da759v', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:55 PDT PID:4734 XID:0 LOG: duration: 2.171 ms 2014-07-30 09:41:55 PDT PID:4720 XID:0 LOG: duration: 8.575 ms 2014-07-30 09:41:55 PDT PID:4736 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:55 PDT PID:4736 XID:0 LOG: duration: 0.348 ms 2014-07-30 09:41:55 PDT PID:4726 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:55 PDT PID:4726 XID:0 LOG: duration: 0.232 ms 2014-07-30 09:41:55 PDT PID:4733 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:55 PDT PID:4733 XID:0 LOG: duration: 0.288 ms 2014-07-30 09:41:55 PDT PID:4728 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:55 PDT PID:4728 XID:0 LOG: duration: 0.274 ms 2014-07-30 09:41:55 PDT PID:4721 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:55 PDT PID:4721 XID:0 LOG: duration: 0.291 ms 2014-07-30 09:41:55 PDT PID:4724 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:55 PDT PID:4724 XID:0 LOG: duration: 0.342 ms 2014-07-30 09:41:55 PDT PID:4720 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:55 PDT PID:4720 XID:0 LOG: duration: 0.347 ms 2014-07-30 09:41:55 PDT PID:4735 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:55 PDT PID:4735 XID:0 LOG: duration: 0.198 ms 2014-07-30 09:41:55 PDT PID:4734 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:55 PDT PID:4734 XID:0 LOG: duration: 0.177 ms 2014-07-30 09:41:55 PDT PID:4726 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:55 PDT PID:4736 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:55 PDT PID:4728 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:55 PDT PID:4733 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:55 PDT PID:4721 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:55 PDT PID:4724 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:55 PDT PID:4735 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:55 PDT PID:4720 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:55 PDT PID:4734 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:56 PDT PID:4731 XID:25812 ERROR: deadlock detected 2014-07-30 09:41:56 PDT PID:4731 XID:25812 DETAIL: Process 4731 waits for ExclusiveLock on tuple (1,98) of relation 16553 of database 16385; blocked by process 4738. 2014-07-30 09:41:56 PDT PID:4731 XID:25812 HINT: See server log for query details. 2014-07-30 09:41:56 PDT PID:4731 XID:25812 STATEMENT: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:56 PDT PID:4719 XID:25802 ERROR: deadlock detected 2014-07-30 09:41:56 PDT PID:4719 XID:25802 DETAIL: Process 4719 waits for ExclusiveLock on tuple (1,98) of relation 16553 of database 16385; blocked by process 4738. 2014-07-30 09:41:56 PDT PID:4719 XID:25802 HINT: See server log for query details. 2014-07-30 09:41:56 PDT PID:4719 XID:25802 STATEMENT: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:56 PDT PID:4718 XID:25797 ERROR: deadlock detected 2014-07-30 09:41:56 PDT PID:4718 XID:25797 DETAIL: Process 4718 waits for ExclusiveLock on tuple (1,98) of relation 16553 of database 16385; blocked by process 4738. 2014-07-30 09:41:56 PDT PID:4718 XID:25797 HINT: See server log for query details. 2014-07-30 09:41:56 PDT PID:4718 XID:25797 STATEMENT: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:56 PDT PID:4725 XID:25791 ERROR: deadlock detected 2014-07-30 09:41:56 PDT PID:4725 XID:25791 DETAIL: Process 4725 waits for ExclusiveLock on tuple (1,98) of relation 16553 of database 16385; blocked by process 4738. 2014-07-30 09:41:56 PDT PID:4725 XID:25791 HINT: See server log for query details. 2014-07-30 09:41:56 PDT PID:4725 XID:25791 STATEMENT: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:56 PDT PID:4730 XID:25785 ERROR: deadlock detected 2014-07-30 09:41:56 PDT PID:4730 XID:25785 DETAIL: Process 4730 waits for ExclusiveLock on tuple (1,98) of relation 16553 of database 16385; blocked by process 4738. 2014-07-30 09:41:56 PDT PID:4730 XID:25785 HINT: See server log for query details. 2014-07-30 09:41:56 PDT PID:4730 XID:25785 STATEMENT: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:56 PDT PID:4737 XID:25800 ERROR: deadlock detected 2014-07-30 09:41:56 PDT PID:4737 XID:25800 DETAIL: Process 4737 waits for ExclusiveLock on tuple (1,98) of relation 16553 of database 16385; blocked by process 4738. 2014-07-30 09:41:56 PDT PID:4737 XID:25800 HINT: See server log for query details. 2014-07-30 09:41:56 PDT PID:4737 XID:25800 STATEMENT: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:56 PDT PID:4715 XID:25799 ERROR: deadlock detected 2014-07-30 09:41:56 PDT PID:4715 XID:25799 DETAIL: Process 4715 waits for ExclusiveLock on tuple (1,98) of relation 16553 of database 16385; blocked by process 4738. 2014-07-30 09:41:56 PDT PID:4715 XID:25799 HINT: See server log for query details. 2014-07-30 09:41:56 PDT PID:4715 XID:25799 STATEMENT: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:56 PDT PID:4732 XID:25798 ERROR: deadlock detected 2014-07-30 09:41:56 PDT PID:4732 XID:25798 DETAIL: Process 4732 waits for ExclusiveLock on tuple (1,98) of relation 16553 of database 16385; blocked by process 4738. 2014-07-30 09:41:56 PDT PID:4732 XID:25798 HINT: See server log for query details. 2014-07-30 09:41:56 PDT PID:4732 XID:25798 STATEMENT: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:56 PDT PID:4723 XID:25786 ERROR: deadlock detected 2014-07-30 09:41:56 PDT PID:4723 XID:25786 DETAIL: Process 4723 waits for ExclusiveLock on tuple (1,98) of relation 16553 of database 16385; blocked by process 4738. 2014-07-30 09:41:56 PDT PID:4723 XID:25786 HINT: See server log for query details. 2014-07-30 09:41:56 PDT PID:4723 XID:25786 STATEMENT: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:56 PDT PID:4739 XID:25806 ERROR: deadlock detected 2014-07-30 09:41:56 PDT PID:4739 XID:25806 DETAIL: Process 4739 waits for ExclusiveLock on tuple (1,98) of relation 16553 of database 16385; blocked by process 4738. 2014-07-30 09:41:56 PDT PID:4739 XID:25806 HINT: See server log for query details. 2014-07-30 09:41:56 PDT PID:4739 XID:25806 STATEMENT: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:56 PDT PID:4738 XID:25805 ERROR: deadlock detected 2014-07-30 09:41:56 PDT PID:4738 XID:25805 DETAIL: Process 4738 waits for ShareLock on transaction 25807; blocked by process 4729. 2014-07-30 09:41:56 PDT PID:4738 XID:25805 HINT: See server log for query details. 2014-07-30 09:41:56 PDT PID:4738 XID:25805 STATEMENT: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:56 PDT PID:4729 XID:0 LOG: duration: 2041.316 ms 2014-07-30 09:41:56 PDT PID:4716 XID:0 LOG: duration: 1000.119 ms 2014-07-30 09:41:56 PDT PID:4717 XID:0 LOG: duration: 997.180 ms 2014-07-30 09:41:56 PDT PID:4727 XID:0 LOG: duration: 1003.124 ms 2014-07-30 09:41:56 PDT PID:4722 XID:0 LOG: duration: 1003.866 ms 2014-07-30 09:41:56 PDT PID:4716 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('cb3tb8q3q8w7jgb9', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:56 PDT PID:4733 XID:0 LOG: duration: 968.410 ms 2014-07-30 09:41:56 PDT PID:4726 XID:0 LOG: duration: 971.450 ms 2014-07-30 09:41:56 PDT PID:4716 XID:0 LOG: duration: 1.847 ms 2014-07-30 09:41:56 PDT PID:4736 XID:0 LOG: duration: 971.586 ms 2014-07-30 09:41:56 PDT PID:4724 XID:0 LOG: duration: 956.523 ms 2014-07-30 09:41:56 PDT PID:4728 XID:0 LOG: duration: 971.513 ms 2014-07-30 09:41:56 PDT PID:4721 XID:0 LOG: duration: 959.007 ms 2014-07-30 09:41:56 PDT PID:4734 XID:0 LOG: duration: 955.818 ms 2014-07-30 09:41:56 PDT PID:4735 XID:0 LOG: duration: 958.631 ms 2014-07-30 09:41:56 PDT PID:4728 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('2d4k7qkj7pxeaxyd', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:56 PDT PID:4724 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('7gt9tzmenv7hs8x9', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:56 PDT PID:4726 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('8xrhdtfypy5pdaxp', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:56 PDT PID:4727 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('fn6ybvr58nghqfvm', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:56 PDT PID:4722 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('65wj9wtqat933hn5', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:56 PDT PID:4733 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('r52xxsdjdbj6vk59', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:56 PDT PID:4729 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('9d5pe3rqrbgh96bs', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:56 PDT PID:4736 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('zucqgdgf8vrxkdub', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:56 PDT PID:4721 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('apgkehysf7eu4dr2', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:56 PDT PID:4728 XID:0 LOG: duration: 5.846 ms 2014-07-30 09:41:56 PDT PID:4727 XID:0 LOG: duration: 3.622 ms 2014-07-30 09:41:56 PDT PID:4722 XID:0 LOG: duration: 3.294 ms 2014-07-30 09:41:56 PDT PID:4733 XID:0 LOG: duration: 2.938 ms 2014-07-30 09:41:56 PDT PID:4726 XID:0 LOG: duration: 4.417 ms 2014-07-30 09:41:56 PDT PID:4736 XID:0 LOG: duration: 1.680 ms 2014-07-30 09:41:56 PDT PID:4729 XID:0 LOG: duration: 2.775 ms 2014-07-30 09:41:56 PDT PID:4724 XID:0 LOG: duration: 5.320 ms 2014-07-30 09:41:56 PDT PID:4734 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('3rabn98sk63nmmkw', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:56 PDT PID:4721 XID:0 LOG: duration: 2.047 ms 2014-07-30 09:41:56 PDT PID:4734 XID:0 LOG: duration: 0.639 ms 2014-07-30 09:41:56 PDT PID:4735 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('nfm3p27uva72vunn', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:56 PDT PID:4735 XID:0 LOG: duration: 0.505 ms 2014-07-30 09:41:56 PDT PID:4720 XID:0 LOG: duration: 968.198 ms 2014-07-30 09:41:56 PDT PID:4720 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('psejqv8mv5jnvkgy', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:56 PDT PID:4720 XID:0 LOG: duration: 1.174 ms 2014-07-30 09:41:56 PDT PID:4717 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('zhq43nvs9wdpb4nh', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:56 PDT PID:4717 XID:0 LOG: duration: 0.946 ms 2014-07-30 09:41:56 PDT PID:4718 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:56 PDT PID:4718 XID:0 LOG: duration: 0.414 ms 2014-07-30 09:41:56 PDT PID:4718 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:56 PDT PID:4718 XID:0 LOG: duration: 0.763 ms 2014-07-30 09:41:56 PDT PID:4730 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:56 PDT PID:4730 XID:0 LOG: duration: 0.254 ms 2014-07-30 09:41:56 PDT PID:4719 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:56 PDT PID:4719 XID:0 LOG: duration: 0.164 ms 2014-07-30 09:41:56 PDT PID:4718 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('6nf4akd5cng3dcsm', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:56 PDT PID:4719 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:56 PDT PID:4719 XID:0 LOG: duration: 1.102 ms 2014-07-30 09:41:56 PDT PID:4715 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:56 PDT PID:4715 XID:0 LOG: duration: 0.391 ms 2014-07-30 09:41:56 PDT PID:4718 XID:0 LOG: duration: 1.852 ms 2014-07-30 09:41:56 PDT PID:4719 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('5vwxvj7yzqkv2438', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:56 PDT PID:4730 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:56 PDT PID:4715 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:56 PDT PID:4728 XID:0 LOG: statement: SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME ZONE 'UTC', "user_1"."id" as _id FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1" WHERE "user_1"."id" = 129 2014-07-30 09:41:56 PDT PID:4728 XID:0 LOG: duration: 0.223 ms 2014-07-30 09:41:56 PDT PID:4719 XID:0 LOG: duration: 4.042 ms 2014-07-30 09:41:56 PDT PID:4728 XID:0 LOG: statement: UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag SET last_issued=DEFAULT FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc WHERE oc.id = ag.client_id AND ag.entity_name = 'user' AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f' RETURNING ag.id 2014-07-30 09:41:56 PDT PID:4730 XID:0 LOG: duration: 9.535 ms 2014-07-30 09:41:56 PDT PID:4715 XID:0 LOG: duration: 8.274 ms 2014-07-30 09:41:56 PDT PID:4728 XID:0 LOG: duration: 5.898 ms 2014-07-30 09:41:56 PDT PID:4730 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('exemfjaxzsebk7uc', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:56 PDT PID:4715 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('3pqfgs5zmm9cnheh', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:56 PDT PID:4728 XID:0 LOG: statement: INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"(token, access_id, refresh_token_id, issued, expiry) VALUES('5c8r8epmtq3abcy2', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval) 2014-07-30 09:41:56 PDT PID:4715 XID:0 LOG: duration: 1.194 ms 2014-07-30 09:41:56 PDT PID:4728 XID:0 LOG: duration: 1.439 ms 2014-07-30 09:41:56 PDT PID:4730 XID:0 LOG: duration: 3.975 ms
postgresql.conf (text/plain, 1.3K) download data_directory = '/var/lib/postgresql/9.3/main' # use data in another directory hba_file = '/etc/postgresql/9.3/main/pg_hba.conf' # host-based authentication file ident_file = '/etc/postgresql/9.3/main/pg_ident.conf' # ident configuration file external_pid_file = '/var/run/postgresql/9.3-main.pid' # write an extra PID file listen_addresses = '*' # what IP address(es) to listen on; port = 5432 # (change requires restart) max_connections = 100 # (change requires restart) unix_socket_directories = '/var/run/postgresql' # comma-separated list of directories ssl = true # (change requires restart) ssl_cert_file = '/etc/ssl/certs/ssl-cert-snakeoil.pem' # (change requires restart) ssl_key_file = '/etc/ssl/private/ssl-cert-snakeoil.key' # (change requires restart) shared_buffers = 128MB # min 128kB log_min_duration_statement = 0 # -1 is disabled, 0 logs all statements log_line_prefix = '%t PID:%p XID:%x ' # special values: log_statement = 'all' # none, ddl, mod, all log_timezone = 'localtime' datestyle = 'iso, mdy' timezone = 'localtime' lc_messages = 'en_US.UTF-8' # locale for system error message lc_monetary = 'en_US.UTF-8' # locale for monetary formatting lc_numeric = 'en_US.UTF-8' # locale for number formatting lc_time = 'en_US.UTF-8' # locale for time formatting default_text_search_config = 'pg_catalog.english'
table_defs (text/plain, 4.1K) download Table "z8z6px927zu6qzzbnb5ntgghxg.access_grants" Column | Type | Modifiers -------------------+-----------------------------+--------------------------------------------------------------------------------------- id | bigint | not null default nextval('z8z6px927zu6qzzbnb5ntgghxg.access_grants_id_seq'::regclass) client_id | bigint | not null entity_name | character varying(40) | not null entity_id | bigint | not null originally_issued | timestamp without time zone | not null default timezone('UTC'::text, now()) last_issued | timestamp without time zone | not null default timezone('UTC'::text, now()) Indexes: "access_grants_pkey" PRIMARY KEY, btree (id) "access_grants_client_id_entity_name_entity_id_key" UNIQUE CONSTRAINT, btree (client_id, entity_name, entity_id) "access_grants_client_id_idx" btree (client_id) Foreign-key constraints: "access_grants_client_id_fkey" FOREIGN KEY (client_id) REFERENCES z8z6px927zu6qzzbnb5ntgghxg.oauth_clients(id) ON DELETE CASCADE Referenced by: TABLE "z8z6px927zu6qzzbnb5ntgghxg.access_tokens" CONSTRAINT "access_tokens_access_id_fkey" FOREIGN KEY (access_id) REFERENCES z8z6px927zu6qzzbnb5ntgghxg.access_grants(id) ON DELETE CASCADE TABLE "z8z6px927zu6qzzbnb5ntgghxg.authorization_codes" CONSTRAINT "authorization_codes_access_id_fkey" FOREIGN KEY (access_id) REFERENCES z8z6px927zu6qzzbnb5ntgghxg.access_grants(id) ON DELETE CASCADE TABLE "z8z6px927zu6qzzbnb5ntgghxg.refresh_tokens" CONSTRAINT "refresh_tokens_access_id_fkey" FOREIGN KEY (access_id) REFERENCES z8z6px927zu6qzzbnb5ntgghxg.access_grants(id) ON DELETE CASCADE Table "z8z6px927zu6qzzbnb5ntgghxg.oauth_clients" Column | Type | Modifiers ---------------+---------------+--------------------------------------------------------------------------------------- id | bigint | not null default nextval('z8z6px927zu6qzzbnb5ntgghxg.oauth_clients_id_seq'::regclass) client_id | character(32) | not null client_secret | character(32) | not null description | text | not null Indexes: "oauth_clients_pkey" PRIMARY KEY, btree (id) "oauth_clients_client_id_key" UNIQUE CONSTRAINT, btree (client_id) "oauth_clients_client_secret_key" UNIQUE CONSTRAINT, btree (client_secret) Referenced by: TABLE "z8z6px927zu6qzzbnb5ntgghxg.access_grants" CONSTRAINT "access_grants_client_id_fkey" FOREIGN KEY (client_id) REFERENCES z8z6px927zu6qzzbnb5ntgghxg.oauth_clients(id) ON DELETE CASCADE TABLE "z8z6px927zu6qzzbnb5ntgghxg.access_schemas" CONSTRAINT "access_schemas_client_id_fkey" FOREIGN KEY (client_id) REFERENCES z8z6px927zu6qzzbnb5ntgghxg.oauth_clients(id) ON DELETE CASCADE TABLE "z8z6px927zu6qzzbnb5ntgghxg.client_features" CONSTRAINT "client_features_client_id_fkey" FOREIGN KEY (client_id) REFERENCES z8z6px927zu6qzzbnb5ntgghxg.oauth_clients(id) ON DELETE CASCADE TABLE "z8z6px927zu6qzzbnb5ntgghxg.client_settings" CONSTRAINT "client_settings_client_id_fkey" FOREIGN KEY (client_id) REFERENCES z8z6px927zu6qzzbnb5ntgghxg.oauth_clients(id) ON DELETE CASCADE TABLE "z8z6px927zu6qzzbnb5ntgghxg.client_whitelists" CONSTRAINT "client_whitelists_client_id_fkey" FOREIGN KEY (client_id) REFERENCES z8z6px927zu6qzzbnb5ntgghxg.oauth_clients(id) ON DELETE CASCADE TABLE "z8z6px927zu6qzzbnb5ntgghxg.creation_tokens" CONSTRAINT "creation_tokens_client_id_fkey" FOREIGN KEY (client_id) REFERENCES z8z6px927zu6qzzbnb5ntgghxg.oauth_clients(id) ON DELETE CASCADE TABLE "z8z6px927zu6qzzbnb5ntgghxg.expired_secrets" CONSTRAINT "expired_secrets_client_id_fkey" FOREIGN KEY (client_id) REFERENCES z8z6px927zu6qzzbnb5ntgghxg.oauth_clients(id) ON DELETE CASCADE TABLE "z8z6px927zu6qzzbnb5ntgghxg.verification_codes" CONSTRAINT "verification_codes_client_id_fkey" FOREIGN KEY (client_id) REFERENCES z8z6px927zu6qzzbnb5ntgghxg.oauth_clients(id) ON DELETE CASCADE
^ permalink raw reply [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-08-01 00:59  Alvaro Herrera <alvherre@2ndquadrant.com>
  parent: Andrew Sackville-West <awest@janrain.com>
  1 sibling, 1 reply; 34+ messages in thread

From: Alvaro Herrera @ 2014-08-01 00:59 UTC (permalink / raw)
  To: Andrew Sackville-West <awest@janrain.com>; +Cc: pgsql-bugs

Andrew Sackville-West wrote:
> Hi,
> 
> I've discussed this problem on irc a couple of times and think I've
> found a regression that plagues our application, introduced in some
> version newer than 9.1.9, and still present in 9.3.5.

I don't think you have provided everything: for instance I see that your
log has INSERTs into table access_tokens, which has a foreign key
relationship to/from some other table you showed.

I'm too lazy to unscramble the whole thing into a real schema right now.
pg_dump output would be more helpful, as would some trivial sample data
enough to reproduce the problem.

It'd probably be easier to reproduce if you wrap the statements in
transactions and have them sleep before COMMIT.  (If you run two of
these updates in parallel, the first one blocks the second until the
first one commits, because they update the same row.  What happens if
the blocking session runs the aforementioned INSERT while the other is
blocked?  Perhaps three sessions are needed to show a problem without
explicit transactions.)

-- 
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-08-01 15:40  Marti Raudsepp <marti@juffo.org>
  parent: Andrew Sackville-West <awest@janrain.com>
  1 sibling, 1 reply; 34+ messages in thread

From: Marti Raudsepp @ 2014-08-01 15:40 UTC (permalink / raw)
  To: Andrew Sackville-West <awest@janrain.com>; +Cc: pgsql-bugs

On Fri, Aug 1, 2014 at 2:30 AM, Andrew Sackville-West <awest@janrain.com> wrote:
> I have not been able to reproduce the deadlock by making concurrent
> UPDATEs via what amounts to a bash fork-bomb w/ psql, but I suspect my
> methodology might be too crude there.

Another way is using pgbench. Write a script file with the SQL query
in it (must be on a single line). Then launch it as:
    pgbench -f scriptfile.sql -n -c 10 dbname

Regards,
Marti


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-08-01 15:46  Andrew Sackville-West <awest@janrain.com>
  parent: Marti Raudsepp <marti@juffo.org>
  0 siblings, 0 replies; 34+ messages in thread

From: Andrew Sackville-West @ 2014-08-01 15:46 UTC (permalink / raw)
  To: Marti Raudsepp <marti@juffo.org>; +Cc: pgsql-bugs

On Fri, Aug 01, 2014 at 06:40:51PM +0300, Marti Raudsepp wrote:
> On Fri, Aug 1, 2014 at 2:30 AM, Andrew Sackville-West <awest@janrain.com> wrote:
> > I have not been able to reproduce the deadlock by making concurrent
> > UPDATEs via what amounts to a bash fork-bomb w/ psql, but I suspect my
> > methodology might be too crude there.
>
> Another way is using pgbench. Write a script file with the SQL query
> in it (must be on a single line). Then launch it as:
>     pgbench -f scriptfile.sql -n -c 10 dbname
>

a perfect, thanks I'll see if I can reproduce this way and follow up.

A


--


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-08-04 16:12  Andrew Sackville-West <awest@janrain.com>
  parent: Alvaro Herrera <alvherre@2ndquadrant.com>
  0 siblings, 1 reply; 34+ messages in thread

From: Andrew Sackville-West @ 2014-08-04 16:12 UTC (permalink / raw)
  To: pgsql-bugs

On Thu, Jul 31, 2014 at 08:59:50PM -0400, Alvaro Herrera wrote:
> Andrew Sackville-West wrote:
> > Hi,
> >
> > I've discussed this problem on irc a couple of times and think I've
> > found a regression that plagues our application, introduced in some
> > version newer than 9.1.9, and still present in 9.3.5.
>
> I don't think you have provided everything: for instance I see that your
> log has INSERTs into table access_tokens, which has a foreign key
> relationship to/from some other table you showed.

Ah you're correct, I'll attach the description of that table. But,
really, that is all that's going on in the database.

>
> I'm too lazy to unscramble the whole thing into a real schema right now.
> pg_dump output would be more helpful, as would some trivial sample data
> enough to reproduce the problem.

It's really minimal data. I'll attach a dump of the access_grants and
oauth_clients table. The access_tokens table is not empty, but I'm not
sure how relevant the data is. What is shown in the log is
typical. There is another table in play here, refresh_tokens, but
we're not actually using them in this case -- the table is empty, and
the reference to it in access_tokens in null.


> It'd probably be easier to reproduce if you wrap the statements in
> transactions and have them sleep before COMMIT.

The issue here is, with no code changes, this works fine under very
heavy load in production against 9.0.x, 9.1.9, etc. But under
9.3.{3,4,5} it fails. That code has no transaction. I think adding a
transaction is a distraction from what appears to me to be a
regression.

Interestingly, if I change the code to include a transaction around
the UPDATE, the problem goes away (or so it seems so far in my testing).

> (If you run two of
> these updates in parallel, the first one blocks the second until the
> first one commits, because they update the same row.  What happens if
> the blocking session runs the aforementioned INSERT while the other is
> blocked?  Perhaps three sessions are needed to show a problem without
> explicit transactions.)

I've run pg_bench from 3 machines all pointing at the same database
running this same set of statements and it fails to induce the
deadlock.

It occurs to me that I haven't completely described the sequence of
actions, so here is a snippet of the actual SQL that a given action
induces, when it works as expected:

SET standard_conforming_strings TO on;

SET datestyle TO ISO;

SET client_encoding TO utf8;

SELECT "user_1"."id", "user_1"."uuid", "user_1"."lastUpdated" AT TIME
ZONE 'UTC', "user_1"."id" as _id
FROM "z8z6px927zu6qzzbnb5ntgghxg"."user_1" AS "user_1"  WHERE "user_1"."id" = 129;

UPDATE "z8z6px927zu6qzzbnb5ntgghxg"."access_grants" ag
SET last_issued=DEFAULT
FROM "z8z6px927zu6qzzbnb5ntgghxg"."oauth_clients" oc
WHERE oc.id = ag.client_id AND ag.entity_name = 'user'
  AND ag.entity_id = 129 AND oc.client_id = '3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f'
RETURNING ag.id;

INSERT INTO "z8z6px927zu6qzzbnb5ntgghxg"."access_tokens"
  (token, access_id, refresh_token_id, issued, expiry)
VALUES
  ('xys7vzs94huex2y7', 2, null, timezone('UTC'::text, now()), timezone('UTC'::text, now()) + '1:00:00':: interval);

This represents one complete action. There are several of these
running concurrently, interleaved together. There is no transaction
involved here. As far as I can tell, the application is using
bog-standard libpq (via FFI wrapper in Haskell) with no non-default
configuration applied to the connection.

I realize there's not a lot to go on here, and I don't expect help
debugging my application. I've got a patch that seems to resolve the
problem for us. But I'm suspicious of this change in behavior and hope
that pointing it out can help in some way.

regards,

A



>
> --
> Álvaro Herrera                http://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Training & Services

--

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

access_tokens_table (text/plain, 1.3K) download Table "z8z6px927zu6qzzbnb5ntgghxg.access_tokens" Column | Type | Modifiers ------------------+-----------------------------+------------------------------------------------------------------------ id | bigint | not null default nextval('access_tokens_id_seq'::regclass) token | character(16) | not null access_id | bigint | not null refresh_token_id | bigint | issued | timestamp without time zone | not null default timezone('UTC'::text, now()) expiry | timestamp without time zone | not null default (timezone('UTC'::text, now()) + '01:00:00'::interval) refresh_secret | character varying(64) | Indexes: "access_tokens_pkey" PRIMARY KEY, btree (id) "access_tokens_token_key" UNIQUE CONSTRAINT, btree (token) "access_tokens_access_id_idx" btree (access_id) "access_tokens_refresh_to_idx" btree (refresh_token_id) Foreign-key constraints: "access_tokens_access_id_fkey" FOREIGN KEY (access_id) REFERENCES access_grants(id) ON DELETE CASCADE "access_tokens_refresh_token_id_fkey" FOREIGN KEY (refresh_token_id) REFERENCES refresh_tokens(id) ON DELETE CASCADE
sample_data (text/plain, 702B) download id | client_id | entity_name | entity_id | originally_issued | last_issued ----+-----------+-------------+-----------+----------------------------+---------------------------- 2 | 1 | user | 129 | 2014-07-10 19:15:37.116183 | 2014-07-31 02:11:25.286745 1 | 1 | user | 1 | 2014-03-19 01:43:12.856049 | 2014-07-10 21:19:27.43646 (2 rows) id | client_id | client_secret | description ----+----------------------------------+----------------------------------+------------------- 1 | 3hp45h9d4f9wwtx7cvpus6rdb4s5kb9f | wwyxv338q8qhd72yhvtk45znw2kzhw32 | application owner (1 row)
^ permalink raw reply [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-08-04 16:30  Alvaro Herrera <alvherre@2ndquadrant.com>
  parent: Andrew Sackville-West <awest@janrain.com>
  0 siblings, 1 reply; 34+ messages in thread

From: Alvaro Herrera @ 2014-08-04 16:30 UTC (permalink / raw)
  To: pgsql-bugs

Andrew Sackville-West wrote:

> > I don't think you have provided everything: for instance I see that your
> > log has INSERTs into table access_tokens, which has a foreign key
> > relationship to/from some other table you showed.
> 
> Ah you're correct, I'll attach the description of that table. But,
> really, that is all that's going on in the database.

See, access_tokens has a foreign key to access_grants.  So when the
insert to access_tokens happens, the process also acquires a lock on a
tuple on access_grants, which should not conflict with the UPDATE; but
apparently it is blocking in some cases, for unknown reasons.  But note
that one of the original tables had a large number of foreign keys to
other tables; are those necessary to reproduce the problem?  I mean, if
you just copy those three tables to an otherwise empty database and then
run the hanging application, do you see a problem?  If not, does adding
all those other tables cause the problem to show up?

Note that the set of columns covered by unique indexes is very
important.  Your \d does not have an unique index on the updated column
AFAICS; but if it did have one, things would be completely different
(because then the insert would definitely conflict with the update).

It would help a lot of you posted the table definitions as pg_dump -t
output rather than \d, because it's much easier for me to reproduce the
setup, rather than cutting and pasting the \d output into CREATE TABLE
commands.

-- 
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-12-08 23:55  Andrew Sackville-West <awest@janrain.com>
  parent: Alvaro Herrera <alvherre@2ndquadrant.com>
  0 siblings, 2 replies; 34+ messages in thread

From: Andrew Sackville-West @ 2014-12-08 23:55 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: pgsql-bugs; Paulo Tanimoto <paulo@janrain.com>

Some months later (stupid business priorities...) we have something to
report on this. We have been able to produce a minimal schema to
demonstrate the problem, and successfully induced the deadlock using
pgbench (thanks to Paulo Tanimoto, cc-ed here).

Please see:

https://gist.github.com/andrewsw-janrain/40d1687db013b1e7c3b3

for detailed instructions on how to trigger the deadlock.

I would be thrilled to learn that we've done something wrong here,
otherwise I think this represents a regression introduced in 9.3.

A

On Mon, Aug 04, 2014 at 12:30:27PM -0400, Alvaro Herrera wrote:
> Andrew Sackville-West wrote:
>
> > > I don't think you have provided everything: for instance I see that your
> > > log has INSERTs into table access_tokens, which has a foreign key
> > > relationship to/from some other table you showed.
> >
> > Ah you're correct, I'll attach the description of that table. But,
> > really, that is all that's going on in the database.
>
> See, access_tokens has a foreign key to access_grants.  So when the
> insert to access_tokens happens, the process also acquires a lock on a
> tuple on access_grants, which should not conflict with the UPDATE; but
> apparently it is blocking in some cases, for unknown reasons.  But note
> that one of the original tables had a large number of foreign keys to
> other tables; are those necessary to reproduce the problem?  I mean, if
> you just copy those three tables to an otherwise empty database and then
> run the hanging application, do you see a problem?  If not, does adding
> all those other tables cause the problem to show up?
>
> Note that the set of columns covered by unique indexes is very
> important.  Your \d does not have an unique index on the updated column
> AFAICS; but if it did have one, things would be completely different
> (because then the insert would definitely conflict with the update).
>
> It would help a lot of you posted the table definitions as pg_dump -t
> output rather than \d, because it's much easier for me to reproduce the
> setup, rather than cutting and pasting the \d output into CREATE TABLE
> commands.
>
> --
> Álvaro Herrera                http://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Training & Services
>
>
> --
> Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs

--


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-12-09 05:58  Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
  parent: Andrew Sackville-West <awest@janrain.com>
  1 sibling, 2 replies; 34+ messages in thread

From: Mark Kirkwood @ 2014-12-09 05:58 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; pgsql-bugs; Paulo Tanimoto <paulo@janrain.com>

On 09/12/14 12:55, Andrew Sackville-West wrote:
> Some months later (stupid business priorities...) we have something to
> report on this. We have been able to produce a minimal schema to
> demonstrate the problem, and successfully induced the deadlock using
> pgbench (thanks to Paulo Tanimoto, cc-ed here).
>
> Please see:
>
> https://gist.github.com/andrewsw-janrain/40d1687db013b1e7c3b3
>
> for detailed instructions on how to trigger the deadlock.
>
> I would be thrilled to learn that we've done something wrong here,
> otherwise I think this represents a regression introduced in 9.3.
>
>


That is interesting - FWIW I can reproduce:

- 9.2.9 no deadlock
- 9.4rc1 many deadlocks

so something has changed after 9.2 for sure!

Just mucking about I changed certain things in your schema setup 
(removed ON DELETE CASCADE, use CURRENT_TIMESTAMP instead of 
now()...lessen the use of DEFAULT)...however still seeing deadlocks in 
9.4, so at least it is easy to reproduce!

Regards

Mark



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-12-09 12:36  hubert depesz lubaczewski <depesz@gmail.com>
  parent: Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
  1 sibling, 1 reply; 34+ messages in thread

From: hubert depesz lubaczewski @ 2014-12-09 12:36 UTC (permalink / raw)
  To: Mark Kirkwood <mark.kirkwood@catalyst.net.nz>; +Cc: Alvaro Herrera <alvherre@2ndquadrant.com>; pgsql-bugs; Paulo Tanimoto <paulo@janrain.com>

For whatever it's worth, I was able to bisect the problem to this commit:

commit
0ac5ad5134f2769ccbaefec73844f8504c4d6182

Author: Alvaro Herrera <alvherre@alvh.no-ip.org>

Date:   Wed Jan 23 12:04:59 2013 -0300

    Improve concurrency of foreign key locking
...


depesz


On Tue, Dec 9, 2014 at 6:58 AM, Mark Kirkwood <mark.kirkwood@catalyst.net.nz
> wrote:

> On 09/12/14 12:55, Andrew Sackville-West wrote:
>
>> Some months later (stupid business priorities...) we have something to
>> report on this. We have been able to produce a minimal schema to
>> demonstrate the problem, and successfully induced the deadlock using
>> pgbench (thanks to Paulo Tanimoto, cc-ed here).
>>
>> Please see:
>>
>> https://gist.github.com/andrewsw-janrain/40d1687db013b1e7c3b3
>>
>> for detailed instructions on how to trigger the deadlock.
>>
>> I would be thrilled to learn that we've done something wrong here,
>> otherwise I think this represents a regression introduced in 9.3.
>>
>>
>>
>
> That is interesting - FWIW I can reproduce:
>
> - 9.2.9 no deadlock
> - 9.4rc1 many deadlocks
>
> so something has changed after 9.2 for sure!
>
> Just mucking about I changed certain things in your schema setup (removed
> ON DELETE CASCADE, use CURRENT_TIMESTAMP instead of now()...lessen the use
> of DEFAULT)...however still seeing deadlocks in 9.4, so at least it is easy
> to reproduce!
>
> Regards
>
> Mark
>
>
>
>
> --
> Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs
>

^ permalink  raw  reply  [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-12-09 14:14  Alvaro Herrera <alvherre@2ndquadrant.com>
  parent: hubert depesz lubaczewski <depesz@gmail.com>
  0 siblings, 1 reply; 34+ messages in thread

From: Alvaro Herrera @ 2014-12-09 14:14 UTC (permalink / raw)
  To: hubert depesz lubaczewski <depesz@gmail.com>; +Cc: Mark Kirkwood <mark.kirkwood@catalyst.net.nz>; pgsql-bugs; Paulo Tanimoto <paulo@janrain.com>

hubert depesz lubaczewski wrote:
> For whatever it's worth, I was able to bisect the problem to this commit:
> 
> commit
> 0ac5ad5134f2769ccbaefec73844f8504c4d6182
> 
> Author: Alvaro Herrera <alvherre@alvh.no-ip.org>
> 
> Date:   Wed Jan 23 12:04:59 2013 -0300
> 
>     Improve concurrency of foreign key locking

I'm not surprised in the least, TBH.

-- 
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-12-09 17:28  Andrew Sackville-West <awest@janrain.com>
  parent: Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
  1 sibling, 1 reply; 34+ messages in thread

From: Andrew Sackville-West @ 2014-12-09 17:28 UTC (permalink / raw)
  To: Mark Kirkwood <mark.kirkwood@catalyst.net.nz>; +Cc: Alvaro Herrera <alvherre@2ndquadrant.com>; pgsql-bugs; Paulo Tanimoto <paulo@janrain.com>

On Mon, Dec 8, 2014 at 9:58 PM, Mark Kirkwood <mark.kirkwood@catalyst.net.nz
> wrote:

> On 09/12/14 12:55, Andrew Sackville-West wrote:
>
>>
>> https://gist.github.com/andrewsw-janrain/40d1687db013b1e7c3b3
>>
>> for detailed instructions on how to trigger the deadlock.
>
>

>
>>
> That is interesting - FWIW I can reproduce:
>
> - 9.2.9 no deadlock
> - 9.4rc1 many deadlocks
>
> so something has changed after 9.2 for sure!
>
> Just mucking about I changed certain things in your schema setup (removed
> ON DELETE CASCADE, use CURRENT_TIMESTAMP instead of now()...lessen the use
> of DEFAULT)...however still seeing deadlocks in 9.4, so at least it is easy
> to reproduce!
>

Can you speak to what benefits those changes might yield? Or point to
relevant docs?

thanks

A


>
> Regards
>
> Mark
>
>
>
>
> --
> Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs
>

^ permalink  raw  reply  [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-12-09 17:38  Andrew Sackville-West <awest@janrain.com>
  parent: Alvaro Herrera <alvherre@2ndquadrant.com>
  0 siblings, 1 reply; 34+ messages in thread

From: Andrew Sackville-West @ 2014-12-09 17:38 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: hubert depesz lubaczewski <depesz@gmail.com>; Mark Kirkwood <mark.kirkwood@catalyst.net.nz>; pgsql-bugs; Paulo Tanimoto <paulo@janrain.com>

On Tue, Dec 9, 2014 at 6:14 AM, Alvaro Herrera <alvherre@2ndquadrant.com>
wrote:

> hubert depesz lubaczewski wrote:
> > For whatever it's worth, I was able to bisect the problem to this commit:
> >
> > commit
> > 0ac5ad5134f2769ccbaefec73844f8504c4d6182
> >
> > Author: Alvaro Herrera <alvherre@alvh.no-ip.org>
> >
> > Date:   Wed Jan 23 12:04:59 2013 -0300
> >
> >     Improve concurrency of foreign key locking
>
> I'm not surprised in the least, TBH.
>
>
Thanks for your attention to this. Is there anything we're doing wrong that
could improve this in current 9.3 versions?

A


> --
> Álvaro Herrera                http://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
>
>
> --
> Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs
>

^ permalink  raw  reply  [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-12-09 17:43  Andres Freund <andres@2ndquadrant.com>
  parent: Andrew Sackville-West <awest@janrain.com>
  0 siblings, 1 reply; 34+ messages in thread

From: Andres Freund @ 2014-12-09 17:43 UTC (permalink / raw)
  To: Andrew Sackville-West <awest@janrain.com>; +Cc: Alvaro Herrera <alvherre@2ndquadrant.com>; hubert depesz lubaczewski <depesz@gmail.com>; Mark Kirkwood <mark.kirkwood@catalyst.net.nz>; pgsql-bugs; Paulo Tanimoto <paulo@janrain.com>

On 2014-12-09 09:38:33 -0800, Andrew Sackville-West wrote:
> On Tue, Dec 9, 2014 at 6:14 AM, Alvaro Herrera <alvherre@2ndquadrant.com>
> wrote:
> 
> > hubert depesz lubaczewski wrote:
> > > For whatever it's worth, I was able to bisect the problem to this commit:
> > >
> > > commit
> > > 0ac5ad5134f2769ccbaefec73844f8504c4d6182
> > >
> > > Author: Alvaro Herrera <alvherre@alvh.no-ip.org>
> > >
> > > Date:   Wed Jan 23 12:04:59 2013 -0300
> > >
> > >     Improve concurrency of foreign key locking
> >
> > I'm not surprised in the least, TBH.
> >
> >
> Thanks for your attention to this. Is there anything we're doing wrong that
> could improve this in current 9.3 versions?

I don't think anybody can seriously can give you a serious workaround
until the issue has been diagnosed further.

One thing you could try would be to create a unique index that spans all
the columns in the table... That'd prevent usage of lower locklevels
added in the above commit.

Greetings,

Andres Freund

-- 
 Andres Freund	                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-12-09 18:24  Alvaro Herrera <alvherre@2ndquadrant.com>
  parent: Andrew Sackville-West <awest@janrain.com>
  1 sibling, 0 replies; 34+ messages in thread

From: Alvaro Herrera @ 2014-12-09 18:24 UTC (permalink / raw)
  To: pgsql-bugs; Paulo Tanimoto <paulo@janrain.com>

Andrew Sackville-West wrote:
> Some months later (stupid business priorities...) we have something to
> report on this. We have been able to produce a minimal schema to
> demonstrate the problem, and successfully induced the deadlock using
> pgbench (thanks to Paulo Tanimoto, cc-ed here).
> 
> Please see:
> 
> https://gist.github.com/andrewsw-janrain/40d1687db013b1e7c3b3
> 
> for detailed instructions on how to trigger the deadlock.
> 
> I would be thrilled to learn that we've done something wrong here,
> otherwise I think this represents a regression introduced in 9.3.

To avoid having to visit an external URL that might well not exist at
all, and to simplify the test case which still has too many extraneous
details, here's a simpler version that still causes the UPDATE to
deadlock:

-- schema.sql:
create table pktab (id int primary key, data serial not null);
create table fktab (fk int references pktab);
insert into pktab values (1);

-- query.sql:
update pktab set data = default;
insert into fktab values (1);

This doesn't deadlock in 9.2, yet in 9.3 it raises an error in a few
seconds with pgbench -c 16.

-- 
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-12-10 03:07  Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
  parent: Andrew Sackville-West <awest@janrain.com>
  0 siblings, 1 reply; 34+ messages in thread

From: Mark Kirkwood @ 2014-12-10 03:07 UTC (permalink / raw)
  To: Andrew Sackville-West <awest@janrain.com>; +Cc: Alvaro Herrera <alvherre@2ndquadrant.com>; pgsql-bugs; Paulo Tanimoto <paulo@janrain.com>

On 10/12/14 06:28, Andrew Sackville-West wrote:
> On Mon, Dec 8, 2014 at 9:58 PM, Mark Kirkwood

>     Just mucking about I changed certain things in your schema setup
>     (removed ON DELETE CASCADE, use CURRENT_TIMESTAMP instead of
>     now()...lessen the use of DEFAULT)...however still seeing deadlocks
>     in 9.4, so at least it is easy to reproduce!
>
>
> Can you speak to what benefits those changes might yield? Or point to
> relevant docs?
>

Not so much advantages - just seeing if I could still reproduce the 
issue with a simpler test case i.e ensuring you were not doing anything 
'odd' - and you are not :-)

The next step would be trying to figure out what commit introduced this 
behaviour - but depesz has already beaten me to that (nice work)!

Cheers

Mark


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-12-10 16:29  Andrew Sackville-West <awest@janrain.com>
  parent: Andres Freund <andres@2ndquadrant.com>
  0 siblings, 0 replies; 34+ messages in thread

From: Andrew Sackville-West @ 2014-12-10 16:29 UTC (permalink / raw)
  To: Andres Freund <andres@2ndquadrant.com>; +Cc: pgsql-bugs; Paulo Tanimoto <paulo@janrain.com>

On Tue, Dec 09, 2014 at 06:43:20PM +0100, Andres Freund wrote:
> On 2014-12-09 09:38:33 -0800, Andrew Sackville-West wrote:
> > On Tue, Dec 9, 2014 at 6:14 AM, Alvaro Herrera <alvherre@2ndquadrant.com>
> > wrote:
> >
> > > hubert depesz lubaczewski wrote:
> > > > For whatever it's worth, I was able to bisect the problem to this commit:
> > > >
> > > > commit
> > > > 0ac5ad5134f2769ccbaefec73844f8504c4d6182
> > > >
> > > > Author: Alvaro Herrera <alvherre@alvh.no-ip.org>
> > > >
> > > > Date:   Wed Jan 23 12:04:59 2013 -0300
> > > >
> > > >     Improve concurrency of foreign key locking
> > >
> > > I'm not surprised in the least, TBH.
> > >
> > >
> > Thanks for your attention to this. Is there anything we're doing wrong that
> > could improve this in current 9.3 versions?
>
> I don't think anybody can seriously can give you a serious workaround
> until the issue has been diagnosed further.

agreed.

>
> One thing you could try would be to create a unique index that spans all
> the columns in the table... That'd prevent usage of lower locklevels
> added in the above commit.


Thanks for this idea. I'll investigate.

thanks


A


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-12-10 19:33  Alvaro Herrera <alvherre@2ndquadrant.com>
  parent: Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
  0 siblings, 1 reply; 34+ messages in thread

From: Alvaro Herrera @ 2014-12-10 19:33 UTC (permalink / raw)
  To: Mark Kirkwood <mark.kirkwood@catalyst.net.nz>; +Cc: Andrew Sackville-West <awest@janrain.com>; pgsql-bugs; Paulo Tanimoto <paulo@janrain.com>

Mark Kirkwood wrote:

> Not so much advantages - just seeing if I could still reproduce the issue
> with a simpler test case i.e ensuring you were not doing anything 'odd' -
> and you are not :-)
> 
> The next step would be trying to figure out what commit introduced this
> behaviour - but depesz has already beaten me to that (nice work)!

So I traced through the problem using the simplified test case I posted.
It goes like this:

* tuple on the referenced table has been updated a bunch of times
  already, and keeps being updated, so there's a large update chain to
  follow.

* two or more transactions (T1 and T2, say) have snapshots in which
  some version of the tuple (not the last one) is visible.

* transaction T3 has a ForKeyShare lock on the latest version of the
  tuple, which is grabbed because of the INSERT in the referencing
  table.  Note that these locks are propagated upwards in an update
  chain, so even if T3 locked an old version, all future versions are
  also locked by T3.

* each of T1 and T2 tries to update the version they have visible; this
  fails because it's not the last version, so they need to go through
  EvalPlanQual, which walks through the update chain.

At this point, T1 passes through heap_lock_tuple, gets the HW tuple
lock, marks itself as locker in the tuple's Xmax.  T1 is scheduled out;
time for T2 to run.  T2 goes through heap_lock_tuple, grabs HW lock;
examines Xmax, sees that T1 is the locker, goes to sleep until T1
awakes.  T1 is scheduled to run again, runs heap_update.  The first
thing it needs is to do LockTuple ...  but T2 is holding that one, so T1
goes to sleep until T2 awakes -- now they are both sleeping on each
other.

Kaboom.

I'm not seeing a solution here.  There is something wrong in having to
release the HW lock then grab it again, in that EvalPlanQual dance.  It
sounds like we need to hold on to the tuple's HW lock until after
heap_update has run, but it's not at all clear how this would work --
the interface through EvalPlanQual is messy enough as it is without
entertaining the idea that a "please keep HW lock until later" flag
needs to be passed up and down all over the place.

One simple idea that occurs to me is have some global state in heapam.c;
when the EPQ code is invoked from ExecUpdate, we tell heapam to keep the
HW lock, and it's only released once heap_update is finished.  That
would keep T2 away from the tuple.  We'd need a PG_TRY block in
ExecUpdate to reset the global state once the update is done.  (It's not
entirely clear that we need all this for deletes too.  The main
difference is that after a delete completes the tuple is gone, which is
obviously not the case in an update.  Also, deletes don't create update
chains.)

One thing I haven't thought too much about is why doesn't this happen in
9.2.

-- 
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-12-10 21:56  Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
  parent: Alvaro Herrera <alvherre@2ndquadrant.com>
  0 siblings, 1 reply; 34+ messages in thread

From: Mark Kirkwood @ 2014-12-10 21:56 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: Andrew Sackville-West <awest@janrain.com>; pgsql-bugs; Paulo Tanimoto <paulo@janrain.com>

On 11/12/14 08:33, Alvaro Herrera wrote:
> Mark Kirkwood wrote:
>
>> Not so much advantages - just seeing if I could still reproduce the issue
>> with a simpler test case i.e ensuring you were not doing anything 'odd' -
>> and you are not :-)
>>
>> The next step would be trying to figure out what commit introduced this
>> behaviour - but depesz has already beaten me to that (nice work)!
>
> So I traced through the problem using the simplified test case I posted.
> It goes like this:
>
> * tuple on the referenced table has been updated a bunch of times
>    already, and keeps being updated, so there's a large update chain to
>    follow.
>
> * two or more transactions (T1 and T2, say) have snapshots in which
>    some version of the tuple (not the last one) is visible.
>
> * transaction T3 has a ForKeyShare lock on the latest version of the
>    tuple, which is grabbed because of the INSERT in the referencing
>    table.  Note that these locks are propagated upwards in an update
>    chain, so even if T3 locked an old version, all future versions are
>    also locked by T3.
>
> * each of T1 and T2 tries to update the version they have visible; this
>    fails because it's not the last version, so they need to go through
>    EvalPlanQual, which walks through the update chain.
>
> At this point, T1 passes through heap_lock_tuple, gets the HW tuple
> lock, marks itself as locker in the tuple's Xmax.  T1 is scheduled out;
> time for T2 to run.  T2 goes through heap_lock_tuple, grabs HW lock;
> examines Xmax, sees that T1 is the locker, goes to sleep until T1
> awakes.  T1 is scheduled to run again, runs heap_update.  The first
> thing it needs is to do LockTuple ...  but T2 is holding that one, so T1
> goes to sleep until T2 awakes -- now they are both sleeping on each
> other.
>
> Kaboom.
>
> I'm not seeing a solution here.  There is something wrong in having to
> release the HW lock then grab it again, in that EvalPlanQual dance.  It
> sounds like we need to hold on to the tuple's HW lock until after
> heap_update has run, but it's not at all clear how this would work --
> the interface through EvalPlanQual is messy enough as it is without
> entertaining the idea that a "please keep HW lock until later" flag
> needs to be passed up and down all over the place.
>
> One simple idea that occurs to me is have some global state in heapam.c;
> when the EPQ code is invoked from ExecUpdate, we tell heapam to keep the
> HW lock, and it's only released once heap_update is finished.  That
> would keep T2 away from the tuple.  We'd need a PG_TRY block in
> ExecUpdate to reset the global state once the update is done.  (It's not
> entirely clear that we need all this for deletes too.  The main
> difference is that after a delete completes the tuple is gone, which is
> obviously not the case in an update.  Also, deletes don't create update
> chains.)
>
> One thing I haven't thought too much about is why doesn't this happen in
> 9.2.
>

Hmmm - interesting, yeah I think the why-it-doesn't-in-9.2 part is the 
next thing to understand :-)

Cheers

Mark


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-12-11 07:12  Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
  parent: Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
  0 siblings, 1 reply; 34+ messages in thread

From: Mark Kirkwood @ 2014-12-11 07:12 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: Andrew Sackville-West <awest@janrain.com>; pgsql-bugs; Paulo Tanimoto <paulo@janrain.com>

On 11/12/14 10:56, Mark Kirkwood wrote:
> On 11/12/14 08:33, Alvaro Herrera wrote:
>> Mark Kirkwood wrote:
>>
>>> Not so much advantages - just seeing if I could still reproduce the
>>> issue
>>> with a simpler test case i.e ensuring you were not doing anything
>>> 'odd' -
>>> and you are not :-)
>>>
>>> The next step would be trying to figure out what commit introduced this
>>> behaviour - but depesz has already beaten me to that (nice work)!
>>
>> So I traced through the problem using the simplified test case I posted.
>> It goes like this:
>>
>> * tuple on the referenced table has been updated a bunch of times
>>    already, and keeps being updated, so there's a large update chain to
>>    follow.
>>
>> * two or more transactions (T1 and T2, say) have snapshots in which
>>    some version of the tuple (not the last one) is visible.
>>
>> * transaction T3 has a ForKeyShare lock on the latest version of the
>>    tuple, which is grabbed because of the INSERT in the referencing
>>    table.  Note that these locks are propagated upwards in an update
>>    chain, so even if T3 locked an old version, all future versions are
>>    also locked by T3.
>>
>> * each of T1 and T2 tries to update the version they have visible; this
>>    fails because it's not the last version, so they need to go through
>>    EvalPlanQual, which walks through the update chain.
>>
>> At this point, T1 passes through heap_lock_tuple, gets the HW tuple
>> lock, marks itself as locker in the tuple's Xmax.  T1 is scheduled out;
>> time for T2 to run.  T2 goes through heap_lock_tuple, grabs HW lock;
>> examines Xmax, sees that T1 is the locker, goes to sleep until T1
>> awakes.  T1 is scheduled to run again, runs heap_update.  The first
>> thing it needs is to do LockTuple ...  but T2 is holding that one, so T1
>> goes to sleep until T2 awakes -- now they are both sleeping on each
>> other.
>>
>> Kaboom.
>>
>> I'm not seeing a solution here.  There is something wrong in having to
>> release the HW lock then grab it again, in that EvalPlanQual dance.  It
>> sounds like we need to hold on to the tuple's HW lock until after
>> heap_update has run, but it's not at all clear how this would work --
>> the interface through EvalPlanQual is messy enough as it is without
>> entertaining the idea that a "please keep HW lock until later" flag
>> needs to be passed up and down all over the place.
>>
>> One simple idea that occurs to me is have some global state in heapam.c;
>> when the EPQ code is invoked from ExecUpdate, we tell heapam to keep the
>> HW lock, and it's only released once heap_update is finished.  That
>> would keep T2 away from the tuple.  We'd need a PG_TRY block in
>> ExecUpdate to reset the global state once the update is done.  (It's not
>> entirely clear that we need all this for deletes too.  The main
>> difference is that after a delete completes the tuple is gone, which is
>> obviously not the case in an update.  Also, deletes don't create update
>> chains.)
>>
>> One thing I haven't thought too much about is why doesn't this happen in
>> 9.2.
>>
>
> Hmmm - interesting, yeah I think the why-it-doesn't-in-9.2 part is the
> next thing to understand :-)
>

In the most glaringly obvious (and possibly not at all helpful) analysis 
- this is because we are using "FOR KEY SHARE" instead of "FOR SHARE" in 
the newer code. Reverting this (see attached very basic patch) gets rid 
of the deadlock (tested in 9.5devel). However this is obviously a less 
than desirable solution, as it loses any possible concurrency 
improvement - that we worked hard to gain in the patch that added this 
new lock mode! We really want to figure out how to keep "FOR KEY SHARE" 
and have it *not* deadlock.

Cheers

Mark

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

0002-undo-fk-concurrency.patch (text/x-patch, 1.6K) download diff --git a/src/backend/utils/adt/ri_triggers.c b/src/backend/utils/adt/ri_triggers.c index 2f02303..a38ea32 100644 --- a/src/backend/utils/adt/ri_triggers.c +++ b/src/backend/utils/adt/ri_triggers.c @@ -427,7 +427,7 @@ RI_FKey_check(TriggerData *trigdata) querysep = "AND"; queryoids[i] = fk_type; } - appendStringInfoString(&querybuf, " FOR KEY SHARE OF x"); + appendStringInfoString(&querybuf, " FOR SHARE OF x"); /* Prepare and save the plan */ qplan = ri_PlanCheck(querybuf.data, riinfo->nkeys, queryoids, @@ -562,7 +562,7 @@ ri_Check_Pk_Match(Relation pk_rel, Relation fk_rel, querysep = "AND"; queryoids[i] = pk_type; } - appendStringInfoString(&querybuf, " FOR KEY SHARE OF x"); + appendStringInfoString(&querybuf, " FOR SHARE OF x"); /* Prepare and save the plan */ qplan = ri_PlanCheck(querybuf.data, riinfo->nkeys, queryoids, @@ -754,7 +754,7 @@ ri_restrict_del(TriggerData *trigdata, bool is_no_action) querysep = "AND"; queryoids[i] = pk_type; } - appendStringInfoString(&querybuf, " FOR KEY SHARE OF x"); + appendStringInfoString(&querybuf, " FOR SHARE OF x"); /* Prepare and save the plan */ qplan = ri_PlanCheck(querybuf.data, riinfo->nkeys, queryoids, @@ -977,7 +977,7 @@ ri_restrict_upd(TriggerData *trigdata, bool is_no_action) querysep = "AND"; queryoids[i] = pk_type; } - appendStringInfoString(&querybuf, " FOR KEY SHARE OF x"); + appendStringInfoString(&querybuf, " FOR SHARE OF x"); /* Prepare and save the plan */ qplan = ri_PlanCheck(querybuf.data, riinfo->nkeys, queryoids,
^ permalink raw reply [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-12-11 13:06  Alvaro Herrera <alvherre@2ndquadrant.com>
  parent: Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
  0 siblings, 1 reply; 34+ messages in thread

From: Alvaro Herrera @ 2014-12-11 13:06 UTC (permalink / raw)
  To: Mark Kirkwood <mark.kirkwood@catalyst.net.nz>; +Cc: Andrew Sackville-West <awest@janrain.com>; pgsql-bugs; Paulo Tanimoto <paulo@janrain.com>

Mark Kirkwood wrote:

> In the most glaringly obvious (and possibly not at all helpful) analysis -
> this is because we are using "FOR KEY SHARE" instead of "FOR SHARE" in the
> newer code. Reverting this (see attached very basic patch) gets rid of the
> deadlock (tested in 9.5devel). However this is obviously a less than
> desirable solution, as it loses any possible concurrency improvement - that
> we worked hard to gain in the patch that added this new lock mode! We really
> want to figure out how to keep "FOR KEY SHARE" and have it *not* deadlock.

Yeah.  The problem is that the INSERT in the fktab table takes a FOR KEY
SHARE lock in the pktab table.  This puts the inserting process' Xid
into the tuple's Xmax, but allows concurrent UPDATE while the inserter
transaction is still in progress.  If you use a FOR SHARE lock, the
UPDATE is disallowed until the inserter transaction is completed.

Having the inserter be live is what causes the heap_lock_tuple and
heap_update calls in the updater process to take the heavyweight tuple
lock.

I think what we should do here is NOT take the HW lock unless we're
going to sleep in heap_lock_tuple and heap_update.  Right now we always
take it if HeapTupleSatisfiesUpdate returns HeapTupleBeingUpdated, even
if we end up not sleeping to wait for something else.

I'm going to experiment with that idea and see if it leads to a
solution.  I tried the other idea yesterday (to keep the HW tuple lock
we acquire in heap_lock_tuple until heap_update is done) but aside from
being very complicated and bug-prone, it doesn't solve the problem
anyway.

-- 
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-12-11 17:22  Alvaro Herrera <alvherre@2ndquadrant.com>
  parent: Alvaro Herrera <alvherre@2ndquadrant.com>
  0 siblings, 5 replies; 34+ messages in thread

From: Alvaro Herrera @ 2014-12-11 17:22 UTC (permalink / raw)
  To: Mark Kirkwood <mark.kirkwood@catalyst.net.nz>; +Cc: Andrew Sackville-West <awest@janrain.com>; pgsql-bugs; Paulo Tanimoto <paulo@janrain.com>

Alvaro Herrera wrote:

> I'm going to experiment with that idea and see if it leads to a
> solution.  I tried the other idea yesterday (to keep the HW tuple lock
> we acquire in heap_lock_tuple until heap_update is done) but aside from
> being very complicated and bug-prone, it doesn't solve the problem
> anyway.

Here's a preliminary patch.  It does solve the deadlock in my simplified
test case.  If Andrew can confirm that it fixes his original problem
too, that'd be good.

Before this can be committed I need an isolationtester spec file that
reproduces the problem.  Now that I understand why it happens it should
be easy to produce: just have a transaction that does BEGIN, then the
insert, and keeps the transaction open; enough other sessions run the
UPDATE until the problem pops up.  (Also, comments on
Would_MultiXactIdWait_Block need work.)

FWIW this code should also have slightly better performance than the
original coding, since the heavyweight tuple lock acquisition is skipped
in some cases.  Not sure if that is measurable, though.  Maybe in
extreme cases such as the one in #8470 ...

-- 
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

deadlock.patch (text/x-diff, 9.2K) download diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index df4853b..5f92627 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -93,6 +93,9 @@ static void HeapSatisfiesHOTandKeyUpdate(Relation relation, bool *satisfies_hot, bool *satisfies_key, bool *satisfies_id, HeapTuple oldtup, HeapTuple newtup); +static bool heap_acquire_tuplock(Relation relation, ItemPointer tid, + LockTupleMode mode, LockWaitPolicy wait_policy, + bool *have_tuple_lock); static void compute_new_xmax_infomask(TransactionId xmax, uint16 old_infomask, uint16 old_infomask2, TransactionId add_to_xmax, LockTupleMode mode, bool is_update, @@ -110,6 +113,8 @@ static void MultiXactIdWait(MultiXactId multi, MultiXactStatus status, uint16 in int *remaining); static bool ConditionalMultiXactIdWait(MultiXactId multi, MultiXactStatus status, uint16 infomask, Relation rel, int *remaining); +static bool Would_MultiXactIdWait_Block(MultiXactId multi, MultiXactStatus status, + uint16 infomask); static XLogRecPtr log_heap_new_cid(Relation relation, HeapTuple tup); static HeapTuple ExtractReplicaIdentity(Relation rel, HeapTuple tup, bool key_modified, bool *copy); @@ -2700,11 +2705,8 @@ l1: * this arranges that we stay at the head of the line while rechecking * tuple state. */ - if (!have_tuple_lock) - { - LockTupleTuplock(relation, &(tp.t_self), LockTupleExclusive); - have_tuple_lock = true; - } + heap_acquire_tuplock(relation, &(tp.t_self), LockTupleExclusive, + LockWaitBlock, &have_tuple_lock); /* * Sleep until concurrent transaction ends. Note that we don't care @@ -3224,21 +3226,6 @@ l2: LockBuffer(buffer, BUFFER_LOCK_UNLOCK); /* - * Acquire tuple lock to establish our priority for the tuple (see - * heap_lock_tuple). LockTuple will release us when we are - * next-in-line for the tuple. - * - * If we are forced to "start over" below, we keep the tuple lock; - * this arranges that we stay at the head of the line while rechecking - * tuple state. - */ - if (!have_tuple_lock) - { - LockTupleTuplock(relation, &(oldtup.t_self), *lockmode); - have_tuple_lock = true; - } - - /* * Now we have to do something about the existing locker. If it's a * multi, sleep on it; we might be awakened before it is completely * gone (or even not sleep at all in some cases); we need to preserve @@ -3248,12 +3235,30 @@ l2: * before actually going to sleep. If the update doesn't conflict * with the locks, we just continue without sleeping (but making sure * it is preserved). + * + * Before sleeping, we need to acquire tuple lock to establish our + * priority for the tuple (see heap_lock_tuple). LockTuple will + * release us when we are next-in-line for the tuple. Note we must not + * acquire the tuple lock until we're sure we're going to sleep; + * otherwise we're open for race conditions with other transactions + * holding the tuple lock which sleep on us. + * + * If we are forced to "start over" below, we keep the tuple lock; + * this arranges that we stay at the head of the line while rechecking + * tuple state. */ if (infomask & HEAP_XMAX_IS_MULTI) { TransactionId update_xact; int remain; + /* acquire tuple lock, if necessary */ + if (Would_MultiXactIdWait_Block((MultiXactId) xwait, mxact_status, infomask)) + { + heap_acquire_tuplock(relation, &(oldtup.t_self), *lockmode, + LockWaitBlock, &have_tuple_lock); + } + /* wait for multixact */ MultiXactIdWait((MultiXactId) xwait, mxact_status, infomask, relation, &oldtup.t_data->t_ctid, XLTW_Update, @@ -3330,7 +3335,12 @@ l2: } else { - /* wait for regular transaction to end */ + /* + * Wait for regular transaction to end; but first, acquire + * tuple lock. + */ + heap_acquire_tuplock(relation, &(oldtup.t_self), *lockmode, + LockWaitBlock, &have_tuple_lock); XactLockTableWait(xwait, relation, &oldtup.t_data->t_ctid, XLTW_Update); LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE); @@ -4038,6 +4048,48 @@ get_mxact_status_for_lock(LockTupleMode mode, bool is_update) return (MultiXactStatus) retval; } +/* + * Acquire heavyweight lock on the given tuple, in preparation for acquiring + * its normal, Xmax-based tuple lock. + * + * have_tuple_lock is an input and output parameter: on input, it indicates + * whether the lock has previously been acquired (and this function does + * nothing in that case). If this function returns success, have_tuple_lock + * has been flipped to true. + * + * Returns false if it was unable to obtain the lock; this can only happen if + * wait_policy is Skip. + */ +static bool +heap_acquire_tuplock(Relation relation, ItemPointer tid, LockTupleMode mode, + LockWaitPolicy wait_policy, bool *have_tuple_lock) +{ + if (*have_tuple_lock) + return true; + + switch (wait_policy) + { + case LockWaitBlock: + LockTupleTuplock(relation, tid, mode); + break; + + case LockWaitSkip: + if (!ConditionalLockTupleTuplock(relation, tid, mode)) + return false; + break; + + case LockWaitError: + if (!ConditionalLockTupleTuplock(relation, tid, mode)) + ereport(ERROR, + (errcode(ERRCODE_LOCK_NOT_AVAILABLE), + errmsg("could not obtain lock on row in relation \"%s\"", + RelationGetRelationName(relation)))); + break; + } + *have_tuple_lock = true; + + return true; +} /* * heap_lock_tuple - lock a tuple in shared or exclusive mode @@ -4171,42 +4223,6 @@ l3: } /* - * Acquire tuple lock to establish our priority for the tuple. - * LockTuple will release us when we are next-in-line for the tuple. - * We must do this even if we are share-locking. - * - * If we are forced to "start over" below, we keep the tuple lock; - * this arranges that we stay at the head of the line while rechecking - * tuple state. - */ - if (!have_tuple_lock) - { - switch (wait_policy) - { - case LockWaitBlock: - LockTupleTuplock(relation, tid, mode); - break; - case LockWaitSkip: - if (!ConditionalLockTupleTuplock(relation, tid, mode)) - { - result = HeapTupleWouldBlock; - /* recovery code expects to have buffer lock held */ - LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE); - goto failed; - } - break; - case LockWaitError: - if (!ConditionalLockTupleTuplock(relation, tid, mode)) - ereport(ERROR, - (errcode(ERRCODE_LOCK_NOT_AVAILABLE), - errmsg("could not obtain lock on row in relation \"%s\"", - RelationGetRelationName(relation)))); - break; - } - have_tuple_lock = true; - } - - /* * Initially assume that we will have to wait for the locking * transaction(s) to finish. We check various cases below in which * this can be turned off. @@ -4327,6 +4343,9 @@ l3: * We don't need to allow old multixacts here; if that had * been the case, HeapTupleSatisfiesUpdate would have returned * MayBeUpdated and we wouldn't be here. + * + * XXX looks like this can be replaced with a call to + * Would_MultiXactIdWait_Block */ nmembers = GetMultiXactIdMembers(xwait, &members, false, @@ -4397,6 +4416,28 @@ l3: if (require_sleep) { + /* + * Acquire tuple lock to establish our priority for the tuple. + * LockTuple will release us when we are next-in-line for the tuple. + * We must do this even if we are share-locking. + * + * If we are forced to "start over" below, we keep the tuple lock; + * this arranges that we stay at the head of the line while rechecking + * tuple state. + */ + if (!heap_acquire_tuplock(relation, tid, mode, wait_policy, + &have_tuple_lock)) + { + /* + * This can only happen if wait_policy is Skip and the lock + * couldn't be obtained. + */ + result = HeapTupleWouldBlock; + /* recovery code expects to have buffer lock held */ + LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE); + goto failed; + } + if (infomask & HEAP_XMAX_IS_MULTI) { MultiXactStatus status = get_mxact_status_for_lock(mode, false); @@ -6188,6 +6229,48 @@ Do_MultiXactIdWait(MultiXactId multi, MultiXactStatus status, } /* + * return true if sleeping on the given multixact with the given status would + * cause to sleep until some xact is done. + */ +static bool +Would_MultiXactIdWait_Block(MultiXactId multi, MultiXactStatus status, + uint16 infomask) +{ + bool allow_old; + int nmembers; + MultiXactMember *members; + bool result = false; + + allow_old = !(infomask & HEAP_LOCK_MASK) && HEAP_XMAX_IS_LOCKED_ONLY(infomask); + nmembers = GetMultiXactIdMembers(multi, &members, allow_old, + HEAP_XMAX_IS_LOCKED_ONLY(infomask)); + + if (nmembers >= 0) + { + int i; + + for (i = 0; i < nmembers; i++) + { + TransactionId memxid = members[i].xid; + MultiXactStatus memstatus = members[i].status; + + if (TransactionIdIsCurrentTransactionId(memxid)) + continue; + + if (!DoLockModesConflict(LOCKMODE_from_mxstatus(memstatus), + LOCKMODE_from_mxstatus(status))) + continue; + + result = true; + break; + } + pfree(members); + } + + return result; +} + +/* * MultiXactIdWait * Sleep on a MultiXactId. *
^ permalink raw reply [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-12-11 21:28  Andrew Sackville-West <awest@janrain.com>
  parent: Alvaro Herrera <alvherre@2ndquadrant.com>
  4 siblings, 0 replies; 34+ messages in thread

From: Andrew Sackville-West @ 2014-12-11 21:28 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: Mark Kirkwood <mark.kirkwood@catalyst.net.nz>; pgsql-bugs; Paulo Tanimoto <paulo@janrain.com>

On Thu, Dec 11, 2014 at 02:22:56PM -0300, Alvaro Herrera wrote:
> Alvaro Herrera wrote:
>
> > I'm going to experiment with that idea and see if it leads to a
> > solution.  I tried the other idea yesterday (to keep the HW tuple lock
> > we acquire in heap_lock_tuple until heap_update is done) but aside from
> > being very complicated and bug-prone, it doesn't solve the problem
> > anyway.
>
> Here's a preliminary patch.  It does solve the deadlock in my simplified
> test case.  If Andrew can confirm that it fixes his original problem
> too, that'd be good.

We can try that. We don't currently build our own pg, so it'll take a
bit for us to get there. I'll report back with results.

A


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-12-11 23:05  Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
  parent: Alvaro Herrera <alvherre@2ndquadrant.com>
  4 siblings, 0 replies; 34+ messages in thread

From: Mark Kirkwood @ 2014-12-11 23:05 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: Andrew Sackville-West <awest@janrain.com>; pgsql-bugs; Paulo Tanimoto <paulo@janrain.com>

On 12/12/14 06:22, Alvaro Herrera wrote:
> Alvaro Herrera wrote:
>
>> I'm going to experiment with that idea and see if it leads to a
>> solution.  I tried the other idea yesterday (to keep the HW tuple lock
>> we acquire in heap_lock_tuple until heap_update is done) but aside from
>> being very complicated and bug-prone, it doesn't solve the problem
>> anyway.
>
> Here's a preliminary patch.  It does solve the deadlock in my simplified
> test case.  If Andrew can confirm that it fixes his original problem
> too, that'd be good.
>
> Before this can be committed I need an isolationtester spec file that
> reproduces the problem.  Now that I understand why it happens it should
> be easy to produce: just have a transaction that does BEGIN, then the
> insert, and keeps the transaction open; enough other sessions run the
> UPDATE until the problem pops up.  (Also, comments on
> Would_MultiXactIdWait_Block need work.)
>
> FWIW this code should also have slightly better performance than the
> original coding, since the heavyweight tuple lock acquisition is skipped
> in some cases.  Not sure if that is measurable, though.  Maybe in
> extreme cases such as the one in #8470 ...
>

Yeah, works for me too. I've tried your simplified and also Andrew's 
original schema + queries against 9.5devel with deadlock.patch applied 
(neither show any deadlocks in that case).

Cheers

Mark


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-12-12 08:36  Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
  parent: Alvaro Herrera <alvherre@2ndquadrant.com>
  4 siblings, 1 reply; 34+ messages in thread

From: Mark Kirkwood @ 2014-12-12 08:36 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: Andrew Sackville-West <awest@janrain.com>; pgsql-bugs; Paulo Tanimoto <paulo@janrain.com>

On 12/12/14 06:22, Alvaro Herrera wrote:

> Before this can be committed I need an isolationtester spec file that
> reproduces the problem.  Now that I understand why it happens it should
> be easy to produce: just have a transaction that does BEGIN, then the
> insert, and keeps the transaction open; enough other sessions run the
> UPDATE until the problem pops up.  (Also, comments on
> Would_MultiXactIdWait_Block need work.)
>


FWIW - I was having a look at the isolationtester spec. Playing with the 
pgbench setup to see the minimal number of session I needed to provoke 
the deadlock  (unpatched 9.5 code) seemed to converge to about 4. I 
managed to still see 1 deadlock with each session only doing 1 
transaction - i.e:

$ pgbench -c 4 -C  -n -t 1 -f query.sql deadlock

...which resulted in 1 deadlock. So we may be able to get a reasonable 
test case that shows this up! I'll take a look at setting up a test case 
later - but don't let that stop you doing it 1st :-)

Cheers

Mark



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-12-12 20:52  Alvaro Herrera <alvherre@2ndquadrant.com>
  parent: Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
  0 siblings, 1 reply; 34+ messages in thread

From: Alvaro Herrera @ 2014-12-12 20:52 UTC (permalink / raw)
  To: Mark Kirkwood <mark.kirkwood@catalyst.net.nz>; +Cc: Andrew Sackville-West <awest@janrain.com>; pgsql-bugs; Paulo Tanimoto <paulo@janrain.com>

Mark Kirkwood wrote:

> FWIW - I was having a look at the isolationtester spec. Playing with the
> pgbench setup to see the minimal number of session I needed to provoke the
> deadlock  (unpatched 9.5 code) seemed to converge to about 4. I managed to
> still see 1 deadlock with each session only doing 1 transaction - i.e:
> 
> $ pgbench -c 4 -C  -n -t 1 -f query.sql deadlock
> 
> ...which resulted in 1 deadlock. So we may be able to get a reasonable test
> case that shows this up! I'll take a look at setting up a test case later -
> but don't let that stop you doing it 1st :-)

Okay, I created a reproducer ... but it doesn't work.  I mean, the
commands are fine: if I execute them manually in four sessions in an
unpatched server I get a deadlock.  But isolationtester doesn't know to
handle more than one blocked session, so it just hangs when the third
session blocks after the second one is already blocked.  :-(

Here it is anyway.  If we get around to improving isolationtester to
handle more blocked sessions, it would be good to add this file.

setup {
   DROP TABLE IF EXISTS pktab;
   CREATE TABLE pktab (id int PRIMARY KEY, data SERIAL NOT NULL);
   INSERT INTO pktab VALUES (1, DEFAULT);
}

teardown {
   DROP TABLE pktab;
}

session "s1"
step "s1_advlock" { SELECT pg_advisory_lock(142857); }
step "s1_chain" { UPDATE pktab SET data = DEFAULT; }
step "s1_begin" { BEGIN; }
step "s1_grablock" { SELECT * FROM pktab FOR KEY SHARE; }
step "s1_advunlock" { SELECT pg_advisory_unlock(142857); }
step "s1_commit" { COMMIT; }

session "s2"
step "s2_update" { UPDATE pktab SET data = DEFAULT WHERE pg_advisory_lock_shared(142857) IS NOT NULL; }

session "s3"
step "s3_update" { UPDATE pktab SET data = DEFAULT WHERE pg_advisory_lock_shared(142857) IS NOT NULL; }

session "s4"
step "s4_update" { UPDATE pktab SET data = DEFAULT WHERE pg_advisory_lock_shared(142857) IS NOT NULL; }

permutation "s1_advlock" "s2_update" "s3_update" "s4_update" "s1_chain" "s1_grablock" "s1_advunlock" "s1_commit"

-- 
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-12-12 21:03  Peter Geoghegan <pg@heroku.com>
  parent: Alvaro Herrera <alvherre@2ndquadrant.com>
  0 siblings, 1 reply; 34+ messages in thread

From: Peter Geoghegan @ 2014-12-12 21:03 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: Mark Kirkwood <mark.kirkwood@catalyst.net.nz>; Andrew Sackville-West <awest@janrain.com>; pgsql-bugs; Paulo Tanimoto <paulo@janrain.com>

On Fri, Dec 12, 2014 at 12:52 PM, Alvaro Herrera
<alvherre@2ndquadrant.com> wrote:
> Okay, I created a reproducer ... but it doesn't work.  I mean, the
> commands are fine: if I execute them manually in four sessions in an
> unpatched server I get a deadlock.  But isolationtester doesn't know to
> handle more than one blocked session, so it just hangs when the third
> session blocks after the second one is already blocked.  :-(

We need a stress-testing framework. I hacked together one for the ON
CONFLICT UPDATE patch (https://github.com/petergeoghegan/upsert), but
a more comprehensive effort is needed.

-- 
Peter Geoghegan


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-12-12 21:16  Alvaro Herrera <alvherre@2ndquadrant.com>
  parent: Peter Geoghegan <pg@heroku.com>
  0 siblings, 1 reply; 34+ messages in thread

From: Alvaro Herrera @ 2014-12-12 21:16 UTC (permalink / raw)
  To: Peter Geoghegan <pg@heroku.com>; +Cc: Mark Kirkwood <mark.kirkwood@catalyst.net.nz>; Andrew Sackville-West <awest@janrain.com>; pgsql-bugs; Paulo Tanimoto <paulo@janrain.com>

Peter Geoghegan wrote:
> On Fri, Dec 12, 2014 at 12:52 PM, Alvaro Herrera
> <alvherre@2ndquadrant.com> wrote:
> > Okay, I created a reproducer ... but it doesn't work.  I mean, the
> > commands are fine: if I execute them manually in four sessions in an
> > unpatched server I get a deadlock.  But isolationtester doesn't know to
> > handle more than one blocked session, so it just hangs when the third
> > session blocks after the second one is already blocked.  :-(
> 
> We need a stress-testing framework. I hacked together one for the ON
> CONFLICT UPDATE patch (https://github.com/petergeoghegan/upsert), but
> a more comprehensive effort is needed.

Hm, that's nice, but I hope you realize that a framework based on shell
scripts cannot possibly work for us.

-- 
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-12-12 21:31  Peter Geoghegan <pg@heroku.com>
  parent: Alvaro Herrera <alvherre@2ndquadrant.com>
  0 siblings, 0 replies; 34+ messages in thread

From: Peter Geoghegan @ 2014-12-12 21:31 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: Mark Kirkwood <mark.kirkwood@catalyst.net.nz>; Andrew Sackville-West <awest@janrain.com>; pgsql-bugs; Paulo Tanimoto <paulo@janrain.com>

On Fri, Dec 12, 2014 at 1:16 PM, Alvaro Herrera
<alvherre@2ndquadrant.com> wrote:
> Hm, that's nice, but I hope you realize that a framework based on shell
> scripts cannot possibly work for us.

Of course it couldn't be committed, but maybe this test framework
doesn't need to live in the authoritative git repo. The effort might
be bike-shedded to death otherwise. Not everyone needs to run these
types of tests.

-- 
Peter Geoghegan


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-12-12 21:57  Alvaro Herrera <alvherre@2ndquadrant.com>
  parent: Alvaro Herrera <alvherre@2ndquadrant.com>
  4 siblings, 2 replies; 34+ messages in thread

From: Alvaro Herrera @ 2014-12-12 21:57 UTC (permalink / raw)
  To: Mark Kirkwood <mark.kirkwood@catalyst.net.nz>; +Cc: Andrew Sackville-West <awest@janrain.com>; pgsql-bugs; Paulo Tanimoto <paulo@janrain.com>

Alvaro Herrera wrote:
> Alvaro Herrera wrote:
> 
> > I'm going to experiment with that idea and see if it leads to a
> > solution.  I tried the other idea yesterday (to keep the HW tuple lock
> > we acquire in heap_lock_tuple until heap_update is done) but aside from
> > being very complicated and bug-prone, it doesn't solve the problem
> > anyway.
> 
> Here's a preliminary patch.

Here's a finished version of this patch, which I messed a bit with and
so needs some extra testing.  I want to push this shortly and backpatch
to 9.4 and 9.3.  I don't want to disrupt the 9.4.0 release next week,
but it'd be nice not to ship it with this bug.

-- 
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

deadlock-2.patch (text/x-diff, 11.9K) download diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index df4853b..fa7bd1c 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -93,6 +93,9 @@ static void HeapSatisfiesHOTandKeyUpdate(Relation relation, bool *satisfies_hot, bool *satisfies_key, bool *satisfies_id, HeapTuple oldtup, HeapTuple newtup); +static bool heap_acquire_tuplock(Relation relation, ItemPointer tid, + LockTupleMode mode, LockWaitPolicy wait_policy, + bool *have_tuple_lock); static void compute_new_xmax_infomask(TransactionId xmax, uint16 old_infomask, uint16 old_infomask2, TransactionId add_to_xmax, LockTupleMode mode, bool is_update, @@ -105,6 +108,8 @@ static void GetMultiXactIdHintBits(MultiXactId multi, uint16 *new_infomask, uint16 *new_infomask2); static TransactionId MultiXactIdGetUpdateXid(TransactionId xmax, uint16 t_infomask); +static bool DoesMultiXactIdConflict(MultiXactId multi, uint16 infomask, + LockTupleMode lockmode); static void MultiXactIdWait(MultiXactId multi, MultiXactStatus status, uint16 infomask, Relation rel, ItemPointer ctid, XLTW_Oper oper, int *remaining); @@ -2700,11 +2705,8 @@ l1: * this arranges that we stay at the head of the line while rechecking * tuple state. */ - if (!have_tuple_lock) - { - LockTupleTuplock(relation, &(tp.t_self), LockTupleExclusive); - have_tuple_lock = true; - } + heap_acquire_tuplock(relation, &(tp.t_self), LockTupleExclusive, + LockWaitBlock, &have_tuple_lock); /* * Sleep until concurrent transaction ends. Note that we don't care @@ -3224,21 +3226,6 @@ l2: LockBuffer(buffer, BUFFER_LOCK_UNLOCK); /* - * Acquire tuple lock to establish our priority for the tuple (see - * heap_lock_tuple). LockTuple will release us when we are - * next-in-line for the tuple. - * - * If we are forced to "start over" below, we keep the tuple lock; - * this arranges that we stay at the head of the line while rechecking - * tuple state. - */ - if (!have_tuple_lock) - { - LockTupleTuplock(relation, &(oldtup.t_self), *lockmode); - have_tuple_lock = true; - } - - /* * Now we have to do something about the existing locker. If it's a * multi, sleep on it; we might be awakened before it is completely * gone (or even not sleep at all in some cases); we need to preserve @@ -3248,12 +3235,30 @@ l2: * before actually going to sleep. If the update doesn't conflict * with the locks, we just continue without sleeping (but making sure * it is preserved). + * + * Before sleeping, we need to acquire tuple lock to establish our + * priority for the tuple (see heap_lock_tuple). LockTuple will + * release us when we are next-in-line for the tuple. Note we must not + * acquire the tuple lock until we're sure we're going to sleep; + * otherwise we're open for race conditions with other transactions + * holding the tuple lock which sleep on us. + * + * If we are forced to "start over" below, we keep the tuple lock; + * this arranges that we stay at the head of the line while rechecking + * tuple state. */ if (infomask & HEAP_XMAX_IS_MULTI) { TransactionId update_xact; int remain; + /* acquire tuple lock, if necessary */ + if (DoesMultiXactIdConflict((MultiXactId) xwait, infomask, *lockmode)) + { + heap_acquire_tuplock(relation, &(oldtup.t_self), *lockmode, + LockWaitBlock, &have_tuple_lock); + } + /* wait for multixact */ MultiXactIdWait((MultiXactId) xwait, mxact_status, infomask, relation, &oldtup.t_data->t_ctid, XLTW_Update, @@ -3330,7 +3335,12 @@ l2: } else { - /* wait for regular transaction to end */ + /* + * Wait for regular transaction to end; but first, acquire + * tuple lock. + */ + heap_acquire_tuplock(relation, &(oldtup.t_self), *lockmode, + LockWaitBlock, &have_tuple_lock); XactLockTableWait(xwait, relation, &oldtup.t_data->t_ctid, XLTW_Update); LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE); @@ -4038,7 +4048,6 @@ get_mxact_status_for_lock(LockTupleMode mode, bool is_update) return (MultiXactStatus) retval; } - /* * heap_lock_tuple - lock a tuple in shared or exclusive mode * @@ -4171,42 +4180,6 @@ l3: } /* - * Acquire tuple lock to establish our priority for the tuple. - * LockTuple will release us when we are next-in-line for the tuple. - * We must do this even if we are share-locking. - * - * If we are forced to "start over" below, we keep the tuple lock; - * this arranges that we stay at the head of the line while rechecking - * tuple state. - */ - if (!have_tuple_lock) - { - switch (wait_policy) - { - case LockWaitBlock: - LockTupleTuplock(relation, tid, mode); - break; - case LockWaitSkip: - if (!ConditionalLockTupleTuplock(relation, tid, mode)) - { - result = HeapTupleWouldBlock; - /* recovery code expects to have buffer lock held */ - LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE); - goto failed; - } - break; - case LockWaitError: - if (!ConditionalLockTupleTuplock(relation, tid, mode)) - ereport(ERROR, - (errcode(ERRCODE_LOCK_NOT_AVAILABLE), - errmsg("could not obtain lock on row in relation \"%s\"", - RelationGetRelationName(relation)))); - break; - } - have_tuple_lock = true; - } - - /* * Initially assume that we will have to wait for the locking * transaction(s) to finish. We check various cases below in which * this can be turned off. @@ -4312,66 +4285,26 @@ l3: { /* * If we're requesting NoKeyExclusive, we might also be able to - * avoid sleeping; just ensure that there's no other lock type - * than KeyShare. Note that this is a bit more involved than just - * checking hint bits -- we need to expand the multixact to figure - * out lock modes for each one (unless there was only one such - * locker). + * avoid sleeping; just ensure that there no conflicting lock + * already acquired. */ if (infomask & HEAP_XMAX_IS_MULTI) { - int nmembers; - MultiXactMember *members; - - /* - * We don't need to allow old multixacts here; if that had - * been the case, HeapTupleSatisfiesUpdate would have returned - * MayBeUpdated and we wouldn't be here. - */ - nmembers = - GetMultiXactIdMembers(xwait, &members, false, - HEAP_XMAX_IS_LOCKED_ONLY(infomask)); - - if (nmembers <= 0) + if (!DoesMultiXactIdConflict((MultiXactId) xwait, infomask, + mode)) { /* - * No need to keep the previous xmax here. This is - * unlikely to happen. + * No conflict, but if the xmax changed under us in the + * meantime, start over. */ - require_sleep = false; - } - else - { - int i; - bool allowed = true; - - for (i = 0; i < nmembers; i++) - { - if (members[i].status != MultiXactStatusForKeyShare) - { - allowed = false; - break; - } - } - if (allowed) - { - /* - * if the xmax changed under us in the meantime, start - * over. - */ - LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE); - if (xmax_infomask_changed(tuple->t_data->t_infomask, infomask) || - !TransactionIdEquals(HeapTupleHeaderGetRawXmax(tuple->t_data), - xwait)) - { - pfree(members); - goto l3; - } - /* otherwise, we're good */ - require_sleep = false; - } + LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE); + if (xmax_infomask_changed(tuple->t_data->t_infomask, infomask) || + !TransactionIdEquals(HeapTupleHeaderGetRawXmax(tuple->t_data), + xwait)) + goto l3; - pfree(members); + /* otherwise, we're good */ + require_sleep = false; } } else if (HEAP_XMAX_IS_KEYSHR_LOCKED(infomask)) @@ -4397,6 +4330,28 @@ l3: if (require_sleep) { + /* + * Acquire tuple lock to establish our priority for the tuple. + * LockTuple will release us when we are next-in-line for the tuple. + * We must do this even if we are share-locking. + * + * If we are forced to "start over" below, we keep the tuple lock; + * this arranges that we stay at the head of the line while rechecking + * tuple state. + */ + if (!heap_acquire_tuplock(relation, tid, mode, wait_policy, + &have_tuple_lock)) + { + /* + * This can only happen if wait_policy is Skip and the lock + * couldn't be obtained. + */ + result = HeapTupleWouldBlock; + /* recovery code expects to have buffer lock held */ + LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE); + goto failed; + } + if (infomask & HEAP_XMAX_IS_MULTI) { MultiXactStatus status = get_mxact_status_for_lock(mode, false); @@ -4713,6 +4668,48 @@ failed: return HeapTupleMayBeUpdated; } +/* + * Acquire heavyweight lock on the given tuple, in preparation for acquiring + * its normal, Xmax-based tuple lock. + * + * have_tuple_lock is an input and output parameter: on input, it indicates + * whether the lock has previously been acquired (and this function does + * nothing in that case). If this function returns success, have_tuple_lock + * has been flipped to true. + * + * Returns false if it was unable to obtain the lock; this can only happen if + * wait_policy is Skip. + */ +static bool +heap_acquire_tuplock(Relation relation, ItemPointer tid, LockTupleMode mode, + LockWaitPolicy wait_policy, bool *have_tuple_lock) +{ + if (*have_tuple_lock) + return true; + + switch (wait_policy) + { + case LockWaitBlock: + LockTupleTuplock(relation, tid, mode); + break; + + case LockWaitSkip: + if (!ConditionalLockTupleTuplock(relation, tid, mode)) + return false; + break; + + case LockWaitError: + if (!ConditionalLockTupleTuplock(relation, tid, mode)) + ereport(ERROR, + (errcode(ERRCODE_LOCK_NOT_AVAILABLE), + errmsg("could not obtain lock on row in relation \"%s\"", + RelationGetRelationName(relation)))); + break; + } + *have_tuple_lock = true; + + return true; +} /* * Given an original set of Xmax and infomask, and a transaction (identified by @@ -6092,6 +6089,71 @@ HeapTupleGetUpdateXid(HeapTupleHeader tuple) } /* + * Does the given multixact conflict with the current transaction grabbing a + * tuple lock of the given strength? + * + * The passed infomask pairs up with the given multixact in the tuple header. + */ +static bool +DoesMultiXactIdConflict(MultiXactId multi, uint16 infomask, + LockTupleMode lockmode) +{ + bool allow_old; + int nmembers; + MultiXactMember *members; + bool result = false; + + allow_old = !(infomask & HEAP_LOCK_MASK) && HEAP_XMAX_IS_LOCKED_ONLY(infomask); + nmembers = GetMultiXactIdMembers(multi, &members, allow_old, + HEAP_XMAX_IS_LOCKED_ONLY(infomask)); + if (nmembers >= 0) + { + int i; + + for (i = 0; i < nmembers; i++) + { + TransactionId memxid; + LockTupleMode memlockmode; + + /* ignore members from current xact */ + memxid = members[i].xid; + if (TransactionIdIsCurrentTransactionId(memxid)) + continue; + + memlockmode = LOCKMODE_from_mxstatus(members[i].status); + /* ignore members that don't conflict with the lock we want */ + if (!DoLockModesConflict(memlockmode, lockmode)) + continue; + + if (ISUPDATE_from_mxstatus(members[i].status)) + { + /* ignore aborted updaters */ + /* XXX do we need to check XidIsInProgress here? */ + if (TransactionIdDidAbort(memxid)) + continue; + } + else + { + /* ignore lockers-only that are no longer in progress */ + if (!TransactionIdIsInProgress(memxid)) + continue; + } + + /* + * Whatever remains are either live lockers that conflict with our + * wanted lock, and updaters that are not aborted. Those conflict + * with what we want, so return true. + */ + result = true; + break; + } + pfree(members); + } + + return result; +} + +/* * Do_MultiXactIdWait * Actual implementation for the two functions below. *
^ permalink raw reply [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-12-14 02:22  Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
  parent: Alvaro Herrera <alvherre@2ndquadrant.com>
  1 sibling, 1 reply; 34+ messages in thread

From: Mark Kirkwood @ 2014-12-14 02:22 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: Andrew Sackville-West <awest@janrain.com>; pgsql-bugs; Paulo Tanimoto <paulo@janrain.com>

On 13/12/14 10:57, Alvaro Herrera wrote:
> Alvaro Herrera wrote:
>> Alvaro Herrera wrote:
>>
>>> I'm going to experiment with that idea and see if it leads to a
>>> solution.  I tried the other idea yesterday (to keep the HW tuple lock
>>> we acquire in heap_lock_tuple until heap_update is done) but aside from
>>> being very complicated and bug-prone, it doesn't solve the problem
>>> anyway.
>>
>> Here's a preliminary patch.
>
> Here's a finished version of this patch, which I messed a bit with and
> so needs some extra testing.  I want to push this shortly and backpatch
> to 9.4 and 9.3.  I don't want to disrupt the 9.4.0 release next week,
> but it'd be nice not to ship it with this bug.
>

This patch seems good too. I'm possibly seeing it performing slightly 
slower than the previous patch (approx 68 tps vs 63 on average - 
completely untuned 9.5 running on a single SATA drive, but that could 
just be natural variation/noise).

Regards

Mark


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-12-14 02:24  Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
  parent: Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
  0 siblings, 0 replies; 34+ messages in thread

From: Mark Kirkwood @ 2014-12-14 02:24 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: Andrew Sackville-West <awest@janrain.com>; pgsql-bugs; Paulo Tanimoto <paulo@janrain.com>

On 14/12/14 15:22, Mark Kirkwood wrote:
> On 13/12/14 10:57, Alvaro Herrera wrote:
>> Alvaro Herrera wrote:
>>> Alvaro Herrera wrote:
>>>
>>>> I'm going to experiment with that idea and see if it leads to a
>>>> solution.  I tried the other idea yesterday (to keep the HW tuple lock
>>>> we acquire in heap_lock_tuple until heap_update is done) but aside from
>>>> being very complicated and bug-prone, it doesn't solve the problem
>>>> anyway.
>>>
>>> Here's a preliminary patch.
>>
>> Here's a finished version of this patch, which I messed a bit with and
>> so needs some extra testing.  I want to push this shortly and backpatch
>> to 9.4 and 9.3.  I don't want to disrupt the 9.4.0 release next week,
>> but it'd be nice not to ship it with this bug.
>>
>
> This patch seems good too. I'm possibly seeing it performing slightly
> slower than the previous patch (approx 68 tps vs 63 on average -
> completely untuned 9.5 running on a single SATA drive, but that could
> just be natural variation/noise).
>

Blast - and forgot to clarify that "seems good" means I've tested it 
against both your and Andrew's deadlock producing schema (no deadlocks 
with this patch applied)...

Cheers

Mark



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-12-15 20:06  Andrew Sackville-West <awest@janrain.com>
  parent: Alvaro Herrera <alvherre@2ndquadrant.com>
  1 sibling, 0 replies; 34+ messages in thread

From: Andrew Sackville-West @ 2014-12-15 20:06 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: Mark Kirkwood <mark.kirkwood@catalyst.net.nz>; pgsql-bugs; Paulo Tanimoto <paulo@janrain.com>

On Fri, Dec 12, 2014 at 06:57:52PM -0300, Alvaro Herrera wrote:
> Alvaro Herrera wrote:
> > Alvaro Herrera wrote:
> >
> > > I'm going to experiment with that idea and see if it leads to a
> > > solution.  I tried the other idea yesterday (to keep the HW tuple lock
> > > we acquire in heap_lock_tuple until heap_update is done) but aside from
> > > being very complicated and bug-prone, it doesn't solve the problem
> > > anyway.
> >
> > Here's a preliminary patch.
>
> Here's a finished version of this patch, which I messed a bit with and
> so needs some extra testing.  I want to push this shortly and backpatch
> to 9.4 and 9.3.  I don't want to disrupt the 9.4.0 release next week,
> but it'd be nice not to ship it with this bug.

We have tested this patch on the latest postgresql with our actual
application and it appears to work for us.

We'll be happy to test a patch against the 9.3 series, using our actual
application, as well when it becomes available.

thanks!

A


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-12-26 16:56  Alvaro Herrera <alvherre@2ndquadrant.com>
  parent: Alvaro Herrera <alvherre@2ndquadrant.com>
  4 siblings, 1 reply; 34+ messages in thread

From: Alvaro Herrera @ 2014-12-26 16:56 UTC (permalink / raw)
  To: Mark Kirkwood <mark.kirkwood@catalyst.net.nz>; +Cc: Andrew Sackville-West <awest@janrain.com>; pgsql-bugs; Paulo Tanimoto <paulo@janrain.com>

Alvaro Herrera wrote:
> Alvaro Herrera wrote:
> 
> > I'm going to experiment with that idea and see if it leads to a
> > solution.  I tried the other idea yesterday (to keep the HW tuple lock
> > we acquire in heap_lock_tuple until heap_update is done) but aside from
> > being very complicated and bug-prone, it doesn't solve the problem
> > anyway.
> 
> Here's a preliminary patch.  It does solve the deadlock in my simplified
> test case.  If Andrew can confirm that it fixes his original problem
> too, that'd be good.

Pushed this patch to master, 9.4 and 9.3.

-- 
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 34+ messages in thread

* Re: regression, deadlock in high frequency single-row UPDATE
@ 2014-12-29 23:25  Paulo Tanimoto <paulo@janrain.com>
  parent: Alvaro Herrera <alvherre@2ndquadrant.com>
  0 siblings, 0 replies; 34+ messages in thread

From: Paulo Tanimoto @ 2014-12-29 23:25 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: Mark Kirkwood <mark.kirkwood@catalyst.net.nz>; Andrew Sackville-West <awest@janrain.com>; pgsql-bugs

Hi Alvaro,

On Fri, Dec 26, 2014 at 8:56 AM, Alvaro Herrera
<alvherre@2ndquadrant.com> wrote:
>
> Pushed this patch to master, 9.4 and 9.3.
>

Thank you for porting and pushing your patch to these other branches.
Andrew, our team lead, is out this week, but I wanted to give you some
feedback as soon as possible.

I've built PostgreSQL 9.3 (git branch REL9_3_STABLE) with and without
this patch, and at least in my tests I was able to confirm that it
solves our issue.  Besides testing it with our simplified pgbench
scripts, I also tested it locally with our Haskell web server, which
was how we ran into the deadlock error in the first place.  In all my
tests, I consistently get the deadlock errors without the patch, and
no longer see them when the patch is applied.

Let us know if you'd like to see anything else tested on our end.

Take care,

Paulo


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 34+ messages in thread


end of thread, other threads:[~2014-12-29 23:25 UTC | newest]

Thread overview: 34+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-07-31 23:30 regression, deadlock in high frequency single-row UPDATE Andrew Sackville-West <awest@janrain.com>
2014-08-01 00:59 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2014-08-04 16:12   ` Andrew Sackville-West <awest@janrain.com>
2014-08-04 16:30     ` Alvaro Herrera <alvherre@2ndquadrant.com>
2014-12-08 23:55       ` Andrew Sackville-West <awest@janrain.com>
2014-12-09 05:58         ` Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
2014-12-09 12:36           ` hubert depesz lubaczewski <depesz@gmail.com>
2014-12-09 14:14             ` Alvaro Herrera <alvherre@2ndquadrant.com>
2014-12-09 17:38               ` Andrew Sackville-West <awest@janrain.com>
2014-12-09 17:43                 ` Andres Freund <andres@2ndquadrant.com>
2014-12-10 16:29                   ` Andrew Sackville-West <awest@janrain.com>
2014-12-09 17:28           ` Andrew Sackville-West <awest@janrain.com>
2014-12-10 03:07             ` Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
2014-12-10 19:33               ` Alvaro Herrera <alvherre@2ndquadrant.com>
2014-12-10 21:56                 ` Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
2014-12-11 07:12                   ` Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
2014-12-11 13:06                     ` Alvaro Herrera <alvherre@2ndquadrant.com>
2014-12-11 17:22                       ` Alvaro Herrera <alvherre@2ndquadrant.com>
2014-12-11 21:28                         ` Andrew Sackville-West <awest@janrain.com>
2014-12-11 23:05                         ` Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
2014-12-12 08:36                         ` Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
2014-12-12 20:52                           ` Alvaro Herrera <alvherre@2ndquadrant.com>
2014-12-12 21:03                             ` Peter Geoghegan <pg@heroku.com>
2014-12-12 21:16                               ` Alvaro Herrera <alvherre@2ndquadrant.com>
2014-12-12 21:31                                 ` Peter Geoghegan <pg@heroku.com>
2014-12-12 21:57                         ` Alvaro Herrera <alvherre@2ndquadrant.com>
2014-12-14 02:22                           ` Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
2014-12-14 02:24                             ` Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
2014-12-15 20:06                           ` Andrew Sackville-West <awest@janrain.com>
2014-12-26 16:56                         ` Alvaro Herrera <alvherre@2ndquadrant.com>
2014-12-29 23:25                           ` Paulo Tanimoto <paulo@janrain.com>
2014-12-09 18:24         ` Alvaro Herrera <alvherre@2ndquadrant.com>
2014-08-01 15:40 ` Marti Raudsepp <marti@juffo.org>
2014-08-01 15:46   ` Andrew Sackville-West <awest@janrain.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox