Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gUZGx-0000pu-Kf for pgsql-general@arkaria.postgresql.org; Wed, 05 Dec 2018 15:39:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gUZGt-0001Sy-Vo for pgsql-general@arkaria.postgresql.org; Wed, 05 Dec 2018 15:39:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gUZGs-0001SS-5Q for pgsql-general@lists.postgresql.org; Wed, 05 Dec 2018 15:39:31 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gUZGm-0002wn-NG for pgsql-general@postgresql.org; Wed, 05 Dec 2018 15:39:29 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id D78FE21FEE; Wed, 5 Dec 2018 10:39:22 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 05 Dec 2018 10:39:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=imap.cc; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=X K6dxH1I7y/8Ot1DLOTecl5Hb+U/8QgnX2V3iCS2iFk=; b=lhS55Ze3SwIkDamiq WxKzeoop6K1O1+rs0W4ihMabgFcgQ7oPstvb3XUftKSdEc0rmu86f8YLGHd3xF8p TCbAuX+Ytf7BI9pfZbAXd7yjiMZEK9zsYdxqnBUWo11pYpPm6pKU4oQM6Wc1Xq6X U1Vvy4ZQVkwz67MYhaRF2UGrG4W9Qtv9HNA5KmPITQoeoZORjHjLpEcEHZACpE6g osmnk0FLwR7LMwg6XwUxGc8cp21pD9LSXlCFxEJF3O9sOOvjd+x6N+lnhMX6dcte Fz80SpWDoiCHf/s4BIulpXEYyfHq8DPMrhm0y0DkcxRXa1l8eUt/kBRTd2eXqqMi +sUnQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=XK6dxH1I7y/8Ot1DLOTecl5Hb+U/8QgnX2V3iCS2i Fk=; b=wabZ6wQNU3viH/CH8JY7YNB/+V5+EkRSRZVDjKRthe8k7Aqp9bz41Oyq5 PZXPdXW2O+o1nLpNxTCXeO1gTb+TWS/ASbjJwhleLqWpgICHkVjyHDKUvQ/FUO8U Cv/XbqoJyJm684JP68ljXsZcIsFE4tNmlXuajFVR28Q4iZgbD7PC/1xRa34ldxvb 9ZOrftiTZIW9PKRFSHQGHNXNtGPrLioSwS4FOYmaBuoQww04PMsBoLoWaZ8PEkLd gtDZ/cJrPwJCSxv+kdVULI5VC7s0AiElGOXSBAb3JM/fX82b/bnAZRMOAalh0+W+ 24wH4NvVWE1S3eHLgwsCv5MdQSbkg== X-ME-Sender: X-ME-Proxy: Received: from [10.2.33.124] (unknown [185.25.33.70]) by mail.messagingengine.com (Postfix) with ESMTPA id 81A96E44A5; Wed, 5 Dec 2018 10:39:21 -0500 (EST) Subject: Re: debugging intermittent slow updates under higher load To: Chris Withers , pgsql-general References: From: Alexey Bashtanov Message-ID: <56acdbff-1e87-e1f9-3e9e-873685ad0e1e@imap.cc> Date: Wed, 5 Dec 2018 15:40:09 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > > The table has around 1.5M rows which have been updated/inserted around > 121M times, the distribution of updates to row in alerts_alert will be > quite uneven, from 1 insert up to 1 insert and 0.5M updates. > > Under high load (200-300 inserts/updates per second) we see occasional > (~10 per hour) updates taking excessively long times (2-10s). These > updates are always of the form: > > UPDATE "alerts_alert" SET ...bunch of fields... WHERE > "alerts_alert"."id" = '...sha1 hash...'; > > Here's a sample explain: > > https://explain.depesz.com/s/Fjq8 > > What could be causing this? What could we do to debug? What config > changes could we make to alleviate this? > Hello Chris, One of the reasons could be the row already locked by another backend, doing the same kind of an update or something different. Are these updates performed in a longer transactions? Can they hit the same row from two clients at the same time? Is there any other write or select-for-update/share load on the table? Have you tried periodical logging of the non-granted locks? Try querying pg_stat_activity and pg_locks (possibly joined and maybe repeatedly self-joined, google for it) to get the backends that wait one for another while competing for to lock the same row or object. Best,  Alex