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 1nHZgN-0005fB-K5 for pgsql-general@arkaria.postgresql.org; Tue, 08 Feb 2022 23:13:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nHZgM-0007Or-B2 for pgsql-general@arkaria.postgresql.org; Tue, 08 Feb 2022 23:13:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nHZgM-0007Ob-0Q for pgsql-general@lists.postgresql.org; Tue, 08 Feb 2022 23:13:58 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nHZgG-0005v6-P3 for pgsql-general@postgresql.org; Tue, 08 Feb 2022 23:13:57 +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 218NDnG71298507; Tue, 8 Feb 2022 18:13:50 -0500 From: Tom Lane To: Aaron Sipser cc: pgsql-general@postgresql.org Subject: Re: Locks on FK Tables From Partitioning In-reply-to: References: Comments: In-reply-to Aaron Sipser message dated "Tue, 08 Feb 2022 11:51:09 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1298505.1644362029.1@sss.pgh.pa.us> Date: Tue, 08 Feb 2022 18:13:49 -0500 Message-ID: <1298506.1644362029@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Aaron Sipser writes: > I am fairly confused about the locks generated by some partitioning code I > am using. The setup is that we have a partitioned table (call it P), and it > has a foreign key constraint to another table F. I'm trying to figure out > why when I add partitions to P, it seems that a lock is also taken on F. Addition of a foreign key constraint implies adding triggers to both sides of the FK. Adding a new partition also adds a child foreign key constraint, which I'm pretty sure requires its own trigger. So the F table is going to need whatever lock strength is involved in CREATE TRIGGER. I don't recall offhand what we use, but it would at least need to block operations that might fire such a trigger. regards, tom lane