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 1h1yjX-0005sQ-RA for pgsql-admin@arkaria.postgresql.org; Thu, 07 Mar 2019 19:31:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h1yjW-0005aY-I5 for pgsql-admin@arkaria.postgresql.org; Thu, 07 Mar 2019 19:31:10 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h1yjW-0005aR-6i for pgsql-admin@lists.postgresql.org; Thu, 07 Mar 2019 19:31:10 +0000 Received: from mx2a.mailbox.org ([2001:67c:2050:104:0:2:25:2] helo=mx2.mailbox.org) by makus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h1yjO-0003VR-AW for pgsql-admin@postgresql.org; Thu, 07 Mar 2019 19:31:08 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id 45208A1122; Thu, 7 Mar 2019 20:30:56 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter05.heinlein-hosting.de (spamfilter05.heinlein-hosting.de [80.241.56.123]) (amavisd-new, port 10030) with ESMTP id QriPDTWMVc_x; Thu, 7 Mar 2019 20:30:44 +0100 (CET) Message-ID: <518282bdc21dd4fc8bbd511a3f7ae69dd6404ac9.camel@cybertec.at> Subject: Re: Too many Row Exclusive Locks held for a long time From: Laurenz Albe To: pavan95 , pgsql-admin@postgresql.org Date: Thu, 07 Mar 2019 20:30:42 +0100 In-Reply-To: <1551969446954-0.post@n3.nabble.com> References: <1551969446954-0.post@n3.nabble.com> Organization: Cybertec Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk pavan95 wrote: > I am facing an issue in one of the production servers. > > I have been observing there are many "Row Exclusive" locks occurring on a > set of similar tables around 2000 locks at any given point of time. And > then the application(Odoo) is being struck for a very long time. > > After we kill those Row Exclusive locks all the locks were released. > > Typically the below is the sample statement being run on database by the > application users: > > SELECT id FROM abc WHERE id=5075 FOR UPDATE NOWAIT; > > So every time this issue occurs we need to go into server identify the "Row > Exclusive Locks" process id's and kill them after which it works fine. > > So is there any permanent fix for this that we need to look upon? ROW EXCLUSIVE is the lock taken on a table if a transaction wants to perform INSERT, UPDATE or DELETE. It is a harmless lock. If your application is getting stuck where such a lock is involved, that means: 1. A lock is held for a long time. 2. Something requests a conflicting lock, i.e. SHARE or higher. Long transactions are evil not only because they hold locks, but also because they prevent VACUUM from doing its job. Taking high table locks (probably with an explicit LOCK statement) is something hat should not be done regularly. For one, it makes autovacuum give up, which can lead to table bloat. Try to figure out what causes the high table lock (you should see it stuck behind a ROW EXCLUSIVE lock or vice versa). Try to fix the application so that it uses short transactions. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com