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 1ha4LN-0002lo-I7 for pgsql-general@arkaria.postgresql.org; Sun, 09 Jun 2019 20:23:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ha4LK-0002QV-VJ for pgsql-general@arkaria.postgresql.org; Sun, 09 Jun 2019 20:23:06 +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 1ha4LK-0002QN-Ic for pgsql-general@lists.postgresql.org; Sun, 09 Jun 2019 20:23:06 +0000 Received: from svana.org ([113.212.99.187]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ha4LD-0005WD-2j for pgsql-general@postgresql.org; Sun, 09 Jun 2019 20:23:05 +0000 Received: from kleptog by svana.org with local (Exim 4.84_2) (envelope-from ) id 1ha4Ky-0007jD-UO; Mon, 10 Jun 2019 06:22:48 +1000 Date: Sun, 9 Jun 2019 22:22:44 +0200 From: Martijn van Oosterhout To: Tom Lane Cc: Bill Moran , Aln Kapa , Postgres General Postgres General Message-ID: <20190609202244.GA28125@svana.org> Reply-To: Martijn van Oosterhout Mail-Followup-To: Tom Lane , Bill Moran , Aln Kapa , Postgres General Postgres General References: <20130314074251.62f6efdcb2027f87fe63d997@potentialtech.com> <20130315071657.d767d368df0985fbff15d0a1@potentialtech.com> <3598.1363354686@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3598.1363354686@sss.pgh.pa.us> X-PGP-Key-ID: Length=4096; ID=0x4BE62D44 X-PGP-Key-Fingerprint: AF6F C0D6 3B8A AF7D 942B D2BC 4BED FBE7 4BE6 2D44 User-Agent: Mutt/1.5.23 (2014-03-12) X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: kleptog@svana.org X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on calyx X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NO_RELAYS autolearn=ham autolearn_force=no version=3.4.0 Subject: Re: unexpected lock waits (was Re: [GENERAL] Do not understand why this happens) X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:24:06 +0000) X-SA-Exim-Scanned: Yes (on svana.org) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk (sorry, very old thread) On Fri, Mar 15, 2013 at 09:38:06AM -0400, Tom Lane wrote: > Bill Moran writes: > > I do wonder what else is happening in the transaction that you're > > calling NOTIFY within; and that some other statement could be causing > > the lock wait. > > FWIW, the lock seems to be the one taken to serialize insertions into > the shared NOTIFY queue, from this bit in commands/async.c: [SNIP] > This lock is held while inserting the transaction's notify message(s), > after which the transaction commits and releases the lock. There's not > very much code in that window. So what we can conclude is that some > other transaction also doing NOTIFY hung up within that sequence for > something in excess of 3 seconds. We have been shown no data whatsoever > that would allow us to speculate about what's causing that other > transaction to take so long to get through its commit sequence. I just want to add that after running into this very same issue (see [1]) that in our case the above conclusion is incorrect. It is not the NOTIFYing transactions that are holding the lock too long, but the LISTENing backends. In our case it is because we have lots of databases and all databases share a single global NOTIFY queue. To verify this I made some small patches that significantly reduce the time LISTENing backends hold the lock and they reduce the problem significantly for us, see [2]. A slow commit does have a bit of impact, but the bulk of the time is elsehwere. [1]: https://www.postgresql.org/message-id/CADWG95t0j9zF0uwdcMH81KMnDsiTAVHxmBvgYqrRJcD-iLwQhw@mail.gmail.com [2]: https://www.postgresql.org/message-id/CADWG95uLhar1uq6PQLoY1mTQYeN23c1dvOr2tVjcXUBZ1ge9XA@mail.gmail.com Hope this helps. -- Martijn van Oosterhout http://svana.org/kleptog/ > The combine: one man, one day, wheat for half a million loaves of bread.