CREATE PUBLICATION in an extension script does not record extension membership ============================================================================== AI-generated bug report from the AI Annex Report ID: 01a1cb98-9752-7561-b128-bf79b7d3115a Filed: 2026-11-11 17:12:17 UTC Severity: 45/100 Blamed commit: 665d1fad99e7b11678b0d5fa24d2898424243cd6 CREATE PUBLICATION does not record a dependency on the extension whose script creates the publication. ALTER EXTENSION ADD PUBLICATION and ALTER EXTENSION DROP PUBLICATION are rejected. DROP EXTENSION therefore leaves the publication behind. Installing the extension again fails because the publication name is still in use. Publishing an extension-owned table does not tie the publication's lifetime to that table. The row in pg_publication_rel depends on the publication with an AUTO dependency, so dropping the table removes only the membership row. pg_dump uses extension membership to decide whether to emit an object. selectDumpablePublicationObject already calls checkExtensionMembership. Without a membership dependency, a dump contains the extension script, which creates the publication, and a separate CREATE PUBLICATION for the same name. Restoring that dump fails when the second creation runs. No supported command can attach the orphan publication to the extension afterward. Commit 665d1fad99e7b11678b0d5fa24d2898424243cd6 (Logical replication, 2017-01-20) added CreatePublication. That function records an owner dependency and does not call recordDependencyOnCurrentExtension. The same omission, and the rejection of OBJECT_PUBLICATION in ALTER EXTENSION, are present on master and on REL_14_STABLE through REL_19_STABLE. The behavior was reproduced on current master. Install an extension with this control file and script: ``` comment = 'publication membership repro' default_version = '1.0' relocatable = false ``` ```sql CREATE PUBLICATION tip25_pub FOR ALL TABLES; ``` Then run: ```sql CREATE EXTENSION tip25_pub; DROP EXTENSION tip25_pub; SELECT pubname FROM pg_publication WHERE pubname = 'tip25_pub'; CREATE EXTENSION tip25_pub; ``` Expected: DROP EXTENSION removes tip25_pub, the SELECT returns no rows, and the extension can be created again. Actual: the SELECT returns tip25_pub. The second CREATE EXTENSION fails with: ``` ERROR: publication "tip25_pub" already exists ``` The error context names the extension script. A script that creates a table and a publication for that table behaves the same way: ```sql CREATE TABLE tip25_t (a int); CREATE PUBLICATION tip25_pub2 FOR TABLE tip25_t; ``` After CREATE EXTENSION, the deptype 'e' dependencies name the table and its row type, not the publication. DROP EXTENSION drops the table and leaves tip25_pub2 in place. Creating the extension again fails with publication "tip25_pub2" already exists. Attaching an existing publication is also rejected: ```sql CREATE PUBLICATION tip25_free; ALTER EXTENSION tip25_pub ADD PUBLICATION tip25_free; ``` Expected: tip25_free becomes a member of the extension. Actual: ``` ERROR: cannot add an object of this type to an extension ``` CreatePublication inserts the pg_publication row and calls recordDependencyOnOwner only. Other database-local objects created from an extension script, including event triggers, call recordDependencyOnCurrentExtension at that point. ExecAlterExtensionContentsStmt rejects OBJECT_PUBLICATION before it looks up the extension. The grammar already accepts PUBLICATION for ALTER EXTENSION ADD and DROP, and get_object_address already resolves a publication by name. pg_publication has no ACL column. From version 16 on, recordExtObjInitPriv returns without recording privileges when the object type has no ACL attribute, so accepting the object type is enough there. On versions 14 and 15 that function raises "unrecognized or unsupported class OID" for a class that is not on its explicit list. PublicationRelationId has to be added to the list of types with no ACL before ALTER EXTENSION ADD PUBLICATION can succeed on those versions. Creating the publication from the script does not call recordExtObjInitPriv, so recording membership at creation does not need that change. dumpPublication does not call binary_upgrade_extension_member. During a binary upgrade, extension members are dumped individually and then associated with ALTER EXTENSION ADD. Other member objects append that command. A publication member would be created and left outside the extension. Publications are database-local. The extension documentation says the member kinds are those listed for ALTER EXTENSION. It names cluster-wide objects (databases, roles, and tablespaces) and subsidiary objects such as indexes as the cases a script may create without tracking them. A publication is neither. After the owner dependency is recorded in CreatePublication, call recordDependencyOnCurrentExtension. Stop rejecting OBJECT_PUBLICATION in ExecAlterExtensionContentsStmt. When binary upgrade output is requested, have dumpPublication call binary_upgrade_extension_member so the dump emits ALTER EXTENSION ... ADD PUBLICATION. List PUBLICATION in the ALTER EXTENSION synopsis and in psql tab completion. On versions 14 and 15, also include PublicationRelationId in the no-ACL class list inside recordExtObjInitPriv. No catalog version bump is required: the membership row uses the existing extension dependency type. A patch against master is included. It was built, and the repro was run again on that build. DROP EXTENSION removes the publication, ALTER EXTENSION ADD PUBLICATION and DROP PUBLICATION succeed, and the test_extensions regression covers both paths. The same source change applies on REL_16_STABLE through REL_19_STABLE. Versions 14 and 15 also need the recordExtObjInitPriv list change described above; that part is not in the attached patch. Severity is 45. The nearest anchor is 40 (unlikely, medium impact, possible workarounds). Extension scripts that create publications are uncommon, and dropping the orphan by hand lets the extension be installed again. The score is five points higher because the orphan blocks reinstall and a dump and restore, dropping the published table does not remove the publication, and ALTER EXTENSION cannot repair the membership.