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 1lHDVy-0000Dn-Aq for pgsql-general@arkaria.postgresql.org; Tue, 02 Mar 2021 22:29:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lHDVx-0008TY-8D for pgsql-general@arkaria.postgresql.org; Tue, 02 Mar 2021 22:29:13 +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 1lHDVw-0008TR-As for pgsql-general@lists.postgresql.org; Tue, 02 Mar 2021 22:29:13 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lHDVn-00053w-II for pgsql-general@postgresql.org; Tue, 02 Mar 2021 22:29:10 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 5102716E9; Tue, 2 Mar 2021 17:29:00 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Tue, 02 Mar 2021 17:29:00 -0500 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=saQNLR+1pjGJD951i4WjaDu1ovxjYCDVpaJ/s828UQE=; b=VRnHxcBr Besp7EKZCEZdDCX+L8ggp1w+UmVjF5+xW+La4026Wu6VMQlhdzCp2/zH/6WSTO2R SE1gTKQ58Rc2VW/Z/xg8WyS67//bsngWB7V68QHQrfubBwKS1TImHrJVt4SscR+q FmiheOOtDK59IPw/nEQ/0lXAPL/wFloA851dZbty1uv5h7vEsj1Dwa0gz3sms33U DJlk3m8opPyXsnUEtXg5RG/Dhaw3rE/lF5hbRVMB8VBp6Kk153YL5wAvlIReFjxM Nt4AQ9LCygdUW7lVnd4zR/1Jh2kwQKmpIWeYaYdV/gfTLFg8f1bF3nGxtK4Stz8g pkYYYfdBa/Rknw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledruddttddgudehudcutefuodetggdotefrod 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 5B5D6108005C; Tue, 2 Mar 2021 17:28:59 -0500 (EST) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 700902A14F6; Tue, 2 Mar 2021 19:28:56 -0300 (-03) Date: Tue, 2 Mar 2021 19:28:56 -0300 From: Alvaro Herrera To: Asaf Flescher Cc: pgsql-general@postgresql.org Subject: Re: Locks in creating a partition in CREATE TABLE vs ALTER TABLE Message-ID: <20210302222856.GA16038@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) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2021-Mar-02, Asaf Flescher wrote: > I'm not sure if this is a bug or I'm missing something regarding how > partitioning is supposed to work but I've noticed (in Postgres 12.6) that > if I have a partitioned table, and then try to add a partition to it via > CREATE TABLE ... PARTITION OF, the statement will grab an AccessExclusive > lock on the partitioned table. Meanwhile, if I create that same table > normally, then attach it to the partitioned table via ALTER table - no > AccessExclusive lock. It's a new feature in Postgres 12 actually -- we went great lengths to be able to do ALTER TABLE .. ATTACH PARTITION without a full AccessExclusive lock. However, it's just not possible to do the same for CREATE TABLE .. PARTITION AS. If you try the same in Postgres 11, you'll notice that both use an AccessExclusive lock. -- Álvaro Herrera Valdivia, Chile Syntax error: function hell() needs an argument. Please choose what hell you want to involve.