Patch
Document that subscriptions cannot be extension members
- Branch
- master
- Risk
- 10
- Base commit
- 7fc2f0423320e02beb8c44b863f1827604c47c75
To apply it to a checkout of master at the base commit:
curl -s https://ai-annex.j-davis.com/api/v1/patches/01a1e750-4187-754c-b33c-5181999b0831 | jq -r .body | git am
From 4ff9ecbca721951186a1c6a6e6b0f3698815bc51 Mon Sep 17 00:00:00 2001
From: Claude <noreply@anthropic.com>
Date: Mon, 16 Nov 2026 18:19:17 -0800
Subject: [PATCH] Document that subscriptions cannot be extension members
An extension script may run CREATE SUBSCRIPTION (with connect = false
or create_slot = false, since the script runs inside a transaction),
but CreateSubscription() never records a dependency on the extension
being created, and ALTER EXTENSION ADD/DROP SUBSCRIPTION is rejected.
The subscription therefore survives DROP EXTENSION, and installing the
extension again fails with "subscription ... already exists".
This is the intended policy for objects stored in shared catalogs:
pg_subscription is shared, doDeletion() cannot drop a subscription,
and findDependentObjects() refuses to drop anything that an object in
a shared catalog depends on. The documentation describes this policy
but names only databases, roles, and tablespaces, so say explicitly
that subscriptions cannot be members and that DROP EXTENSION leaves
such objects in place.
While here, make ALTER EXTENSION ... DROP of an unsupported object
type say "cannot drop" rather than "cannot add", and add a test.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
---
doc/src/sgml/extend.sgml | 8 +++++---
src/backend/commands/extension.c | 10 +++++++++-
.../modules/test_pg_dump/expected/test_pg_dump.out | 2 ++
src/test/modules/test_pg_dump/sql/test_pg_dump.sql | 1 +
4 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/doc/src/sgml/extend.sgml b/doc/src/sgml/extend.sgml
index 63c5ec6d1eb..2bc8f97020a 100644
--- a/doc/src/sgml/extend.sgml
+++ b/doc/src/sgml/extend.sgml
@@ -606,9 +606,11 @@ RETURNS anycompatible AS ...
the description of <link linkend="sql-alterextension"><command>ALTER EXTENSION</command></link>. Notably, objects
that are database-cluster-wide, such as databases, roles, and tablespaces,
cannot be extension members since an extension is only known within one
- database. (Although an extension script is not prohibited from creating
- such objects, if it does so they will not be tracked as part of the
- extension.) Also notice that while a table can be a member of an
+ database. Subscriptions cannot be extension members either, even though
+ each one belongs to a single database. (Although an extension script is
+ not prohibited from creating such objects, if it does so they will not be
+ tracked as part of the extension, and <command>DROP EXTENSION</command>
+ will leave them in place.) Also notice that while a table can be a member of an
extension, its subsidiary objects such as indexes are not directly
considered members of the extension.
Another important point is that schemas can belong to extensions, but not
diff --git a/src/backend/commands/extension.c b/src/backend/commands/extension.c
index 35443dabecf..78fbef70b45 100644
--- a/src/backend/commands/extension.c
+++ b/src/backend/commands/extension.c
@@ -3926,6 +3926,12 @@ ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt,
ObjectAddress object;
Relation relation;
+ /*
+ * Reject object types that cannot be extension members. Databases,
+ * roles, tablespaces, and subscriptions live in shared catalogs and are
+ * not handled by the dependency machinery that DROP EXTENSION relies on;
+ * the others are either subsidiary objects or have no membership support.
+ */
switch (stmt->objtype)
{
case OBJECT_DATABASE:
@@ -3938,7 +3944,9 @@ ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt,
case OBJECT_TABLESPACE:
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
- errmsg("cannot add an object of this type to an extension")));
+ stmt->action > 0
+ ? errmsg("cannot add an object of this type to an extension")
+ : errmsg("cannot drop an object of this type from an extension")));
break;
default:
/* OK */
diff --git a/src/test/modules/test_pg_dump/expected/test_pg_dump.out b/src/test/modules/test_pg_dump/expected/test_pg_dump.out
index 98c9cd481e7..25033cecdf5 100644
--- a/src/test/modules/test_pg_dump/expected/test_pg_dump.out
+++ b/src/test/modules/test_pg_dump/expected/test_pg_dump.out
@@ -2,6 +2,8 @@ CREATE ROLE regress_dump_test_role;
CREATE EXTENSION test_pg_dump;
ALTER EXTENSION test_pg_dump ADD DATABASE postgres; -- error
ERROR: cannot add an object of this type to an extension
+ALTER EXTENSION test_pg_dump DROP DATABASE postgres; -- error
+ERROR: cannot drop an object of this type from an extension
CREATE TABLE test_pg_dump_t1 (c1 int, junk text);
ALTER TABLE test_pg_dump_t1 DROP COLUMN junk; -- to exercise dropped-col cases
CREATE VIEW test_pg_dump_v1 AS SELECT * FROM test_pg_dump_t1;
diff --git a/src/test/modules/test_pg_dump/sql/test_pg_dump.sql b/src/test/modules/test_pg_dump/sql/test_pg_dump.sql
index 87e66cae6e3..f187ed762e0 100644
--- a/src/test/modules/test_pg_dump/sql/test_pg_dump.sql
+++ b/src/test/modules/test_pg_dump/sql/test_pg_dump.sql
@@ -2,6 +2,7 @@ CREATE ROLE regress_dump_test_role;
CREATE EXTENSION test_pg_dump;
ALTER EXTENSION test_pg_dump ADD DATABASE postgres; -- error
+ALTER EXTENSION test_pg_dump DROP DATABASE postgres; -- error
CREATE TABLE test_pg_dump_t1 (c1 int, junk text);
ALTER TABLE test_pg_dump_t1 DROP COLUMN junk; -- to exercise dropped-col cases
base-commit: 7fc2f0423320e02beb8c44b863f1827604c47c75
--
2.53.0