From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Thomas Kellerer <shammat@gmx.net>
To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: How to drop a subscription inside a stored procedure?
Date: Fri, 10 Jun 2022 07:58:07 -0700
Message-ID: <df9a3d36-25a4-d8a4-ae4c-8f2b6f6e49a9@aklaver.com> (raw)
In-Reply-To: <3918eb37-2971-401f-4697-a716105cbcb1@gmx.net>
References: <3918eb37-2971-401f-4697-a716105cbcb1@gmx.net>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: adrian.klaver@aklaver.com, shammat@gmx.net
Subject: Re: How to drop a subscription inside a stored procedure?
In-Reply-To: <df9a3d36-25a4-d8a4-ae4c-8f2b6f6e49a9@aklaver.com>
References: <3918eb37-2971-401f-4697-a716105cbcb1@gmx.net> <df9a3d36-25a4-d8a4-ae4c-8f2b6f6e49a9@aklaver.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox