pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alexey Bashtanov <bashtanov@imap.cc>
To: Chris Withers <chris@withers.org>
To: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: debugging intermittent slow updates under higher load
Date: Wed, 5 Dec 2018 15:40:09 +0000
Message-ID: <56acdbff-1e87-e1f9-3e9e-873685ad0e1e@imap.cc> (raw)
In-Reply-To: <bda6cf39-08ad-322f-d562-49c042cb4012@withers.org>
References: <bda6cf39-08ad-322f-d562-49c042cb4012@withers.org>


>
> 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




view thread (9+ messages)  latest in thread

Message-ID: <56acdbff-1e87-e1f9-3e9e-873685ad0e1e@imap.cc>
Permalink:  ../56acdbff-1e87-e1f9-3e9e-873685ad0e1e@imap.cc/
Also on:    postgresql.org/message-id/56acdbff-1e87-e1f9-3e9e-873685ad0e1e@imap.cc

 · 

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: bashtanov@imap.cc, chris@withers.org
  Subject: Re: debugging intermittent slow updates under higher load
  In-Reply-To: <56acdbff-1e87-e1f9-3e9e-873685ad0e1e@imap.cc>
  References: <bda6cf39-08ad-322f-d562-49c042cb4012@withers.org> <56acdbff-1e87-e1f9-3e9e-873685ad0e1e@imap.cc>

* 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