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 1nSMkC-0002o7-Sh for pgsql-general@arkaria.postgresql.org; Thu, 10 Mar 2022 17:38:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nSMkA-0000KM-VB for pgsql-general@arkaria.postgresql.org; Thu, 10 Mar 2022 17:38:30 +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 1nSMkA-0000KD-Ki for pgsql-general@lists.postgresql.org; Thu, 10 Mar 2022 17:38:30 +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 1nSMk8-0002cr-Em for pgsql-general@postgresql.org; Thu, 10 Mar 2022 17:38:29 +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 22AHcRDM658815; Thu, 10 Mar 2022 12:38:27 -0500 From: Tom Lane To: George Woodring cc: pgsql-general Subject: Re: foreign key on delete cascade order? In-reply-to: References: <649664.1646927803@sss.pgh.pa.us> Comments: In-reply-to George Woodring message dated "Thu, 10 Mar 2022 12:32:21 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <658813.1646933907.1@sss.pgh.pa.us> Date: Thu, 10 Mar 2022 12:38:27 -0500 Message-ID: <658814.1646933907@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk George Woodring writes: > I have always thought the way to avoid deadlocks was to update rows in the > same order by the different updaters. Is there a better chain of thought > for updating and deleting rows at the same time? Do we need to put a lock > on the table to update, then have the delete queue up waiting for the lock > to be removed? With the amount of detail you've provided (viz: none), it's impossible for anyone to guess what your problem actually is, let alone speculate on suitable solutions. regards, tom lane