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 1ewetL-00021w-K4 for pgsql-general@arkaria.postgresql.org; Fri, 16 Mar 2018 02:14:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ewetK-0002CS-0x for pgsql-general@arkaria.postgresql.org; Fri, 16 Mar 2018 02:14:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ewesq-0007TF-EA for pgsql-general@lists.postgresql.org; Fri, 16 Mar 2018 02:14:16 +0000 Received: from tamriel.snowman.net ([96.255.250.162]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ewesm-0003hy-Of for pgsql-general@lists.postgresql.org; Fri, 16 Mar 2018 02:14:15 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id 84A9B5F79C; Thu, 15 Mar 2018 22:14:11 -0400 (EDT) Date: Thu, 15 Mar 2018 22:14:11 -0400 From: Stephen Frost To: Melvin Davidson Cc: Enrico Thierbach , "pgsql-generallists.postgresql.org" Subject: Re: SELECT .. FOR UPDATE: find out who locked a row Message-ID: <20180316021411.GX2416@tamriel.snowman.net> References: <20180315204851.GU2416@tamriel.snowman.net> <206B6740-DCC5-4491-A87D-EEF5CBF8EA6B@open-lab.org> <20180315220512.GV2416@tamriel.snowman.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="pJRRd3X7WdrfkNOA" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --pJRRd3X7WdrfkNOA Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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. >=20 > *FWIW, I really don't understand your need to identify the actual rows th= at > 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 --pJRRd3X7WdrfkNOA Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJaqyhzAAoJEO1sijiDR2RV+ZQQAJyV7KM9muot4dljoeLIbRJu g9sWMs33ccv7u/uPjkNFTJX4mt3ozjRc8chj2hnGncGH5nL9JXsfJJsC5doymAD7 4fNjX3cI3ueMKsKH+E3Pv6bi9v4UWvrM8kN2gwqPTNC8DQ9wYjsWCyjg4JtZmOW5 NsxOwkJNUvkE0D26PwTH1x52MANUduUvGZOUx6IG2QzqRphydGgqxhkIHMDc43fV 3irN90HB03GKrnYtuerijLXrZAZeDTVW0CtAAKQrcU0u6py25skYChZUPodoqR1M BRDu/FAJ00yVvcZrhq8tqZcJEJvVfhOZNUBATiJqws4DTZN5SSbIJVNil7nnOeda sBaBwHleL0vSWeSbi31E4QGoqZUxuKyOZla/5gFiineX0DmkLvctwCD4uDB+jkuQ foPIY88MC4Wp57UBiJboEOxtAagfCgriSujx0/5y8WDK4YtgMMxffaFFPfpzbe9q P/ukCFR72ouXyBOm93fSrchK6ULfhsOp/klpNKEpfk/USAZeSzKFK76TSKJRKKrz eT2/CGsh5ZJ7b4rD7tDNn0XHadVWcM7SAJLKSbDA5zDiHGDZKue72seD7dYzBk+i JhsoMMdeft2Qa89HoH79OFjsMOpFw58tr4ZMj8cG0fwcrPw4CBJzsfhup7g0HShL ZBaRKUY5MaxpZl+UHHPN =zZ1j -----END PGP SIGNATURE----- --pJRRd3X7WdrfkNOA--