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 1lZzM5-0000K8-DO for pgsql-hackers@arkaria.postgresql.org; Fri, 23 Apr 2021 17:12:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lZzM4-0004dD-9H for pgsql-hackers@arkaria.postgresql.org; Fri, 23 Apr 2021 17:12:36 +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 1lZzM4-0004d6-2S for pgsql-hackers@lists.postgresql.org; Fri, 23 Apr 2021 17:12:36 +0000 Received: from [66.111.4.29] (helo=out5-smtp.messagingengine.com) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lZzM1-0000fb-SD for pgsql-hackers@lists.postgresql.org; Fri, 23 Apr 2021 17:12:35 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 9BAAF5C0143; Fri, 23 Apr 2021 13:12:22 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Fri, 23 Apr 2021 13:12:22 -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=KORzpGw6vkisGsegF22nv4TzmWifg8sOJ+0oL58hCdo=; b=oIGgXC8F PsaMBNPgpqcne+gw6Vl7es9o3txNkGXeerodS/+pEIh77Nvk2oMf+A+igjhgDW8Y OaBKWc5vN7XmafSHUtjs6OX7NYCjoOcxzr2N8SfW5iQ71ZM1JMESFQKfwQYYMt58 VGgtJsRmuXy+BofqJQ5dQNb6uBv8gN+qhUif3s4bSSpoeWC6fcBi8FURAZW7jMrk MfWS+Dc4PLgcQ1+0Ah8ZS2B1e5xA6B733mY6YmM7G9pMDwsL2/wNMsFPeCjcD2i0 4E1SzuX0UE1pieCSHs0ZKio0Rjp5VnhVhsgKt02CyAzowSRpk0liXwmYQipeKbT3 AMgGqWtHA6X4Nw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvdduvddguddtlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvuffkgggtugfgjggfsehtkeertddtredunecuhfhrohhmpeetlhhv rghrohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorh hgqeenucggtffrrghtthgvrhhnpeeufffhjeeiueeuffegvddukeegledtveeivdeiueef ieeivefgteehueefteehvdenucfkphepudeltddrleehrdduledrleehnecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghlvhhhvghrrhgvsegr lhhvhhdrnhhoqdhiphdrohhrgh X-ME-Proxy: Received: from perhan.alvh.no-ip.org (unknown [190.95.19.95]) by mail.messagingengine.com (Postfix) with ESMTPA id C77481080064; Fri, 23 Apr 2021 13:12:21 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 153982A0ADC; Fri, 23 Apr 2021 13:12:19 -0400 (-04) Date: Fri, 23 Apr 2021 13:12:19 -0400 From: Alvaro Herrera To: Amit Langote Cc: Justin Pryzby , Tom Lane , PostgreSQL Hackers Subject: Re: ALTER TABLE .. DETACH PARTITION CONCURRENTLY Message-ID: <20210423171219.GA26578@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Host-Lookup-Failed: Reverse DNS lookup failed for 66.111.4.29 (deferred) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2021-Apr-23, Amit Langote wrote: > Back in the 1st session: > > end; > insert into fk select generate_series(1, 10000); > INSERT 0 10000 > Time: 47400.792 ms (00:47.401) I guess I was wrong about that ... the example I tried didn't have 1000s of partitions, and I used debug print-outs to show when a new partdesc was being rebuilt, and only six were occurring. I'm not sure why my case behaves so differently from yours, but clearly from the timing this is not good. > I am afraid we may have to fix this in the code after all, because > there does not seem a good way to explain this away in the > documentation. Yeah, looking at this case, I agree that it needs a fix of some kind. > If I read correctly, you did try an approach of caching the > PartitionDesc that we currently don't, no? I think the patch I posted was too simple. I think a real fix requires us to keep track of exactly in what way the partdesc is outdated, so that we can compare to the current situation in deciding to use that partdesc or build a new one. For example, we could keep track of a list of OIDs of detached partitions (and it simplifies things a lot if allow only a single partition in this situation, because it's either zero OIDs or one OID); or we can save the Xmin of the pg_inherits tuple for the detached partition (and we can compare that Xmin to our current active snapshot and decide whether to use that partdesc or not). I'll experiment with this a little more and propose a patch later today. I don't think it's too much of a problem to state that you need to finalize one detach before you can do the next one. After all, with regular detach, you'd have the tables exclusively locked so you can't do them in parallel anyway. (It also increases the chances that people will finalize detach operations that went unnoticed.) -- Álvaro Herrera 39°49'30"S 73°17'W