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 1nzeEB-00069y-Bh for pgsql-general@arkaria.postgresql.org; Fri, 10 Jun 2022 12:59:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nzeDA-0005ZQ-F0 for pgsql-general@arkaria.postgresql.org; Fri, 10 Jun 2022 12:58:00 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nzeDA-0005ZH-3b for pgsql-general@lists.postgresql.org; Fri, 10 Jun 2022 12:58:00 +0000 Received: from mout.gmx.net ([212.227.17.22]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nzeD7-0001xV-FP for pgsql-general@lists.postgresql.org; Fri, 10 Jun 2022 12:57:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1654865874; bh=V7rEW4GnMVt0Nuwvp8nzgpRLDBJLnKuxXR+lo0JGGz8=; h=X-UI-Sender-Class:To:From:Subject:Date; b=NJcx8pE0MJ+1KnuB6y3Ag9m3iAfpz9f/vmRrquTXL/clWZwT3ELukuEGekdmRFVIO u+UM4cZCPhOlcl5HlXD+HyABJ9/LVEchcrQel3mn+h9mvnfk2gHOLbLbuNMFAEQxq5 eqgCKCFm8fnCHMH3K6ZvA+ik+i4wMQrHxQB5c6Ok= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [10.1.33.252] ([185.40.248.10]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MSKy8-1oAfl42Q0G-00SfMb for ; Fri, 10 Jun 2022 14:57:54 +0200 To: "pgsql-general@lists.postgresql.org" From: Thomas Kellerer Subject: How to drop a subscription inside a stored procedure? Message-ID: <3918eb37-2971-401f-4697-a716105cbcb1@gmx.net> Date: Fri, 10 Jun 2022 14:57:53 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: de-DE Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:uTIwbUdU5gCtFZiU5UMuFRA59liHpmqS6RYPL8HrCroYGJzpWus 99OIQsqumRHrDEu8H/btC0rFX9HuJdyZ7cedCT+6uzBq6mQGSN/9pqBtwdeRzpi/VxYYyIp K0Dnfx7x5YsfO1X7WdkanN+dPZgMfjHVE7YuaVi9oP2+0ToECd4CPuBQfpZXzN8qU85qZsN K8CMWMZprzw42l+qDoSQA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:kXPJ+Nxe0XI=:xWuGakqaYUaGehzhm8nbyU SDE+dtXiWPQT7RFU3bmeZKAdwk+oQU1V1GKrGvG5waxemso62pjKGptDpwGQ/y1Y38+15Z9+5 6RVaoffVv0mOLNNeyLYrsqw6efPQhsVKTzg5MH7IIe4kDj5/1jZRgEaEft0BCxOZj706+62AP YWEpjMae0UmXMAVV+PWUNqFPlByLJ02M8VX7lvNUV9dsvDISZKYXb4XHLxdoEe9ZjwL7SfYlr XdmVGZKVQNmvYXWezQV1/FzUhrVtdd+zgEQ4Cl5MZXkFJlVJ+fLWQpEAli9nwYu2SkGPr3p82 WkU8N61nsxdJtwxtteBce/606lw10pXtE31YFSHtkDW4h1/8pLHYsp/Qw4tzZYPv9o2rHHI8f O7zJaBpt/17a1s/svZrgx3kH+elJrzeUG4VYAmKbqJc0ijwytPHnrKiy5Tj5VlTozCQM0T+JD 0PzYCmrvZCk++BCXrx9PihfSgoW10uuc7ndAgAtvdv6KxFwYWnXnblkhOU1ly5FZhpJo5iIM4 xvCXDxryaM0c0eFStibcy3wOq/O171ylYCZIHvJU9PrI9+IJL71dDEn5tMtjQXFMSSYjsjI1Y 0TeDtF3VIxdh868f5ggYbhd04O7ZevMiXfFc1W3FaOc75+3duKQvO+f7hefzozR6BoxlU3tjG OFtgp83y9QOjdldtfcA+ASyOQ8bsZ8GDkPQdzwbYTIU6Hwh4PGB/mSE3iFwqTruNQhUfKNQVx jbUNaqFR29lrzo1XhJQQncn4t++HPACdIZpfNC6BShTCvHVpAx5r4PMKsuxuMyI0jPmmavg5Y 5rY201aFSj9KmMuOsRkJjAN7QIj74kCsSbsWbZ0UIA6teJComkJZvn/Z0HmCS29mQ/wPCSR+k WNJgljayFJXhIdDy5pFB8t3OnBOhvEqTtLOw+on92XB0TLm0vSRMT21hNRuqMWrufxc5lQ+Bm cfOau61gF4v8bJqE9sZHR4zMUaQiI0bydhFAiQZkUIp/2x0pWtKltD2oGpC5dg7WKFhQKqIpi nmysDCrlmS07+Fro7uo07xCH4hDTHc2sav3pyPNrEoAo7+9xkC22ajdDyocrgaMdmaE3MBjun mQG1/9dXX4cXLCZr5xjVl2mlujTOpbS+97EGosgzWpFU7Wbpbap9c2Arw== List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I am trying to write a stored procedure (Postgres 13) to enable non-superusers to re-create a subscription. For that, I essentially want to drop and re-create the subscription. In order to be able to do that, the tables need to be empty. So the approach is: Run a query to get all replicated tables, store this in an array. Run "drop subscription ..." Truncate all tables Run "create 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 proc= edure, 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? Regards Thomas