Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ewqw1-00046I-Bf for pgsql-general@arkaria.postgresql.org; Fri, 16 Mar 2018 15:06:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ewqw0-0001zf-5R for pgsql-general@arkaria.postgresql.org; Fri, 16 Mar 2018 15:06:20 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ewqvz-0001zU-QG for pgsql-general@lists.postgresql.org; Fri, 16 Mar 2018 15:06:19 +0000 Received: from tamriel.snowman.net ([2001:470:e38f::11]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ewqvr-0006aF-OY for pgsql-general@lists.postgresql.org; Fri, 16 Mar 2018 15:06:18 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id 43D795F79C; Fri, 16 Mar 2018 11:06:11 -0400 (EDT) Date: Fri, 16 Mar 2018 11:06:11 -0400 From: Stephen Frost To: Enrico Thierbach Cc: Melvin Davidson , "pgsql-generallists.postgresql.org" Subject: Re: SELECT .. FOR UPDATE: find out who locked a row Message-ID: <20180316150611.GJ2416@tamriel.snowman.net> References: <20180315204851.GU2416@tamriel.snowman.net> <206B6740-DCC5-4491-A87D-EEF5CBF8EA6B@open-lab.org> <20180315220512.GV2416@tamriel.snowman.net> <0678E648-BF9E-410D-9EA8-B2D914A6AFFF@open-lab.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="dd98MptxfTW1zh1x" Content-Disposition: inline In-Reply-To: <0678E648-BF9E-410D-9EA8-B2D914A6AFFF@open-lab.org> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --dd98MptxfTW1zh1x Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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.* >=20 > The goal is to run a job queue, with a potentially largish number of work= ers > that feed of the queue. So it would be useful to find out which queue ent= ry > 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 intent= ion > is NOT to kill the worker or its query. >=20 > With what the conversation brought up here (still trying to catch up with > everything) I can: >=20 > 1) determine all workers that currently are holding a lock (via Melvin=E2= =80=99s); > 2) on an individual base try to lock the row in a second connection and u= se > a third connection to figure out which worker connection holds a lock on a > specific single row (via Stephen=E2=80=99s). >=20 > This is probably good enough to cover the necessary basic functionality, = so > thank you for your input. >=20 > 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 o= ne > 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.snowm= an.net > (I guess I am also correct to assume that whatever the worker is doing th= ere > is no way to somehow write this information into the database **via the s= ame > 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 =66rom within a stored procedure or similar. Thanks! Stephen --dd98MptxfTW1zh1x Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJaq91iAAoJEO1sijiDR2RVMdsQAIUsiN2dpvqSfKHKui7btPC5 +eNKWsDB38cw0s7/nGyy4FR8WwOBqJWFlQLUUCWGXzSGrU60YksXQOoUu7Ui/T3v OHFY3ZhF0dNL7Zrsc2eNGypQ1c26o8TzG5BrqM5W03mbVEpK26hBgcQD/4dTE0Wq gosG+Ma1EjgyNq8sx4KnwuNcqO+qLc0p1PL0/20+eNkZnNymLNw4ndF4VbgBNJM/ HGbMCl99y3J6sNCykXSjcGjdEBoOG/gJT8/h+jPHnHlm7XuA6ahA9LKgHIM5w6Qu DIXw88NUKejo9e8MDbq9IGTy0qJsx3m8nMcTL27gekcWXhnzfuTBRiVCVlj5NxFM yYl8ruel4Par5MK34ZsVXGan64GoqZHSZU95Adb0lq1cym+rTuGAjmgfwZcqdKZ/ uMmEFQpbZ48qgbLnnEL/se9BVD5Ez+rawoLhGRsMX+Xq6tnsu5z3pUUnH2OjXa8I ttr68b4H4Q5st/JE6UHNcSmd6wcr/GDMww4nhWkbRn2EZN96QzKNmK3p825wbr2n MYMtDDgXCaR68JolNtnU2g7I45BuB3Bjgpov1pHgyiHSqSPTnxEUCNF2agbpO225 CRP5ScsVn/6nKmBmO/ZsKQ2lYeEqWJRbOKv0WRi08zDmPkKQfs7i8L66NV636agI C/lTBWIcIKKAMOr4NONn =7qfN -----END PGP SIGNATURE----- --dd98MptxfTW1zh1x--