From f1e51a497946b2bc5227430bad26af2141584f00 Mon Sep 17 00:00:00 2001 From: Nisha Moond Date: Tue, 3 Jun 2025 10:48:00 +0530 Subject: [PATCH v18 2/2] Fix for pg_dump When there is subscrption where both two_phase and failover are enabled, generate the CREATE SUBSCRIPTION command only with two_phase = on and ignore failover i.e. failover will be false(default). --- doc/src/sgml/ref/pg_dump.sgml | 13 +++++++++++++ src/bin/pg_dump/pg_dump.c | 12 +++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/doc/src/sgml/ref/pg_dump.sgml b/doc/src/sgml/ref/pg_dump.sgml index cfc74ca6d69..6c133c5e12a 100644 --- a/doc/src/sgml/ref/pg_dump.sgml +++ b/doc/src/sgml/ref/pg_dump.sgml @@ -1633,6 +1633,19 @@ CREATE DATABASE foo WITH TEMPLATE template0; had been originally created with two_phase = true option. + + When dumping logical replication subscriptions where both + two_phase + and failover + are enabled, pg_dump will generate CREATE + SUBSCRIPTION commands with only two_phase = true + option, omitting the failover=true option. That way, + the dump can be restored without encountering the error caused by enabling + both failover and two_phase simultaneously during . + After the restore, users can enable failover using + . + + It is generally recommended to use the () option when restoring a database from a diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 9ed1a856fa3..5c31f30e914 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -5129,6 +5129,7 @@ dumpSubscription(Archive *fout, const SubscriptionInfo *subinfo) int npubnames = 0; int i; char two_phase_disabled[] = {LOGICALREP_TWOPHASE_STATE_DISABLED, '\0'}; + bool set_failover = true; /* Do nothing in data-only dump */ if (dopt->dataOnly) @@ -5174,8 +5175,17 @@ dumpSubscription(Archive *fout, const SubscriptionInfo *subinfo) appendPQExpBufferStr(query, ", streaming = parallel"); if (strcmp(subinfo->subtwophasestate, two_phase_disabled) != 0) + { appendPQExpBufferStr(query, ", two_phase = on"); + /* + * The failover option cannot be set togather with two_phase during + * CREATE SUBSCRIPTION. It can be enabled later using ALTER + * SUBSCRIPTION after the subscription is restored. + */ + set_failover = false; + } + if (strcmp(subinfo->subdisableonerr, "t") == 0) appendPQExpBufferStr(query, ", disable_on_error = true"); @@ -5185,7 +5195,7 @@ dumpSubscription(Archive *fout, const SubscriptionInfo *subinfo) if (strcmp(subinfo->subrunasowner, "t") == 0) appendPQExpBufferStr(query, ", run_as_owner = true"); - if (strcmp(subinfo->subfailover, "t") == 0) + if (set_failover && strcmp(subinfo->subfailover, "t") == 0) appendPQExpBufferStr(query, ", failover = true"); if (strcmp(subinfo->subsynccommit, "off") != 0) -- 2.34.1