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 1nzg5f-0002ZH-Ty for pgsql-general@arkaria.postgresql.org; Fri, 10 Jun 2022 14:58:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nzg5d-0003Z9-Pu for pgsql-general@arkaria.postgresql.org; Fri, 10 Jun 2022 14:58:21 +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 1nzg5b-0003Yh-VI for pgsql-general@lists.postgresql.org; Fri, 10 Jun 2022 14:58:21 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nzg5W-0006GQ-L2 for pgsql-general@lists.postgresql.org; Fri, 10 Jun 2022 14:58:19 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 4460D32009AB; Fri, 10 Jun 2022 10:58:10 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Fri, 10 Jun 2022 10:58:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1654873089; x= 1654959489; bh=9ijFEfAueDYIwR5ugQY1cHj2tIF84V8srbLURwTckkI=; b=S zQmYwhmt/xFYA0iI2rWVWugus3M9JNXVgki7rOWCFfDLds2PXXfmG+QGFUuiXquz 8/d0IsNK8DdVYFMJZ9xUGnBggWzmPScC4Whead88hd7iqn7mYickBsENBl3gRFma EvFdH2k+toXFjbgLUAJqppy9IeVb2AB8vfVwciKop6sqSqIIOEOZVYfBNTF0QBBZ vVCAyVbpDHFySb1IpGrEdytrIncQLC3nDXheEtvho5OqtRoufBEoliY7MBIiOCzQ EnqxMvtF62b5IV5TpLiOUJJ/l9jgYh+Lp5nqp2QQZ8IzCFtGHDxMxdI0UDdT29VD vJX33UYVkdoYNlgxW/zKQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:feedback-id:feedback-id:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1654873089; x=1654959489; bh=9 ijFEfAueDYIwR5ugQY1cHj2tIF84V8srbLURwTckkI=; b=C8niAJ5E7CNFv3YX2 KHa6FWHNkes92aC1Yc6ytYFVaiAHwG/qQmuC0lUfcoy9qrFhFHFkgRYl7JjApFvb 3pIiO1vS3RpQP6SXHGeHjam1N+WnOHAjLdH6mXqtUOmQssg5aYKmCZqTKmcyVXBo h6zH4ldd/3PB5H9qyJ6WK62pvw7Btjg/a1dLhvhnPcMpAQKMRO1byWI5Ue1HSofT cqfW5+F3BEPB3kh0DSJG2h+skpbZB6QM6GsHoHihT+hNpzJD9lunuVQvUlyUrxtO 8oQBGm76jWo5mTkeP4Pg8HkMVLfLJNMSKwVNNxr7gekJcvrUeG+paGW9idVgYz8T Kirgw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrudduuddgkeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefkffggfgfuvfhfhfgjtgfgsehtje ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepffduhedtud eggfekveduffehveevhfeftedthfeviedvgfeigefhieeugefggfegnecuffhomhgrihhn pehpohhsthhgrhgvshhqlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrh grmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgt ohhm X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 10 Jun 2022 10:58:08 -0400 (EDT) Message-ID: Date: Fri, 10 Jun 2022 07:58:07 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: How to drop a subscription inside a stored procedure? Content-Language: en-US To: Thomas Kellerer , "pgsql-general@lists.postgresql.org" References: <3918eb37-2971-401f-4697-a716105cbcb1@gmx.net> From: Adrian Klaver In-Reply-To: <3918eb37-2971-401f-4697-a716105cbcb1@gmx.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 6/10/22 05:57, Thomas Kellerer wrote: > I am trying to write a stored procedure (Postgres 13) to enable > non-superusers to re-create a subscription. > > However, the "drop subscription" part results in this error: > > ERROR: DROP SUBSCRIPTION cannot be executed from a function > CONTEXT: SQL statement "drop subscription if exists my_replication" > > I first thought that the initial SELECT to fetch all replicated tables, > starts an implicit transaction, so I removed everything else from the procedure, > including the dynamic SQL. > > But even this very simple implementation: > > create or replace procedure drop_subscription() > as > $$ > begin > drop subscription if exists test_subscription; > end; > $$ > security definer > language plpgsql; > > > fails with that error. > > Is there any way, I can provide a stored procedure to do this? From the docs: https://www.postgresql.org/docs/current/sql-dropsubscription.html "DROP SUBSCRIPTION cannot be executed inside a transaction block if the subscription is associated with a replication slot. (You can use ALTER SUBSCRIPTION to unset the slot.)" I have not tested but you might try the ALTER SUBSCRIPTION first, though note the caveats here: https://www.postgresql.org/docs/current/sql-altersubscription.html > > Regards > Thomas > > -- Adrian Klaver adrian.klaver@aklaver.com