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 1lOhrl-00017f-Sj for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Mar 2021 14:18:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lOhrk-0007rY-Nz for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Mar 2021 14:18:40 +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 1lOhrj-0007qj-NB for pgsql-hackers@lists.postgresql.org; Tue, 23 Mar 2021 14:18:40 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lOhrd-0003Bi-Fw for pgsql-hackers@lists.postgresql.org; Tue, 23 Mar 2021 14:18:38 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 58B3711C1; Tue, 23 Mar 2021 10:18:31 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Tue, 23 Mar 2021 10:18:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=FBMs7HS5xmSG+FMiMnL3ZSqHqsvPs+HAXleTIojzL1c=; b=Ug+PaXUs aWU/qsOjiu6lJmR0dEsPI32AGlalQkmIlWNJY4LJJ3wyu+TfMpXlqFbENB4Ipn+M To2qBNzGb6gbhhwQdWwfyLwojOE3ZtWKES6kIm70jCgvqcgD5OgbN/cuw5ZpBcn+ cdfrdfvMOY+HMJ80+0dPKHvRTdVG7a+2y44FegpwjuVSbIoYYSZxoa1BO5Cc4Q/N rEHO8cwYotQjeYlNG/4A8QlADmjMSXoEB9ybS5S33repHm2fMTtg7aAyOVhw2jDm qItJpWA5loixqZ7MYjqwJaNUPlxz88EZEMphqfOXJdfBengWJjtg1gJURZK5yeJ1 ZiG1CJQPdBBOyA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudegiedgieefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfggtggugfgjfgesthekredttderudenucfhrhhomheptehlvhgr rhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh eqnecuggftrfgrthhtvghrnhepueffhfejieeuueffgedvudekgeeltdeviedvieeufeei ieevgfetheeufeethedvnecukfhppeduledtrdelhedrudelrdelheenucevlhhushhtvg hrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhvhhgvrhhrvgesrghl vhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Received: from perhan.alvh.no-ip.org (unknown [190.95.19.95]) by mail.messagingengine.com (Postfix) with ESMTPA id A8451108005C; Tue, 23 Mar 2021 10:18:29 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id CC7232A0FC3; Tue, 23 Mar 2021 11:18:26 -0300 (-03) Date: Tue, 23 Mar 2021 11:18:26 -0300 From: Alvaro Herrera To: Justin Pryzby Cc: Amit Langote , pgsql-hackers@lists.postgresql.org Subject: Re: ALTER TABLE .. DETACH PARTITION CONCURRENTLY Message-ID: <20210323141826.GA26281@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210321191519.GA4146@telsasoft.com> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk So I was about ready to get these patches pushed, when I noticed that in REPEATABLE READ isolation mode it is possible to insert rows violating an FK referencing the partition that is being detached. I'm not sure what is a good solution to this problem. The problem goes like this: /* setup */ drop table if exists d4_primary, d4_primary1, d4_fk; create table d4_primary (a int primary key) partition by list (a); create table d4_primary1 partition of d4_primary for values in (1); insert into d4_primary values (1); create table d4_fk (a int references d4_primary); /* session 1 */ begin isolation level repeatable read; select * from d4_primary; /* session 2 */ alter table d4_primary detach partition d4_primary1 concurrently; -- blocks -- Cancel wait: Ctrl-c /* session 1 */ insert into d4_fk values (1); commit; At this point, d4_fk contains the value (1) which is not present in d4_primary. This doesn't happen in READ COMMITTED mode; the INSERT at the final step fails with "insert or update in table f4_fk violates the foreign key", which is what I expected to happen here too. I had the idea that the RI code, in REPEATABLE READ mode, used a different snapshot for the RI queries than the transaction snapshot. Maybe I'm wrong about that. I'm looking into that now. -- Álvaro Herrera Valdivia, Chile "Cuando mañana llegue pelearemos segun lo que mañana exija" (Mowgli)