v19-0002-Don-t-dump-failover-true-with-two_phase-in-CREAT.patch
application/x-patch
Filename: v19-0002-Don-t-dump-failover-true-with-two_phase-in-CREAT.patch
Type: application/x-patch
Part: 1
From b0e26e90d99ebfb2602a7417c2c221df84767d57 Mon Sep 17 00:00:00 2001
From: Nisha Moond <nisha.moond412@gmail.com>
Date: Tue, 3 Jun 2025 10:48:00 +0530
Subject: [PATCH v19 2/2] Don't dump failover=true with two_phase in CREATE
SUBSCRIPTION
When dumping logical replication subscriptions where both two_phase and
failover are enabled, generate the 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 CREATE
SUBSCRIPTION. After the restore, users can enable failover using ALTER
SUBSCRIPTION.
---
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 <literal>two_phase = true</literal> option.
</para>
+ <para>
+ When dumping logical replication subscriptions where both
+ <link linkend="sql-createsubscription-params-with-two-phase"><literal>two_phase</literal></link>
+ and <link linkend="sql-createsubscription-params-with-failover"><literal>failover</literal></link>
+ are enabled, <application>pg_dump</application> will generate <command>CREATE
+ SUBSCRIPTION</command> commands with only <literal>two_phase = true</literal>
+ option, omitting the <literal>failover=true</literal> option. That way,
+ the dump can be restored without encountering the error caused by enabling
+ both failover and two_phase simultaneously during <xref linkend="sql-createsubscription"/>.
+ After the restore, users can enable <literal>failover</literal> using
+ <xref linkend="sql-altersubscription"/>.
+ </para>
+
<para>
It is generally recommended to use the <option>-X</option>
(<option>--no-psqlrc</option>) 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..cb5f4b0812b 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 together 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