Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m1a6F-0006MM-3r for pgsql-general@arkaria.postgresql.org; Thu, 08 Jul 2021 19:54:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m1a6D-0007qA-Pq for pgsql-general@arkaria.postgresql.org; Thu, 08 Jul 2021 19:54:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m1a6C-0007q2-UO for pgsql-general@lists.postgresql.org; Thu, 08 Jul 2021 19:54:17 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m1a65-0001Sb-JU for pgsql-general@lists.postgresql.org; Thu, 08 Jul 2021 19:54:16 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 1760E5C0143; Thu, 8 Jul 2021 15:54:08 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Thu, 08 Jul 2021 15:54:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=o VpAdJQC/tpLibJX9aLacubyOfZmenoManEZd7ZNxEo=; b=cGjU/CN55s3eHbcgf 40q/3DcoEYyJ7u4EhAwx3+MlbebgtPVbsoGUMeEAGtjwm11curElJSMK/p+Wj40v 9tfx9JwqGm7Y53vlLU9Ve5sbo/oHiQHu72Po4evjSTw/HW4o3ZRDqwhYGwxQOYzn b547VbIqYPubB2fc+r+cjYnByTyxP6eYEvsb8P7iha6RguwXcYHycZ6EU+cqtZdt FyP9LephsvB1m6sj+OStJA8C0dMDawlJSVe2vebPVYAJVcl7O1m1m8h0YHYLqx1I kLSH1kJnLdOj4YqEKRU2rNAf58+aQvGNK2xzX72kLU0ruKuB9vNEoLzU1HohvpsT YNYQQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=fm3; bh=oVpAdJQC/tpLibJX9aLacubyOfZmenoManEZd7ZNx Eo=; b=PK4gOtORgZ6UZoPdwFj9yvb2WUJzkhLgKEUI2+RgT5iogIfUCEn9kNkfd MGIvVCQ/p4PiEM0PYnS9jZbs4wN16wKBvsjEEM2ky7t6NcvT4aEOTuxc+gFcdP28 Fg7pSOQ7ztQf0OI4s7xMVeHa7MTF5J+IA5fi9kNgIttaCIZ/DXMsK/h3vpCapHSo JuuxcSSz1x9p+A9IclOjnbVQRJ5rAUEAfqpCx7HNML0QFLsfMGRqOVAAuC2rbrms IicN4FuDxkqZGp59jv9y0Z7TBXYN0XZECSqiCUrcxuXg1XKK/7jzaL7Rb0vQq9lF e201veQRtX9ZAQ7L7pF+7pvtlQ/lw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrtdeggddufeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthejredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeevteejtdeikeetfefhhffhteelvdekffevudegjeeu kefhgfdvieeliedtkeevhfenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhi rghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 8 Jul 2021 15:54:06 -0400 (EDT) Subject: Re: The Curious Case of the Table-Locking UPDATE Query To: Emiliano Saenz , depesz@depesz.com Cc: pgsql-general@lists.postgresql.org References: <20210706092439.GA6661@depesz.com> <20210708174224.GA9739@depesz.com> From: Adrian Klaver Message-ID: Date: Thu, 8 Jul 2021 12:54:06 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 7/8/21 12:09 PM, Emiliano Saenz wrote: > I can see that you say but the database behavior is like the block is > more general than one tuple. > It is difficult to get a pg_lock snapshot to determine some access > exclusive locks on some tables. > Monitoring the database (by Zabbix), when this type of block appears > (AccessExclusiveLock) the CPU consumption is extremely high due to it > being over one main table for our business. > The UPDATE operation has as target one tuple but the block can affect > the complete table? Is it possible? > Furthermore, monitoring other systems, it is strange that this type of > block appears, except when we make a release and we edit the database > structure, truncate tables, etc. Per docs: https://www.postgresql.org/docs/12/view-pg-locks.html "The pid column can be joined to the pid column of the pg_stat_activity view to get more information on the session holding or awaiting each lock, for example SELECT * FROM pg_locks pl LEFT JOIN pg_stat_activity psa ON pl.pid = psa.pid; Also, if you are using prepared transactions, the virtualtransaction column can be joined to the transaction column of the pg_prepared_xacts view to get more information on prepared transactions that hold locks. (A prepared transaction can never be waiting for a lock, but it continues to hold the locks it acquired while running.) For example: SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx ON pl.virtualtransaction = '-1/' || ppx.transaction; " So for the information in pg_locks.csv below, pid of 21187. Then you will find out what is actually causing the lock. > > Best regards, > > > > > On Thu, Jul 8, 2021 at 2:42 PM hubert depesz lubaczewski > > wrote: > > On Thu, Jul 08, 2021 at 02:35:33PM -0300, Emiliano Saenz wrote: > > Attach the files. > > The pg_locks file doesn't show any access exclusive locks on any table? > > =$ awk -F, 'NR==1 || $13 == "AccessExclusiveLock"' pg_locks.csv > Locktype,Database,Relation,Page,Tuple,Virtualxid,Transactionid,Classid,Objid,Objsubid,Virtualtransaction,Pid,Mode,Granted,Fastpath > tuple,248043888,248044255,213071,39,NULL,NULL,NULL,NULL,NULL,198/814,21038,AccessExclusiveLock,f,f > tuple,248043888,248044255,213071,39,NULL,NULL,NULL,NULL,NULL,34/90197,21187,AccessExclusiveLock,t,f > tuple,248043888,248044255,213071,39,NULL,NULL,NULL,NULL,NULL,132/957,21007,AccessExclusiveLock,f,f > > As you can see all the AccessExclusive locks are on tuples (rows). > > Best regards, > > depesz > -- Adrian Klaver adrian.klaver@aklaver.com