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 1f5XCh-0007Es-8d for pgsql-general@arkaria.postgresql.org; Mon, 09 Apr 2018 13:51:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f5XCg-0004RN-1y for pgsql-general@arkaria.postgresql.org; Mon, 09 Apr 2018 13:51:26 +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 1f5XCf-0004RE-N8 for pgsql-general@lists.postgresql.org; Mon, 09 Apr 2018 13:51:25 +0000 Received: from tamriel.snowman.net ([2001:470:e38f::11]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f5XCc-0000HU-N5 for pgsql-general@lists.postgresql.org; Mon, 09 Apr 2018 13:51:24 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id CECAE5F79C; Mon, 9 Apr 2018 09:51:21 -0400 (EDT) Date: Mon, 9 Apr 2018 09:51:21 -0400 From: Stephen Frost To: Thomas Poty Cc: pgsql-general@lists.postgresql.org Subject: Re: algo for canceling a deadlocked transaction Message-ID: <20180409135121.GJ27724@tamriel.snowman.net> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="lPld9KzQhYxXHcUh" 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 --lPld9KzQhYxXHcUh Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Greetings, * Thomas Poty (thomas.poty@gmail.com) wrote: > My question is : In case of a deadlock between 2 transaction, how to know > which transaction will be canceled? Is it predictable? The short answer is "it's whichever one detected the deadlock." The deadlock timeout fires after a lock has been held that long and if a deadlock is detected then the process detecting it will be canceled. I'd strongly recommend reviewing your application and addressing deadlocks by changing how the application acquires locks to be consistent and to avoid lock escalation instead of worrying about how to predict a deadlock- a properly designed and written application shouldn't be causing deadlocks to happen in the first place. Thanks! Stephen --lPld9KzQhYxXHcUh Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJay2/ZAAoJEO1sijiDR2RVP/EP/17P0fBcSPHbgVRJqeaLYink 3+Neskel4Buga2VLZPii+21Bo/UuBsxkOUjYrZrBkQzZzBa269tLjk5grUoGIbV5 5J9MZNAk28C2g7Y8IWJJkT85BtMGciHxMh+SayYgxQ9y1BsMODFvb82GSu/SHM6L WBRm+kgVeM0E7OrV/xQextRbY64GS8NkJ5koDj1OJgnbBvDva2NLHHAT34oGd8x1 e/+evLbeWU32qd1Gak/JTFK9DBL4u20KlOWKx1lvqmcPjzWUtow5vtbDtk0zsQjT frCe4NI0rI8d9Q3J7wDZ60UCOqnM9HPKhENSkPKRZzK3gK1XN96j5rEmthHAScUR lMy7QTOFjXcgF4JSXGpFMoTLuYSqIDkrq27lsQrmb9XQs6X3Y5AWwADQHNaXi1PI cD0tPdDyGYrPVeIyMYxkFvbkIz01dt95de/8JLvQrWtNosq33F9pXzIGKIwrdvpE Bh/rbZhn58WSUyLoX8dojyYG/0jwixKMGYjnhV42NUcvbB2nyrr6qxGQNOaeJmb0 dCk1ja24QG11aoV0xpOHe1JayAQSZAmlEVKcwHGzXxb7Ss8y26JGEqQE1amV11ox K2Icpyuz8+Fi2WIfT8hPN6Lco5R5WkhlywAiq6tmGNvgzh5wDLv4X1hiczgH8tqz ch5im3PcPExYfZGAfr4w =u3S9 -----END PGP SIGNATURE----- --lPld9KzQhYxXHcUh--