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 1nzlGW-0007pK-CG for pgsql-general@arkaria.postgresql.org; Fri, 10 Jun 2022 20:29:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nzlGV-0002tC-3D for pgsql-general@arkaria.postgresql.org; Fri, 10 Jun 2022 20:29:55 +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 1nzlGU-0002r2-Ni for pgsql-general@lists.postgresql.org; Fri, 10 Jun 2022 20:29:54 +0000 Received: from mout.gmx.net ([212.227.17.20]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nzlGN-0000T8-5y for pgsql-general@lists.postgresql.org; Fri, 10 Jun 2022 20:29:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1654892983; bh=FrT+pBem8ix1AwKDrMjMHSbnfo9zRmBWDK5ll6scDdU=; h=X-UI-Sender-Class:Subject:To:References:From:Date:In-Reply-To; b=b8X9vmpTvbWL/RxX52U98J/KGJ+f8RerLlilRzD/W/9WsvGi8FtwkifZDPsX7uIzG 6bSFzeWCBaNyFlVnjns8VxSsdVqUj30Imqvjl0o+ysjthEiedAP4pnuSndSE48yAEM YXar7Ojbja+0bt/YtHZckpauCDeV3lTDtP1LPWvo= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.178.20] ([83.171.169.82]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MVeI8-1o9hQZ15gi-00Rbqt; Fri, 10 Jun 2022 22:29:43 +0200 Subject: Re: How to drop a subscription inside a stored procedure? To: Adrian Klaver , "pgsql-general@lists.postgresql.org" References: <3918eb37-2971-401f-4697-a716105cbcb1@gmx.net> From: Thomas Kellerer Message-ID: <76f2c021-1703-d6d1-39ac-e2d8d415234c@gmx.net> Date: Fri, 10 Jun 2022 22:29:42 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.21) Gecko/20090302 Thunderbird/2.0.0.21 Mnenhy/0.7.5.666 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: de-DE Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:X73aRQkwF4nAp2MIJIrPSjkA/6MxuCzVPkZ9g6pWRqo7mabLAkH QsnXHx0G12ROJiQH9i9S+w6w8yEtt+gqFmspg6m9Qsq0C4ZWRArtaB1yu6FnO8/7s2h1EpK 17Te/biAl3mGuLUJlSOcOInbADKu6JFbT+sZSkyCbUCblYnGOyohQsioHg7SUdJ1mDUWXGE i4FpXdywW3nf5leri6b1g== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:larad6npU5E=:oVa8bU1yUlL+oMLhwPd/ya ysKutF0FGf27lvssDK5KV40Q+eOFPuHnWvtvzQ7lzIy+0yht21eAtK5wJgFvf43fy930GYry6 1OKelfleYYxd328n7GBekbDm85Hs+QsmtYVqT/xhVPOWN7hmnp5IBPLbaw727MkZCF5zcIjqJ Xh0S9F8YtBgEgbdeIRKA/QgMXKbUQjFvZaTnC0kMI+ZwWQ6so3Sfp74+Zn+jHhqFnwiHNDxZQ BGEW+pXewtG/6MAQ0PTMiUA/W25Z0S2DQnU7PoIbtnocvCRZ5zdvPkx6YUyshu/3suzwyyrik 1dkvd6oWDL00VjMw15NT07OPj/erUKdlt6ByTXGM2YAhRfw2mohyJC6Mq6jTmjGiEXXX0IJAi fW7lvo+33GrXMSihRYjSAGynCO9F1UEcGp/QclYg3TL9QjE974E3N8J7U25TvtWfgr5n5x3NB uu/5QJBDwlfWBicdbsBX/IbXWNAlecpiFKQnczxJSQMe8XKuIUgFBoOc+kXd1a/0Uf0TQN1km w+oC64SeTnzkA/LYyYSvsYDuXk4iP4hA9/8jClhsaNj+JCUJrqvYztK1vLieY0TgV5nqDZPQS L54DKK+26jY8ayBeyuwJLGcWOI5lEFM7vBP2MDb1rMUx0MGowcWLeiwU+FuYUVB3lMyOsrtSj SDcCsOJnldkDPyxB5ZE/X7Ug0U7eAshwsT9fm3sDuECGB8et+xzMirAExuLDTjLjaCoOVVIkl Y9DzQxM+csHRQwEVd8Alym80C0YuvDGLz2yTeUZkLR0pX6W0xFBYj68KXplI9rA3Mi8JlB+Ow RZQkHXU0vjiIbLL4WBjHlBFHOzguJyR0hYe95tG/4F19T3uz6dVH+WAwGGrF521VBjEDwKJBw VILnejutLUnaXtO5YQDj6YZbFV8geqQ5fP/pYzglLxmnJfQktogwTxYAVOs/FwJBChM+Si/Vr DANsrJGyfnx0Wk/S0+t0XliUc0g81A7TJ/Xh1GLEqDeffFMIU5NjqQpf0/B/+/qGouJR2OXOF 5UZ0m6nKnfZ7EUnHdVbxpa2ZzOKXVRfhpBK/CZ7BhrPUlNqDQYWGmbkuoCwWJsOOnUmlJ8UP/ CetLpEp2EPHK6U9utyGgiNk0IbIxfE21Yj7iJ+P5J23rg03oWKVihiQGg== List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Adrian Klaver schrieb am 10.06.2022 um 16:58: > 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: >> >> =C2=A0=C2=A0=C2=A0=C2=A0 ERROR:=C2=A0 DROP SUBSCRIPTION cannot be execu= ted from a function >> =C2=A0=C2=A0=C2=A0=C2=A0 CONTEXT:=C2=A0 SQL statement "drop subscriptio= n if exists my_replication" >> > 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 SUB= SCRIPTION 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 Unsetting the slot works (after disabling the subscription), but then I ha= ve an "orphaned" slot on the publisher. I don't see a way how I could get rid of that replication slot from the su= bscriber side.