pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephen Frost <sfrost@snowman.net>
To: Enrico Thierbach <eno@open-lab.org>
Cc: Melvin Davidson <melvin6925@gmail.com>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: SELECT .. FOR UPDATE: find out who locked a row
Date: Fri, 16 Mar 2018 11:06:11 -0400
Message-ID: <20180316150611.GJ2416@tamriel.snowman.net> (raw)
In-Reply-To: <0678E648-BF9E-410D-9EA8-B2D914A6AFFF@open-lab.org>
References: <E269BF34-4CE1-47EC-8A80-F18DE55E2BEF@open-lab.org>
	<20180315204851.GU2416@tamriel.snowman.net>
	<CANu8FixnK=FJswaK8o=eWZ7smOTh=qpb8ciFAYd9oWUCS4tb1A@mail.gmail.com>
	<206B6740-DCC5-4491-A87D-EEF5CBF8EA6B@open-lab.org>
	<20180315220512.GV2416@tamriel.snowman.net>
	<CANu8FiyPd5DUuP01RKjmYzxZcBFaPFfV6qZeiEzQJU5QAfx2jg@mail.gmail.com>
	<0678E648-BF9E-410D-9EA8-B2D914A6AFFF@open-lab.org>

Enrico,

* Enrico Thierbach (eno@open-lab.org) wrote:
> >*FWIW, I really don't understand your need to identify the actual rows
> >that
> >are locked. Once you have identified the query that is causing a block
> >(which is usually due to "Idle in Transaction"), AFAIK the only way to
> >remedy the problem is to kill the offending query, or wait for it to
> >complete. I am not aware of any way available to a user to "unlock"
> >individual rows". Indeed, if you could, it would probably lead to
> >corruption of some form.*
> 
> The goal is to run a job queue, with a potentially largish number of workers
> that feed of the queue. So it would be useful to find out which queue entry
> is being processed right now (I can easily find out: when a row cannot be
> read via SKIP UNLOCKED it is locked, and probably being worked upon.) It
> would also be great to understand which worker holds the lock. The intention
> is NOT to kill the worker or its query.
> 
> With what the conversation brought up here (still trying to catch up with
> everything) I can:
> 
> 1) determine all workers that currently are holding a lock (via Melvin’s);
> 2) on an individual base try to lock the row in a second connection and use
> a third connection to figure out which worker connection holds a lock on a
> specific single row (via Stephen’s).
> 
> This is probably good enough to cover the necessary basic functionality, so
> thank you for your input.
> 
> Am I correct to assume that there is no other way to determine who is
> holding a lock on a specific row and/or determine this for many rows in one
> go?

Evidently my second email got lost somewhere along the way- what you're
looking for is an extension called 'pgrowlocks':

https://www.postgresql.org/docs/10/static/pgrowlocks.html

My prior email on that subject is here:

https://www.postgresql.org/message-id/20180315220512.GV2416%40tamriel.snowman.net

> (I guess I am also correct to assume that whatever the worker is doing there
> is no way to somehow write this information into the database **via the same
> connection**. (Using a second connection would be obviously easy)

You can write it into the database, of course, but you can't read that
information out by some other process.  Depending on what you're doing,
you can use RAISE NOTICE to send messages back to the connected client
from within a stored procedure or similar.

Thanks!

Stephen

Attachments:

  signature.asc (application/pgp-signature, 818B) download

view thread (19+ messages)  latest in thread

Message-ID: <20180316150611.GJ2416@tamriel.snowman.net>
Permalink:  ../20180316150611.GJ2416@tamriel.snowman.net/
Also on:    postgresql.org/message-id/20180316150611.GJ2416@tamriel.snowman.net

 · 

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: sfrost@snowman.net, eno@open-lab.org, melvin6925@gmail.com
  Subject: Re: SELECT .. FOR UPDATE: find out who locked a row
  In-Reply-To: <20180316150611.GJ2416@tamriel.snowman.net>
  References: <E269BF34-4CE1-47EC-8A80-F18DE55E2BEF@open-lab.org> <20180315204851.GU2416@tamriel.snowman.net> <CANu8FixnK=FJswaK8o=eWZ7smOTh=qpb8ciFAYd9oWUCS4tb1A@mail.gmail.com> <206B6740-DCC5-4491-A87D-EEF5CBF8EA6B@open-lab.org> <20180315220512.GV2416@tamriel.snowman.net> <CANu8FiyPd5DUuP01RKjmYzxZcBFaPFfV6qZeiEzQJU5QAfx2jg@mail.gmail.com> <0678E648-BF9E-410D-9EA8-B2D914A6AFFF@open-lab.org> <20180316150611.GJ2416@tamriel.snowman.net>

* 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