From: Stephen Frost <sfrost@snowman.net>
To: Melvin Davidson <melvin6925@gmail.com>
Cc: Enrico Thierbach <eno@open-lab.org>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: SELECT .. FOR UPDATE: find out who locked a row
Date: Thu, 15 Mar 2018 22:14:11 -0400
Message-ID: <20180316021411.GX2416@tamriel.snowman.net> (raw)
In-Reply-To: <CANu8FiyPd5DUuP01RKjmYzxZcBFaPFfV6qZeiEzQJU5QAfx2jg@mail.gmail.com>
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>
Greetings Melvin,
* Melvin Davidson (melvin6925@gmail.com) wrote:
> >I guess with your query I can figure out which connection holds a lock,
> but it seems I cannot correlate those locks to the rows which actually are
> locked, since pg_locks seems not to reference this in any way.
>
> *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.*
No, locks are not able to be released mid-transaction. That said, it
can be difficult sometimes to determine which of the many sessions is
holding a lock on a specific row, hence the two approaches I provided,
which actually address the question which was raised. While the
use-case might not be on completely solid ground here, I don't think
it's entirely unreasonable, so I don't think there's any need to tell
the OP that what they're asking for isn't really what they want, in this
case.
> *BTW, the query I provided WILL work in version 10. The commented section
> was for v9.1 and prior, as "someone" felt it necessary to rename some
> fields in pg_stat_activity*
> *and remove/replace another field. Hopefully they will refrain from doing
> so in the future, as it breaks queries and applications.*
Changes will continue to be made between major versions of PostgreSQL
when they're deemed necessary; I'd suggest those applications be
prepared to adjust on a per-major-version basis when future changes
happen. We do have quite a bit of discussion about changes which are
made and they are not done so without good justification, but they can
and do happen.
Thanks!
Stephen
Attachments:
signature.asc (application/pgp-signature, 818B) download
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, melvin6925@gmail.com, eno@open-lab.org
Subject: Re: SELECT .. FOR UPDATE: find out who locked a row
In-Reply-To: <20180316021411.GX2416@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> <20180316021411.GX2416@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