Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZKjf5-0004Oq-9l for pgsql-bugs@arkaria.postgresql.org; Thu, 30 Jul 2015 08:57:59 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZKjf4-0003E3-Ro for pgsql-bugs@arkaria.postgresql.org; Thu, 30 Jul 2015 08:57:58 +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.84) (envelope-from ) id 1ZKjeS-0002Eb-8z for pgsql-bugs@postgresql.org; Thu, 30 Jul 2015 08:57:20 +0000 Received: from douglastechnology.co.uk ([109.169.21.47] helo=mail.douglastechnology.co.uk) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1ZKjeP-0004JY-Q5 for pgsql-bugs@postgresql.org; Thu, 30 Jul 2015 08:57:19 +0000 Received: from redditch (unknown [95.154.250.181]) by mail.douglastechnology.co.uk (Postfix) with ESMTPSA id 413804002AB92; Thu, 30 Jul 2015 09:57:13 +0100 (BST) From: "Jack Douglas" To: "'Andres Freund'" Cc: References: <20150728162823.25043.27625@wrigleys.postgresql.org> <17665.1438105627@sss.pgh.pa.us> <015301d0caa0$f868f2f0$e93ad8d0$@douglastechnology.co.uk> <20150730083805.GA3161@alap3.anarazel.de> In-Reply-To: <20150730083805.GA3161@alap3.anarazel.de> Subject: Re: BUG #13523: Unexplained deadlocks (possible race condition) Date: Thu, 30 Jul 2015 09:57:11 +0100 Message-ID: <01b001d0caa5$b8ea93e0$2abfbba0$@douglastechnology.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 15.0 Thread-Index: AQGcf0xE18AKTxoNJZtQsHxZmHenRQIzy08OAwiSiZYCLLbpewHEplaL Content-Language: en-gb X-Pg-Spam-Score: -3.3 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org > I don't think that'd help at all? The problem here is the lock upgrade from RowExclusiveLock to the exclusive lock, and that'll not be fixed by that proposal? The problem is that the RowExclusiveLock is being aquired in one session before the Exclusive lock, even though the LOCK TABLE statement is physically first in the SQL function. Because the locks are being acquired out-of-order, deadlocks become possible as another session tries to escalate the lock and waits, then the first session tries to escalate it's own lock and deadlocks. Normally this is prevented by acquiring the most restrictive lock first, but with a SQL-language function (unlike plpgsql for example) this is not possible. This is how I understand Tom's initial reply, is that not right? -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs