From c03784a2181594d150c7f486308172dee19c5321 Mon Sep 17 00:00:00 2001 From: Fujii Masao Date: Wed, 27 May 2026 10:35:49 +0900 Subject: [PATCH] pg_createsubscriber: Fix cleanup of publisher-side objects after errors When pg_createsubscriber fails after creating logical replication objects, it should remove the publication and replication slot that it created on the publisher. Previously, if dropping subscriber-side objects failed, pg_createsubscriber reset its internal cleanup state too early. As a result, the exit-time cleanup could skip removing the publication or replication slot on the publisher. This could leave pg_createsubscriber-created objects behind on the publisher after a failed run. That can make a retry harder, because the leftover publication or replication slot may need to be removed manually before running pg_createsubscriber again. In the case of a replication slot, leaving it behind can also retain WAL files longer than expected. The cause of this issue was that the flags made_publication and made_replslot tracking whether pg_createsubscriber created a publication or replication slot on the primary were incorrectly reset to false when failures occurred while dropping objects on the subscriber. This commit fixes the issue by preventing those cleanup flags from being reset even when failures occurred while dropping objects on the subscriber, ensuring proper cleanup of primary objects before exit on failure. Backpatch to v17, where pg_createsubscriber was added. Author: Nisha Moond Reviewed-by: David G. Johnston Reviewed-by: Fujii Masao Reviewed-by: Peter Smith Discussion: https://postgr.es/m/CABdArM5V9QKK1PkLY9dpgAcZa3kUp84-wPqPovxvdLOri4=69w@mail.gmail.com Backpatch-through: 17 --- src/bin/pg_basebackup/pg_createsubscriber.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/bin/pg_basebackup/pg_createsubscriber.c b/src/bin/pg_basebackup/pg_createsubscriber.c index eb90c23ca0d..b8f3b7111de 100644 --- a/src/bin/pg_basebackup/pg_createsubscriber.c +++ b/src/bin/pg_basebackup/pg_createsubscriber.c @@ -1402,7 +1402,6 @@ drop_replication_slot(PGconn *conn, struct LogicalRepInfo *dbinfo, { pg_log_error("could not drop replication slot \"%s\" in database \"%s\": %s", slot_name, dbinfo->dbname, PQresultErrorMessage(res)); - dbinfo->made_replslot = false; /* don't try again. */ } PQclear(res); @@ -1665,7 +1664,6 @@ drop_publication(PGconn *conn, struct LogicalRepInfo *dbinfo) { pg_log_error("could not drop publication \"%s\" in database \"%s\": %s", dbinfo->pubname, dbinfo->dbname, PQresultErrorMessage(res)); - dbinfo->made_publication = false; /* don't try again. */ /* * Don't disconnect and exit here. This routine is used by primary