Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lodSX-00047g-B5 for pgsql-general@arkaria.postgresql.org; Thu, 03 Jun 2021 02:51:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lodSW-0000A6-A9 for pgsql-general@arkaria.postgresql.org; Thu, 03 Jun 2021 02:51:48 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lodSW-00009y-0k for pgsql-general@lists.postgresql.org; Thu, 03 Jun 2021 02:51:48 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lodSP-000714-Ki for pgsql-general@lists.postgresql.org; Thu, 03 Jun 2021 02:51:47 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 1532pd3f242821; Wed, 2 Jun 2021 22:51:39 -0400 From: Tom Lane To: gerry gan cc: pgsql-general@lists.postgresql.org Subject: Re: Is consistent (deterministic) ordering possible in our case? In-reply-to: References: Comments: In-reply-to gerry gan message dated "Thu, 03 Jun 2021 09:34:46 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <242819.1622688699.1@sss.pgh.pa.us> Date: Wed, 02 Jun 2021 22:51:39 -0400 Message-ID: <242820.1622688699@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk gerry gan writes: > Thanks for the comments! I have a naive question related to the use of > advisory lock. Based on my current reasoning about our scenario, consistent > ordering of commands in two transactions might not help to solve the > deadlock situation. If advisory lock is used, it can return false in case > it cannot get lock on certain row. This, however, might occur in both > transactions. Then it seems to be hard to continue from application side > since the operation is, by any means, required by application logic. In > other words, I guess this might cause 'deadlock' in applications. Do you > have any suggestions to solve this situation? And I'm sorry if my question > is naive. Thank you! A common answer to this sort of problem is to be willing to retry transactions after deadlock failures. If the deadlocks are common, maybe this won't be workable from a performance standpoint. But if they're rare, or you can tweak things to make them so, think about it. Retries can be a lot simpler, more robust, and even more performant than trying to get to a provably-deadlock-free implementation. regards, tom lane