pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Martijn van Oosterhout <kleptog@svana.org>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Bill Moran <wmoran@potentialtech.com>
Cc: Aln Kapa <alnkapa@gmail.com>
Cc: Postgres General Postgres General <pgsql-general@postgresql.org>
Subject: Re: unexpected lock waits (was Re: [GENERAL] Do not understand why this happens)
Date: Sun, 9 Jun 2019 22:22:44 +0200
Message-ID: <20190609202244.GA28125@svana.org> (raw)
In-Reply-To: <3598.1363354686@sss.pgh.pa.us>
References: <CAJqqVEU2dvMO+q=BjpkCnEopT-xiWjY2Pn3XmSN8D=6HVnDh3g@mail.gmail.com>
	<20130314074251.62f6efdcb2027f87fe63d997@potentialtech.com>
	<CAJqqVEXy_GimKe6Bp6YYyB5uk6wsg9Zm+3gkvinJHzTpmaFodA@mail.gmail.com>
	<20130315071657.d767d368df0985fbff15d0a1@potentialtech.com>
	<3598.1363354686@sss.pgh.pa.us>

(sorry, very old thread)

On Fri, Mar 15, 2013 at 09:38:06AM -0400, Tom Lane wrote:
> Bill Moran <wmoran@potentialtech.com> 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...

[2]: https://www.postgresql.org/message-id/CADWG95uLhar1uq6PQLoY1mTQYeN23c1dvOr2tVjcXUBZ1ge9XA@mail.gmail...

Hope this helps.
-- 
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> The combine: one man, one day, wheat for half a million loaves of bread.





Message-ID: <20190609202244.GA28125@svana.org>
Permalink:  ../20190609202244.GA28125@svana.org/
Also on:    postgresql.org/message-id/20190609202244.GA28125@svana.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: kleptog@svana.org, tgl@sss.pgh.pa.us, wmoran@potentialtech.com, alnkapa@gmail.com
  Subject: Re: unexpected lock waits (was Re: [GENERAL] Do not understand why this happens)
  In-Reply-To: <20190609202244.GA28125@svana.org>
  References: <CAJqqVEU2dvMO+q=BjpkCnEopT-xiWjY2Pn3XmSN8D=6HVnDh3g@mail.gmail.com> <20130314074251.62f6efdcb2027f87fe63d997@potentialtech.com> <CAJqqVEXy_GimKe6Bp6YYyB5uk6wsg9Zm+3gkvinJHzTpmaFodA@mail.gmail.com> <20130315071657.d767d368df0985fbff15d0a1@potentialtech.com> <3598.1363354686@sss.pgh.pa.us> <20190609202244.GA28125@svana.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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