Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s6z1h-002qle-Aa for pgsql-general@arkaria.postgresql.org; Tue, 14 May 2024 20:45:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1s6z1g-002v04-Dh for pgsql-general@arkaria.postgresql.org; Tue, 14 May 2024 20:45:32 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s6z1g-002uzw-0O for pgsql-general@lists.postgresql.org; Tue, 14 May 2024 20:45:32 +0000 Received: from wfout8-smtp.messagingengine.com ([64.147.123.151]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s6z1Z-000Dkb-1P for pgsql-general@lists.postgresql.org; Tue, 14 May 2024 20:45:30 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.west.internal (Postfix) with ESMTP id 959F51C00188; Tue, 14 May 2024 16:45:23 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Tue, 14 May 2024 16:45:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1715719523; x= 1715805923; bh=XkFQ6fiba3KvgMTnOgF7c1KdT7tr0pn7djWmltfD0eU=; b=M SynOm4q/XB621oNBIL/3DSGd1vd0j+IQXkrbUHTSp7uzjal4BdHbA9xffVFoqsbq +fIr7FUs4SVUvo1Mm5pLpvvFRlR9fjwX2XpZh/3EpHmX6FXWtBlWxCuHJR8F+rqp yUZVstPVreAf4v1RnxRAriYIi0c7jg5YIMP5TupOtMt7DfsmBDm5lKAE+j6lUIV2 Voy/+15MjSBa/hXexbPjqaT5Z+g7ZUy8OZduAzoNI6yIyQRQCaySsGTNM6i2HNEQ XdTiiodmRewElwftGGtxfRnKYQykC1anMpbfe0UI1EcJ2axjnZ/nZ6qWiX0eBWmH Tdpc+Fa/mvE9CwAX3z3Zw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegiedgudehudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfggtggugfgjsehtkeertddttdejnecuhfhrohhmpeetlhhv rghrohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorh hgqeenucggtffrrghtthgvrhhnpedvkedtffduffdtffffheffhfejjefhgfeiueeukeej keffgfdufffhudffffeuveenucffohhmrghinhepvghnthgvrhhprhhishgvuggsrdgtoh hmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghl vhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 14 May 2024 16:45:22 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1715719521; bh=gEz7ciBNc1fX8ycaNTFYe0bInaCNDK3GQUWyyZqWeMY=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=ZiSOXj6UcxYOb7F4zcxYhCWr0sG296spy1bldayg1dVrXH/r5PAWDX4MbjuBcvSSj MB3wvTnf/4UNqujdUl+3QFmiNr0iV5fM9mP4acaeE94CIrJetVIi5kc3RFvRUyg0Cy ygoExJsywG/I13R7Gbr7ExM+6rlhYI/xvy3qGK/MTqUO6ZD/4RZDFB5Tdxssm9aa5b Coj7IJ1TEyA24B2NTMwjWLeOyaYE8rWD/BCwp7bRSzEt5d+DUFnLu9LKP9Ysh2GGwo VZYyikmqYS8T5Ou9mGdHYKkm+e1QTqxbizziaGDmWEZAa1Rjy7HF7UMYSdAy4UAubK e2iBoRuydo5fw== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 6A0A710B; Tue, 14 May 2024 22:45:21 +0200 (CEST) Date: Tue, 14 May 2024 22:45:21 +0200 From: Alvaro Herrera To: "Dirschel, Steve" Cc: "pgsql-general@lists.postgresql.org" Subject: Re: Using ALTER TABLE DETACH PARTITION CONCURRENTLY inside a procedure Message-ID: <202405142045.avyazkmi6kq2@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2024-May-14, Dirschel, Steve wrote: > But when I try and run the command inside the procedure it throws this error: > > STATE: 25001 > MESSAGE: ALTER TABLE ... DETACH CONCURRENTLY cannot run inside a transaction block > CONTEXT: SQL statement "alter table t2.test1 detach partition t2.test1_gentime_20240511 concurrently" > PL/pgSQL function part.partition_maintenance() line 323 at EXECUTE Yeah, ouch. > The documentation states: > > CONCURRENTLY cannot be run in a transaction block and is not allowed if the partitioned table contains a default partition. Right. > Is there an option to call that CONCURRENTLY inside a procedure as I describe? Not at the moment. The issue is that CONCURRENTLY needs to commit a transaction internally and start a new one, and to ensure that works correctly we check that it's being executed as a "top-level command", which rules out procedures. It may be possible to relax that restriction when run inside procedures, given that procedures need transaction control of their own anyway so we could arrange for the right things to happen; but this is hypothetical and I don't know that anybody has attempted to implement that. -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/