pg_recvlogical cannot create slots with failover=true
Dear hackers,
While reviewing threads I found $SUBJECT.
I think it does not affect to output, but I could not find strong reasons not to
support it. Also, this can be used for testing purpose, i.e., DBAs can verify the
slot-sync can work on their system by only using pg_recvlogical.
Attached patch implements it. Since -f/-F option has already been used, -O was
chosen for the short-version. Better idea is very welcomed.
How do you feel?
Best regards,
Hayato Kuroda
FUJITSU LIMITED
Attachments:
0001-Allow-pg_recvlogical-to-create-slots-with-failover-t.patchapplication/octet-stream; name=0001-Allow-pg_recvlogical-to-create-slots-with-failover-t.patchDownload
From c29d8f7de9da17d74de1737b8feb8707e6f765d6 Mon Sep 17 00:00:00 2001
From: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Date: Tue, 1 Apr 2025 16:45:59 +0900
Subject: [PATCH] Allow pg_recvlogical to create slots with failover=true
--two-phase option in pg_recvlogical allows users to create replication slots
two_phase=true. However, another slot option, failover, could not be enabled
from the command.
This patch adds a new option --failover (-O) in pg_recvlogical. When specified,
the command tries to create a slot with failover=true, which can be synchronized
to the standby.
---
doc/src/sgml/ref/pg_recvlogical.sgml | 14 +++++++++
src/bin/pg_basebackup/pg_basebackup.c | 3 +-
src/bin/pg_basebackup/pg_receivewal.c | 2 +-
src/bin/pg_basebackup/pg_recvlogical.c | 29 +++++++++++++++----
src/bin/pg_basebackup/streamutil.c | 7 ++++-
src/bin/pg_basebackup/streamutil.h | 3 +-
src/bin/pg_basebackup/t/030_pg_recvlogical.pl | 15 ++++++++++
7 files changed, 63 insertions(+), 10 deletions(-)
diff --git a/doc/src/sgml/ref/pg_recvlogical.sgml b/doc/src/sgml/ref/pg_recvlogical.sgml
index 2946bdae1e5..3866855c597 100644
--- a/doc/src/sgml/ref/pg_recvlogical.sgml
+++ b/doc/src/sgml/ref/pg_recvlogical.sgml
@@ -81,6 +81,9 @@ PostgreSQL documentation
<para>
The <option>--two-phase</option> can be specified with
<option>--create-slot</option> to enable decoding of prepared transactions.
+ Also, <option>--falover</option> can be specified with
+ <option>--create-slot</option> to create replication slot which can be
+ synchronized to the standby.
</para>
</listitem>
</varlistentry>
@@ -249,6 +252,17 @@ PostgreSQL documentation
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-O</option></term>
+ <term><option>--failover</option></term>
+ <listitem>
+ <para>
+ Allows created replication slot to be synchronized to the standbys.
+ This option may only be specified with <option>--create-slot</option>.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>-P <replaceable>plugin</replaceable></option></term>
<term><option>--plugin=<replaceable>plugin</replaceable></option></term>
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index 1da4bfc2351..eb7354200bc 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -667,7 +667,8 @@ StartLogStreamer(char *startpos, uint32 timeline, char *sysidentifier,
if (temp_replication_slot || create_slot)
{
if (!CreateReplicationSlot(param->bgconn, replication_slot, NULL,
- temp_replication_slot, true, true, false, false))
+ temp_replication_slot, true, true, false,
+ false, false))
exit(1);
if (verbose)
diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c
index de3584018b0..e816cf58101 100644
--- a/src/bin/pg_basebackup/pg_receivewal.c
+++ b/src/bin/pg_basebackup/pg_receivewal.c
@@ -889,7 +889,7 @@ main(int argc, char **argv)
pg_log_info("creating replication slot \"%s\"", replication_slot);
if (!CreateReplicationSlot(conn, replication_slot, NULL, false, true, false,
- slot_exists_ok, false))
+ slot_exists_ok, false, false))
exit(1);
exit(0);
}
diff --git a/src/bin/pg_basebackup/pg_recvlogical.c b/src/bin/pg_basebackup/pg_recvlogical.c
index e6158251ec1..89198379f62 100644
--- a/src/bin/pg_basebackup/pg_recvlogical.c
+++ b/src/bin/pg_basebackup/pg_recvlogical.c
@@ -42,6 +42,7 @@ typedef enum
static char *outfile = NULL;
static int verbose = 0;
static bool two_phase = false;
+static bool failover = false;
static int noloop = 0;
static int standby_message_timeout = 10 * 1000; /* 10 sec = default */
static int fsync_interval = 10 * 1000; /* 10 sec = default */
@@ -695,6 +696,7 @@ main(int argc, char **argv)
{"file", required_argument, NULL, 'f'},
{"fsync-interval", required_argument, NULL, 'F'},
{"no-loop", no_argument, NULL, 'n'},
+ {"failover", no_argument, NULL, 'O'},
{"verbose", no_argument, NULL, 'v'},
{"two-phase", no_argument, NULL, 't'},
{"version", no_argument, NULL, 'V'},
@@ -745,7 +747,7 @@ main(int argc, char **argv)
}
}
- while ((c = getopt_long(argc, argv, "E:f:F:ntvd:h:p:U:wWI:o:P:s:S:",
+ while ((c = getopt_long(argc, argv, "E:f:F:ntvd:h:p:U:wWI:o:OP:s:S:",
long_options, &option_index)) != -1)
{
switch (c)
@@ -764,6 +766,9 @@ main(int argc, char **argv)
case 'n':
noloop = 1;
break;
+ case 'O':
+ failover = true;
+ break;
case 't':
two_phase = true;
break;
@@ -917,11 +922,22 @@ main(int argc, char **argv)
exit(1);
}
- if (two_phase && !do_create_slot)
+ if (!do_create_slot)
{
- pg_log_error("--two-phase may only be specified with --create-slot");
- pg_log_error_hint("Try \"%s --help\" for more information.", progname);
- exit(1);
+ if (two_phase)
+ {
+ pg_log_error("--two-phase may only be specified with --create-slot");
+ pg_log_error_hint("Try \"%s --help\" for more information.",
+ progname);
+ exit(1);
+ }
+ else if (failover)
+ {
+ pg_log_error("--failover may only be specified with --create-slot");
+ pg_log_error_hint("Try \"%s --help\" for more information.",
+ progname);
+ exit(1);
+ }
}
/*
@@ -984,7 +1000,8 @@ main(int argc, char **argv)
pg_log_info("creating replication slot \"%s\"", replication_slot);
if (!CreateReplicationSlot(conn, replication_slot, plugin, false,
- false, false, slot_exists_ok, two_phase))
+ false, false, slot_exists_ok, two_phase,
+ failover))
exit(1);
startpos = InvalidXLogRecPtr;
}
diff --git a/src/bin/pg_basebackup/streamutil.c b/src/bin/pg_basebackup/streamutil.c
index 8e605f43ffe..c7b8a4c3a4b 100644
--- a/src/bin/pg_basebackup/streamutil.c
+++ b/src/bin/pg_basebackup/streamutil.c
@@ -583,7 +583,7 @@ GetSlotInformation(PGconn *conn, const char *slot_name,
bool
CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin,
bool is_temporary, bool is_physical, bool reserve_wal,
- bool slot_exists_ok, bool two_phase)
+ bool slot_exists_ok, bool two_phase, bool failover)
{
PQExpBuffer query;
PGresult *res;
@@ -594,6 +594,7 @@ CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin,
Assert((is_physical && plugin == NULL) ||
(!is_physical && plugin != NULL));
Assert(!(two_phase && is_physical));
+ Assert(!(failover && is_physical));
Assert(slot_name != NULL);
/* Build base portion of query */
@@ -616,6 +617,10 @@ CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin,
}
else
{
+ if (failover && PQserverVersion(conn) >= 170000)
+ AppendPlainCommandOption(query, use_new_option_syntax,
+ "FAILOVER");
+
if (two_phase && PQserverVersion(conn) >= 150000)
AppendPlainCommandOption(query, use_new_option_syntax,
"TWO_PHASE");
diff --git a/src/bin/pg_basebackup/streamutil.h b/src/bin/pg_basebackup/streamutil.h
index f917c43517f..017b227303c 100644
--- a/src/bin/pg_basebackup/streamutil.h
+++ b/src/bin/pg_basebackup/streamutil.h
@@ -35,7 +35,8 @@ extern PGconn *GetConnection(void);
extern bool CreateReplicationSlot(PGconn *conn, const char *slot_name,
const char *plugin, bool is_temporary,
bool is_physical, bool reserve_wal,
- bool slot_exists_ok, bool two_phase);
+ bool slot_exists_ok, bool two_phase,
+ bool failover);
extern bool DropReplicationSlot(PGconn *conn, const char *slot_name);
extern bool RunIdentifySystem(PGconn *conn, char **sysid,
TimeLineID *starttli,
diff --git a/src/bin/pg_basebackup/t/030_pg_recvlogical.pl b/src/bin/pg_basebackup/t/030_pg_recvlogical.pl
index 62bbc5a3f98..c82e78847b3 100644
--- a/src/bin/pg_basebackup/t/030_pg_recvlogical.pl
+++ b/src/bin/pg_basebackup/t/030_pg_recvlogical.pl
@@ -135,4 +135,19 @@ $node->command_ok(
],
'drop could work without dbname');
+# test with failover option enabled
+$node->command_ok(
+ [
+ 'pg_recvlogical',
+ '--slot' => 'test',
+ '--dbname' => $node->connstr('postgres'),
+ '--create-slot',
+ '--failover',
+ ],
+ 'slot with failover created');
+
+my $result = $node->safe_psql('postgres',
+ "SELECT failover FROM pg_catalog.pg_replication_slots WHERE slot_name = 'test'");
+is($result, 't', "failover is enabled for the new slot");
+
done_testing();
--
2.43.5
Hi,
On Tue, Apr 01, 2025 at 08:01:32AM +0000, Hayato Kuroda (Fujitsu) wrote:
Attached patch implements it. Since -f/-F option has already been used, -O was
chosen for the short-version. Better idea is very welcomed.
Maybe we don't need a short option at all for this, at least initially?
Michael
Dear Michael,
Maybe we don't need a short option at all for this, at least initially?
Indeed, updated.
Best regards,
Hayato Kuroda
FUJITSU LIMITED
Attachments:
v2-0001-Allow-pg_recvlogical-to-create-slots-with-failove.patchapplication/octet-stream; name=v2-0001-Allow-pg_recvlogical-to-create-slots-with-failove.patchDownload
From b234ef52edbefbb26d374032112fd11096ce7ba0 Mon Sep 17 00:00:00 2001
From: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Date: Tue, 1 Apr 2025 16:45:59 +0900
Subject: [PATCH v2] Allow pg_recvlogical to create slots with failover=true
--two-phase option in pg_recvlogical allows users to create replication slots
two_phase=true. However, another slot option, failover, could not be enabled
from the command.
This patch adds a new option --failover in pg_recvlogical. When specified, the
command tries to create a slot with failover=true, which can be synchronized
to the standby.
---
doc/src/sgml/ref/pg_recvlogical.sgml | 13 +++++++++
src/bin/pg_basebackup/pg_basebackup.c | 3 +-
src/bin/pg_basebackup/pg_receivewal.c | 2 +-
src/bin/pg_basebackup/pg_recvlogical.c | 28 +++++++++++++++----
src/bin/pg_basebackup/streamutil.c | 7 ++++-
src/bin/pg_basebackup/streamutil.h | 3 +-
src/bin/pg_basebackup/t/030_pg_recvlogical.pl | 15 ++++++++++
7 files changed, 62 insertions(+), 9 deletions(-)
diff --git a/doc/src/sgml/ref/pg_recvlogical.sgml b/doc/src/sgml/ref/pg_recvlogical.sgml
index 2946bdae1e5..558fb92070f 100644
--- a/doc/src/sgml/ref/pg_recvlogical.sgml
+++ b/doc/src/sgml/ref/pg_recvlogical.sgml
@@ -81,6 +81,9 @@ PostgreSQL documentation
<para>
The <option>--two-phase</option> can be specified with
<option>--create-slot</option> to enable decoding of prepared transactions.
+ Also, <option>--falover</option> can be specified with
+ <option>--create-slot</option> to create replication slot which can be
+ synchronized to the standby.
</para>
</listitem>
</varlistentry>
@@ -249,6 +252,16 @@ PostgreSQL documentation
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>--failover</option></term>
+ <listitem>
+ <para>
+ Allows created replication slot to be synchronized to the standbys.
+ This option may only be specified with <option>--create-slot</option>.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>-P <replaceable>plugin</replaceable></option></term>
<term><option>--plugin=<replaceable>plugin</replaceable></option></term>
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index 1da4bfc2351..eb7354200bc 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -667,7 +667,8 @@ StartLogStreamer(char *startpos, uint32 timeline, char *sysidentifier,
if (temp_replication_slot || create_slot)
{
if (!CreateReplicationSlot(param->bgconn, replication_slot, NULL,
- temp_replication_slot, true, true, false, false))
+ temp_replication_slot, true, true, false,
+ false, false))
exit(1);
if (verbose)
diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c
index de3584018b0..e816cf58101 100644
--- a/src/bin/pg_basebackup/pg_receivewal.c
+++ b/src/bin/pg_basebackup/pg_receivewal.c
@@ -889,7 +889,7 @@ main(int argc, char **argv)
pg_log_info("creating replication slot \"%s\"", replication_slot);
if (!CreateReplicationSlot(conn, replication_slot, NULL, false, true, false,
- slot_exists_ok, false))
+ slot_exists_ok, false, false))
exit(1);
exit(0);
}
diff --git a/src/bin/pg_basebackup/pg_recvlogical.c b/src/bin/pg_basebackup/pg_recvlogical.c
index e6158251ec1..c510d3ebf06 100644
--- a/src/bin/pg_basebackup/pg_recvlogical.c
+++ b/src/bin/pg_basebackup/pg_recvlogical.c
@@ -42,6 +42,7 @@ typedef enum
static char *outfile = NULL;
static int verbose = 0;
static bool two_phase = false;
+static bool failover = false;
static int noloop = 0;
static int standby_message_timeout = 10 * 1000; /* 10 sec = default */
static int fsync_interval = 10 * 1000; /* 10 sec = default */
@@ -89,6 +90,7 @@ usage(void)
printf(_(" --start start streaming in a replication slot (for the slot's name see --slot)\n"));
printf(_("\nOptions:\n"));
printf(_(" -E, --endpos=LSN exit after receiving the specified LSN\n"));
+ printf(_(" --failover enable being synchronized to the standby when creating a slot\n"));
printf(_(" -f, --file=FILE receive log into this file, - for stdout\n"));
printf(_(" -F --fsync-interval=SECS\n"
" time between fsyncs to the output file (default: %d)\n"), (fsync_interval / 1000));
@@ -695,6 +697,7 @@ main(int argc, char **argv)
{"file", required_argument, NULL, 'f'},
{"fsync-interval", required_argument, NULL, 'F'},
{"no-loop", no_argument, NULL, 'n'},
+ {"failover", no_argument, NULL, 5},
{"verbose", no_argument, NULL, 'v'},
{"two-phase", no_argument, NULL, 't'},
{"version", no_argument, NULL, 'V'},
@@ -770,6 +773,9 @@ main(int argc, char **argv)
case 'v':
verbose++;
break;
+ case 5:
+ failover = true;
+ break;
/* connection options */
case 'd':
dbname = pg_strdup(optarg);
@@ -917,11 +923,22 @@ main(int argc, char **argv)
exit(1);
}
- if (two_phase && !do_create_slot)
+ if (!do_create_slot)
{
- pg_log_error("--two-phase may only be specified with --create-slot");
- pg_log_error_hint("Try \"%s --help\" for more information.", progname);
- exit(1);
+ if (two_phase)
+ {
+ pg_log_error("--two-phase may only be specified with --create-slot");
+ pg_log_error_hint("Try \"%s --help\" for more information.",
+ progname);
+ exit(1);
+ }
+ else if (failover)
+ {
+ pg_log_error("--failover may only be specified with --create-slot");
+ pg_log_error_hint("Try \"%s --help\" for more information.",
+ progname);
+ exit(1);
+ }
}
/*
@@ -984,7 +1001,8 @@ main(int argc, char **argv)
pg_log_info("creating replication slot \"%s\"", replication_slot);
if (!CreateReplicationSlot(conn, replication_slot, plugin, false,
- false, false, slot_exists_ok, two_phase))
+ false, false, slot_exists_ok, two_phase,
+ failover))
exit(1);
startpos = InvalidXLogRecPtr;
}
diff --git a/src/bin/pg_basebackup/streamutil.c b/src/bin/pg_basebackup/streamutil.c
index 8e605f43ffe..c7b8a4c3a4b 100644
--- a/src/bin/pg_basebackup/streamutil.c
+++ b/src/bin/pg_basebackup/streamutil.c
@@ -583,7 +583,7 @@ GetSlotInformation(PGconn *conn, const char *slot_name,
bool
CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin,
bool is_temporary, bool is_physical, bool reserve_wal,
- bool slot_exists_ok, bool two_phase)
+ bool slot_exists_ok, bool two_phase, bool failover)
{
PQExpBuffer query;
PGresult *res;
@@ -594,6 +594,7 @@ CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin,
Assert((is_physical && plugin == NULL) ||
(!is_physical && plugin != NULL));
Assert(!(two_phase && is_physical));
+ Assert(!(failover && is_physical));
Assert(slot_name != NULL);
/* Build base portion of query */
@@ -616,6 +617,10 @@ CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin,
}
else
{
+ if (failover && PQserverVersion(conn) >= 170000)
+ AppendPlainCommandOption(query, use_new_option_syntax,
+ "FAILOVER");
+
if (two_phase && PQserverVersion(conn) >= 150000)
AppendPlainCommandOption(query, use_new_option_syntax,
"TWO_PHASE");
diff --git a/src/bin/pg_basebackup/streamutil.h b/src/bin/pg_basebackup/streamutil.h
index f917c43517f..017b227303c 100644
--- a/src/bin/pg_basebackup/streamutil.h
+++ b/src/bin/pg_basebackup/streamutil.h
@@ -35,7 +35,8 @@ extern PGconn *GetConnection(void);
extern bool CreateReplicationSlot(PGconn *conn, const char *slot_name,
const char *plugin, bool is_temporary,
bool is_physical, bool reserve_wal,
- bool slot_exists_ok, bool two_phase);
+ bool slot_exists_ok, bool two_phase,
+ bool failover);
extern bool DropReplicationSlot(PGconn *conn, const char *slot_name);
extern bool RunIdentifySystem(PGconn *conn, char **sysid,
TimeLineID *starttli,
diff --git a/src/bin/pg_basebackup/t/030_pg_recvlogical.pl b/src/bin/pg_basebackup/t/030_pg_recvlogical.pl
index 62bbc5a3f98..c82e78847b3 100644
--- a/src/bin/pg_basebackup/t/030_pg_recvlogical.pl
+++ b/src/bin/pg_basebackup/t/030_pg_recvlogical.pl
@@ -135,4 +135,19 @@ $node->command_ok(
],
'drop could work without dbname');
+# test with failover option enabled
+$node->command_ok(
+ [
+ 'pg_recvlogical',
+ '--slot' => 'test',
+ '--dbname' => $node->connstr('postgres'),
+ '--create-slot',
+ '--failover',
+ ],
+ 'slot with failover created');
+
+my $result = $node->safe_psql('postgres',
+ "SELECT failover FROM pg_catalog.pg_replication_slots WHERE slot_name = 'test'");
+is($result, 't', "failover is enabled for the new slot");
+
done_testing();
--
2.43.5
On Wed, Apr 2, 2025 at 11:57 PM Hayato Kuroda (Fujitsu)
<kuroda.hayato@fujitsu.com> wrote:
Dear Michael,
Maybe we don't need a short option at all for this, at least initially?
Indeed, updated.
Thank you for updating the patch. Here are some minor comments:
The <option>--two-phase</option> can be specified with
<option>--create-slot</option> to enable decoding of prepared
transactions.
+ Also, <option>--falover</option> can be specified with
+ <option>--create-slot</option> to create replication slot which can be
+ synchronized to the standby.
How about rewording the whole sentence like:
+ The <option>--two-phase</option> and
<option>--failover</option> options
+ can be specified with <option>--create-slot</option>.
Explaining both options here seems redundant to me.
---
+ <para>
+ Allows created replication slot to be synchronized to the standbys.
+ This option may only be specified with <option>--create-slot</option>.
+ </para>
How about slightly rewording to like:
+ Enables the slot to be synchronized to the standbys. This
option may only be
+ specified with <option>--create-slot</option>.
Also, the descriptions of pg_recvlogical options are written in
alphabetical order. Please put the description for --failover option
after -E/--endpos.
The rest looks good to me.
Regards,
--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com
Dear Sawada-san,
Thank you for updating the patch. Here are some minor comments:
The <option>--two-phase</option> can be specified with <option>--create-slot</option> to enable decoding of prepared transactions. + Also, <option>--falover</option> can be specified with + <option>--create-slot</option> to create replication slot which can be + synchronized to the standby.How about rewording the whole sentence like:
+ The <option>--two-phase</option> and <option>--failover</option> options + can be specified with <option>--create-slot</option>.Explaining both options here seems redundant to me.
Fixed.
--- + <para> + Allows created replication slot to be synchronized to the standbys. + This option may only be specified with <option>--create-slot</option>. + </para>How about slightly rewording to like:
+ Enables the slot to be synchronized to the standbys. This option may only be + specified with <option>--create-slot</option>.
Fixed. The description in usage() is adjusted based on this.
Also, the descriptions of pg_recvlogical options are written in
alphabetical order. Please put the description for --failover option
after -E/--endpos.
Right. I put because it had short-term '-o' in old version, but it was removed.
Fixed.
PSA new version.
Best regards,
Hayato Kuroda
FUJITSU LIMITED
Attachments:
v3-0001-Allow-pg_recvlogical-to-create-slots-with-failove.patchapplication/octet-stream; name=v3-0001-Allow-pg_recvlogical-to-create-slots-with-failove.patchDownload
From f79cb31eeb96993e63cc5c8208a444a052532490 Mon Sep 17 00:00:00 2001
From: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Date: Tue, 1 Apr 2025 16:45:59 +0900
Subject: [PATCH v3] Allow pg_recvlogical to create slots with failover=true
--two-phase option in pg_recvlogical allows users to create replication slots
two_phase=true. However, another slot option, failover, could not be enabled
from the command.
This patch adds a new option --failover in pg_recvlogical. When specified, the
command tries to create a slot with failover=true, which can be synchronized
to the standby.
Author: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Michael Banck <mbanck@gmx.net>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
---
doc/src/sgml/ref/pg_recvlogical.sgml | 14 +++++++--
src/bin/pg_basebackup/pg_basebackup.c | 3 +-
src/bin/pg_basebackup/pg_receivewal.c | 2 +-
src/bin/pg_basebackup/pg_recvlogical.c | 29 +++++++++++++++----
src/bin/pg_basebackup/streamutil.c | 7 ++++-
src/bin/pg_basebackup/streamutil.h | 3 +-
src/bin/pg_basebackup/t/030_pg_recvlogical.pl | 15 ++++++++++
7 files changed, 62 insertions(+), 11 deletions(-)
diff --git a/doc/src/sgml/ref/pg_recvlogical.sgml b/doc/src/sgml/ref/pg_recvlogical.sgml
index 2946bdae1e5..5166393abeb 100644
--- a/doc/src/sgml/ref/pg_recvlogical.sgml
+++ b/doc/src/sgml/ref/pg_recvlogical.sgml
@@ -79,8 +79,8 @@ PostgreSQL documentation
</para>
<para>
- The <option>--two-phase</option> can be specified with
- <option>--create-slot</option> to enable decoding of prepared transactions.
+ The <option>--two-phase</option> and <option>--falover</option> options
+ can be specified with <option>--create-slot</option>.
</para>
</listitem>
</varlistentry>
@@ -165,6 +165,16 @@ PostgreSQL documentation
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>--failover</option></term>
+ <listitem>
+ <para>
+ Enables the slot to be synchronized to the standbys. This option may
+ only be specified with <option>--create-slot</option>.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>-f <replaceable>filename</replaceable></option></term>
<term><option>--file=<replaceable>filename</replaceable></option></term>
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index 1da4bfc2351..eb7354200bc 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -667,7 +667,8 @@ StartLogStreamer(char *startpos, uint32 timeline, char *sysidentifier,
if (temp_replication_slot || create_slot)
{
if (!CreateReplicationSlot(param->bgconn, replication_slot, NULL,
- temp_replication_slot, true, true, false, false))
+ temp_replication_slot, true, true, false,
+ false, false))
exit(1);
if (verbose)
diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c
index de3584018b0..e816cf58101 100644
--- a/src/bin/pg_basebackup/pg_receivewal.c
+++ b/src/bin/pg_basebackup/pg_receivewal.c
@@ -889,7 +889,7 @@ main(int argc, char **argv)
pg_log_info("creating replication slot \"%s\"", replication_slot);
if (!CreateReplicationSlot(conn, replication_slot, NULL, false, true, false,
- slot_exists_ok, false))
+ slot_exists_ok, false, false))
exit(1);
exit(0);
}
diff --git a/src/bin/pg_basebackup/pg_recvlogical.c b/src/bin/pg_basebackup/pg_recvlogical.c
index e6158251ec1..339d3a539c5 100644
--- a/src/bin/pg_basebackup/pg_recvlogical.c
+++ b/src/bin/pg_basebackup/pg_recvlogical.c
@@ -42,6 +42,7 @@ typedef enum
static char *outfile = NULL;
static int verbose = 0;
static bool two_phase = false;
+static bool failover = false;
static int noloop = 0;
static int standby_message_timeout = 10 * 1000; /* 10 sec = default */
static int fsync_interval = 10 * 1000; /* 10 sec = default */
@@ -89,6 +90,8 @@ usage(void)
printf(_(" --start start streaming in a replication slot (for the slot's name see --slot)\n"));
printf(_("\nOptions:\n"));
printf(_(" -E, --endpos=LSN exit after receiving the specified LSN\n"));
+ printf(_(" --failover enable the replication slot being synchronized to the standby\n"
+ " when creating a slot\n"));
printf(_(" -f, --file=FILE receive log into this file, - for stdout\n"));
printf(_(" -F --fsync-interval=SECS\n"
" time between fsyncs to the output file (default: %d)\n"), (fsync_interval / 1000));
@@ -695,6 +698,7 @@ main(int argc, char **argv)
{"file", required_argument, NULL, 'f'},
{"fsync-interval", required_argument, NULL, 'F'},
{"no-loop", no_argument, NULL, 'n'},
+ {"failover", no_argument, NULL, 5},
{"verbose", no_argument, NULL, 'v'},
{"two-phase", no_argument, NULL, 't'},
{"version", no_argument, NULL, 'V'},
@@ -770,6 +774,9 @@ main(int argc, char **argv)
case 'v':
verbose++;
break;
+ case 5:
+ failover = true;
+ break;
/* connection options */
case 'd':
dbname = pg_strdup(optarg);
@@ -917,11 +924,22 @@ main(int argc, char **argv)
exit(1);
}
- if (two_phase && !do_create_slot)
+ if (!do_create_slot)
{
- pg_log_error("--two-phase may only be specified with --create-slot");
- pg_log_error_hint("Try \"%s --help\" for more information.", progname);
- exit(1);
+ if (two_phase)
+ {
+ pg_log_error("--two-phase may only be specified with --create-slot");
+ pg_log_error_hint("Try \"%s --help\" for more information.",
+ progname);
+ exit(1);
+ }
+ else if (failover)
+ {
+ pg_log_error("--failover may only be specified with --create-slot");
+ pg_log_error_hint("Try \"%s --help\" for more information.",
+ progname);
+ exit(1);
+ }
}
/*
@@ -984,7 +1002,8 @@ main(int argc, char **argv)
pg_log_info("creating replication slot \"%s\"", replication_slot);
if (!CreateReplicationSlot(conn, replication_slot, plugin, false,
- false, false, slot_exists_ok, two_phase))
+ false, false, slot_exists_ok, two_phase,
+ failover))
exit(1);
startpos = InvalidXLogRecPtr;
}
diff --git a/src/bin/pg_basebackup/streamutil.c b/src/bin/pg_basebackup/streamutil.c
index 8e605f43ffe..c7b8a4c3a4b 100644
--- a/src/bin/pg_basebackup/streamutil.c
+++ b/src/bin/pg_basebackup/streamutil.c
@@ -583,7 +583,7 @@ GetSlotInformation(PGconn *conn, const char *slot_name,
bool
CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin,
bool is_temporary, bool is_physical, bool reserve_wal,
- bool slot_exists_ok, bool two_phase)
+ bool slot_exists_ok, bool two_phase, bool failover)
{
PQExpBuffer query;
PGresult *res;
@@ -594,6 +594,7 @@ CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin,
Assert((is_physical && plugin == NULL) ||
(!is_physical && plugin != NULL));
Assert(!(two_phase && is_physical));
+ Assert(!(failover && is_physical));
Assert(slot_name != NULL);
/* Build base portion of query */
@@ -616,6 +617,10 @@ CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin,
}
else
{
+ if (failover && PQserverVersion(conn) >= 170000)
+ AppendPlainCommandOption(query, use_new_option_syntax,
+ "FAILOVER");
+
if (two_phase && PQserverVersion(conn) >= 150000)
AppendPlainCommandOption(query, use_new_option_syntax,
"TWO_PHASE");
diff --git a/src/bin/pg_basebackup/streamutil.h b/src/bin/pg_basebackup/streamutil.h
index f917c43517f..017b227303c 100644
--- a/src/bin/pg_basebackup/streamutil.h
+++ b/src/bin/pg_basebackup/streamutil.h
@@ -35,7 +35,8 @@ extern PGconn *GetConnection(void);
extern bool CreateReplicationSlot(PGconn *conn, const char *slot_name,
const char *plugin, bool is_temporary,
bool is_physical, bool reserve_wal,
- bool slot_exists_ok, bool two_phase);
+ bool slot_exists_ok, bool two_phase,
+ bool failover);
extern bool DropReplicationSlot(PGconn *conn, const char *slot_name);
extern bool RunIdentifySystem(PGconn *conn, char **sysid,
TimeLineID *starttli,
diff --git a/src/bin/pg_basebackup/t/030_pg_recvlogical.pl b/src/bin/pg_basebackup/t/030_pg_recvlogical.pl
index 62bbc5a3f98..c82e78847b3 100644
--- a/src/bin/pg_basebackup/t/030_pg_recvlogical.pl
+++ b/src/bin/pg_basebackup/t/030_pg_recvlogical.pl
@@ -135,4 +135,19 @@ $node->command_ok(
],
'drop could work without dbname');
+# test with failover option enabled
+$node->command_ok(
+ [
+ 'pg_recvlogical',
+ '--slot' => 'test',
+ '--dbname' => $node->connstr('postgres'),
+ '--create-slot',
+ '--failover',
+ ],
+ 'slot with failover created');
+
+my $result = $node->safe_psql('postgres',
+ "SELECT failover FROM pg_catalog.pg_replication_slots WHERE slot_name = 'test'");
+is($result, 't', "failover is enabled for the new slot");
+
done_testing();
--
2.43.5
On Thu, Apr 3, 2025 at 8:28 PM Hayato Kuroda (Fujitsu)
<kuroda.hayato@fujitsu.com> wrote:
Dear Sawada-san,
Thank you for updating the patch. Here are some minor comments:
The <option>--two-phase</option> can be specified with <option>--create-slot</option> to enable decoding of prepared transactions. + Also, <option>--falover</option> can be specified with + <option>--create-slot</option> to create replication slot which can be + synchronized to the standby.How about rewording the whole sentence like:
+ The <option>--two-phase</option> and <option>--failover</option> options + can be specified with <option>--create-slot</option>.Explaining both options here seems redundant to me.
Fixed.
--- + <para> + Allows created replication slot to be synchronized to the standbys. + This option may only be specified with <option>--create-slot</option>. + </para>How about slightly rewording to like:
+ Enables the slot to be synchronized to the standbys. This option may only be + specified with <option>--create-slot</option>.Fixed. The description in usage() is adjusted based on this.
Also, the descriptions of pg_recvlogical options are written in
alphabetical order. Please put the description for --failover option
after -E/--endpos.Right. I put because it had short-term '-o' in old version, but it was removed.
Fixed.
Thank you for updating the patch! Pushed with small cosmetic changes.
Regards,
--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com
On Sat, Apr 5, 2025 at 1:45 AM Masahiko Sawada wrote:
Hi,
Thank you for updating the patch! Pushed with small cosmetic changes.
Thanks for pushing the feature !
I noticed one typo in the doc and here is a tiny patch to fix it.
- The <option>--two-phase</option> and <option>--falover</option> options
+ The <option>--two-phase</option> and <option>--failover</option> options
Best Regards,
Hou zj
Attachments:
0001-fix-typo.patchapplication/octet-stream; name=0001-fix-typo.patchDownload
From e05ed6f87c871bc40e111bc784e450130dcd72d9 Mon Sep 17 00:00:00 2001
From: Zhijie Hou <houzj.fnst@cn.fujitsu.com>
Date: Mon, 7 Apr 2025 10:14:25 +0800
Subject: [PATCH] fix typo
---
doc/src/sgml/ref/pg_recvlogical.sgml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/doc/src/sgml/ref/pg_recvlogical.sgml b/doc/src/sgml/ref/pg_recvlogical.sgml
index 5166393abeb..63a45c7018a 100644
--- a/doc/src/sgml/ref/pg_recvlogical.sgml
+++ b/doc/src/sgml/ref/pg_recvlogical.sgml
@@ -79,7 +79,7 @@ PostgreSQL documentation
</para>
<para>
- The <option>--two-phase</option> and <option>--falover</option> options
+ The <option>--two-phase</option> and <option>--failover</option> options
can be specified with <option>--create-slot</option>.
</para>
</listitem>
--
2.30.0.windows.2
On Sun, Apr 6, 2025 at 7:19 PM Zhijie Hou (Fujitsu)
<houzj.fnst@fujitsu.com> wrote:
On Sat, Apr 5, 2025 at 1:45 AM Masahiko Sawada wrote:
Hi,
Thank you for updating the patch! Pushed with small cosmetic changes.
Thanks for pushing the feature !
I noticed one typo in the doc and here is a tiny patch to fix it.
- The <option>--two-phase</option> and <option>--falover</option> options + The <option>--two-phase</option> and <option>--failover</option> options
Thank you for the report and the patch! Pushed.
Regards,
--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com
On 07.04.25 21:15, Masahiko Sawada wrote:
On Sun, Apr 6, 2025 at 7:19 PM Zhijie Hou (Fujitsu)
<houzj.fnst@fujitsu.com> wrote:On Sat, Apr 5, 2025 at 1:45 AM Masahiko Sawada wrote:
Hi,
Thank you for updating the patch! Pushed with small cosmetic changes.
Thanks for pushing the feature !
I noticed one typo in the doc and here is a tiny patch to fix it.
- The <option>--two-phase</option> and <option>--falover</option> options + The <option>--two-phase</option> and <option>--failover</option> optionsThank you for the report and the patch! Pushed.
I wonder if the option name --failover is ideal. To me, it sounds like
an action "do a failover!". Also consider that pg_recvlogical has other
action options such as --start and --create-slot, so it sounds a bit
like those.
Maybe something like --enable-failover would be better?
On Thu, Jun 12, 2025 at 10:42 PM Peter Eisentraut <peter@eisentraut.org> wrote:
On 07.04.25 21:15, Masahiko Sawada wrote:
On Sun, Apr 6, 2025 at 7:19 PM Zhijie Hou (Fujitsu)
<houzj.fnst@fujitsu.com> wrote:On Sat, Apr 5, 2025 at 1:45 AM Masahiko Sawada wrote:
Hi,
Thank you for updating the patch! Pushed with small cosmetic changes.
Thanks for pushing the feature !
I noticed one typo in the doc and here is a tiny patch to fix it.
- The <option>--two-phase</option> and <option>--falover</option> options + The <option>--two-phase</option> and <option>--failover</option> optionsThank you for the report and the patch! Pushed.
I wonder if the option name --failover is ideal. To me, it sounds like
an action "do a failover!". Also consider that pg_recvlogical has other
action options such as --start and --create-slot, so it sounds a bit
like those.
Fair point.
Maybe something like --enable-failover would be better?
Sounds better, but probably the --two-phase option has the same issue?
Regards,
--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com
On Sat, Jun 14, 2025 at 3:11 AM Masahiko Sawada <sawada.mshk@gmail.com> wrote:
On Thu, Jun 12, 2025 at 10:42 PM Peter Eisentraut <peter@eisentraut.org> wrote:
- The <option>--two-phase</option> and <option>--falover</option> options + The <option>--two-phase</option> and <option>--failover</option> optionsThank you for the report and the patch! Pushed.
I wonder if the option name --failover is ideal. To me, it sounds like
an action "do a failover!". Also consider that pg_recvlogical has other
action options such as --start and --create-slot, so it sounds a bit
like those.Fair point.
Maybe something like --enable-failover would be better?
Sounds better, but probably the --two-phase option has the same issue?
Ideally, we should change both to maintain consistency across various
slot options. OTOH, as we have already described these options as: "
The --two-phase and --failover options can be specified with
--create-slot.", it is clear that these are slot options. The previous
version docs have a description: "The --two-phase can be specified
with --create-slot to enable decoding of prepared transactions." which
makes it even more clear that the two-phase is a slot option. The
options are named similarly in pg_create_logical_replication_slot API
and during CREATE SUBSCRIPTION, so, to some level, there is a
consistency in naming of these options across all APIs/tools. But,
their usage in a tool like pg_recvlogical could be perceived
differently as well, so it is also okay to consider naming them
differently.
--
With Regards,
Amit Kapila.
Dear Amit, Sawada, Peter,
I wonder if the option name --failover is ideal. To me, it sounds like
an action "do a failover!". Also consider that pg_recvlogical has other
action options such as --start and --create-slot, so it sounds a bit
like those.Fair point.
Maybe something like --enable-failover would be better?
Sounds better, but probably the --two-phase option has the same issue?
Ideally, we should change both to maintain consistency across various
slot options. OTOH, as we have already described these options as: "
The --two-phase and --failover options can be specified with
--create-slot.", it is clear that these are slot options. The previous
version docs have a description: "The --two-phase can be specified
with --create-slot to enable decoding of prepared transactions." which
makes it even more clear that the two-phase is a slot option. The
options are named similarly in pg_create_logical_replication_slot API
and during CREATE SUBSCRIPTION, so, to some level, there is a
consistency in naming of these options across all APIs/tools. But,
their usage in a tool like pg_recvlogical could be perceived
differently as well, so it is also okay to consider naming them
differently.
Either name is fine for me, but I have a concern for the description. Now the
documentation says:
```
-t
--two-phase
Enables decoding of prepared transactions. This option may only be specified with --create-slot.
```
If we clarify the option is aimed for the slot, should we follow the
description in the protocol.sgml? I.e.,
```
-t
--two-phase
the slot supports decoding of two-phase commit. This option may only be specified with --create-slot.
```
Best regards,
Hayato Kuroda
FUJITSU LIMITED
On 14.06.25 07:26, Amit Kapila wrote:
On Sat, Jun 14, 2025 at 3:11 AM Masahiko Sawada <sawada.mshk@gmail.com> wrote:
On Thu, Jun 12, 2025 at 10:42 PM Peter Eisentraut <peter@eisentraut.org> wrote:
- The <option>--two-phase</option> and <option>--falover</option> options + The <option>--two-phase</option> and <option>--failover</option> optionsThank you for the report and the patch! Pushed.
I wonder if the option name --failover is ideal. To me, it sounds like
an action "do a failover!". Also consider that pg_recvlogical has other
action options such as --start and --create-slot, so it sounds a bit
like those.Fair point.
Maybe something like --enable-failover would be better?
Sounds better, but probably the --two-phase option has the same issue?
Ideally, we should change both to maintain consistency across various
slot options. OTOH, as we have already described these options as: "
The --two-phase and --failover options can be specified with
--create-slot.", it is clear that these are slot options. The previous
version docs have a description: "The --two-phase can be specified
with --create-slot to enable decoding of prepared transactions." which
makes it even more clear that the two-phase is a slot option. The
options are named similarly in pg_create_logical_replication_slot API
and during CREATE SUBSCRIPTION, so, to some level, there is a
consistency in naming of these options across all APIs/tools. But,
their usage in a tool like pg_recvlogical could be perceived
differently as well, so it is also okay to consider naming them
differently.
Also note that we have a new pg_createsubscriber --enable-two-phase.
It would be nice if there was more consistency between similar/related
tools.
On Tue, Jun 17, 2025 at 12:59 AM Peter Eisentraut <peter@eisentraut.org> wrote:
On 14.06.25 07:26, Amit Kapila wrote:
On Sat, Jun 14, 2025 at 3:11 AM Masahiko Sawada <sawada.mshk@gmail.com> wrote:
On Thu, Jun 12, 2025 at 10:42 PM Peter Eisentraut <peter@eisentraut.org> wrote:
- The <option>--two-phase</option> and <option>--falover</option> options + The <option>--two-phase</option> and <option>--failover</option> optionsThank you for the report and the patch! Pushed.
I wonder if the option name --failover is ideal. To me, it sounds like
an action "do a failover!". Also consider that pg_recvlogical has other
action options such as --start and --create-slot, so it sounds a bit
like those.Fair point.
Maybe something like --enable-failover would be better?
Sounds better, but probably the --two-phase option has the same issue?
Ideally, we should change both to maintain consistency across various
slot options. OTOH, as we have already described these options as: "
The --two-phase and --failover options can be specified with
--create-slot.", it is clear that these are slot options. The previous
version docs have a description: "The --two-phase can be specified
with --create-slot to enable decoding of prepared transactions." which
makes it even more clear that the two-phase is a slot option. The
options are named similarly in pg_create_logical_replication_slot API
and during CREATE SUBSCRIPTION, so, to some level, there is a
consistency in naming of these options across all APIs/tools. But,
their usage in a tool like pg_recvlogical could be perceived
differently as well, so it is also okay to consider naming them
differently.Also note that we have a new pg_createsubscriber --enable-two-phase.
Yeah, I also noticed the precedent.
It would be nice if there was more consistency between similar/related
tools.
I've attached the patch. Feedback is very welcome.
Regards,
--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com
Attachments:
v1-0001-pg_recvlogical-Rename-two-phase-and-failover-opti.patchapplication/octet-stream; name=v1-0001-pg_recvlogical-Rename-two-phase-and-failover-opti.patchDownload
From 53a0644f71c6c9eb87efda16c6826445695e7a14 Mon Sep 17 00:00:00 2001
From: Masahiko Sawada <sawada.mshk@gmail.com>
Date: Tue, 17 Jun 2025 11:02:54 -0700
Subject: [PATCH v1] pg_recvlogical: Rename --two-phase and --failover options.
This commit renames --two-phase and --failover options to
--enable-two-phase and --enable-failover, respectively. The new names
distinguish these enabling options from action options like --start
and --create-slot, while clearly indicating their purpose to enable
specific logical slot features.
No back-patch to back branches as it could break the exsiting tools.
Author: Peter Eisentraut <peter@eisentraut.org>
Reviewed-by:
Discussion: https://postgr.es/m/a28f66df-1354-4709-8d63-932ded4cac35@eisentraut.org
---
doc/src/sgml/logicaldecoding.sgml | 2 +-
doc/src/sgml/ref/pg_recvlogical.sgml | 8 ++++----
src/bin/pg_basebackup/pg_recvlogical.c | 18 +++++++++---------
src/bin/pg_basebackup/t/030_pg_recvlogical.pl | 6 +++---
4 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/doc/src/sgml/logicaldecoding.sgml b/doc/src/sgml/logicaldecoding.sgml
index dd9e83b08ea..00f1d1fc01d 100644
--- a/doc/src/sgml/logicaldecoding.sgml
+++ b/doc/src/sgml/logicaldecoding.sgml
@@ -169,7 +169,7 @@ COMMIT 693
$ pg_recvlogical -d postgres --slot=test --drop-slot
Example 2:
-$ pg_recvlogical -d postgres --slot=test --create-slot --two-phase
+$ pg_recvlogical -d postgres --slot=test --create-slot --enable-two-phase
$ pg_recvlogical -d postgres --slot=test --start -f -
<keycombo action="simul"><keycap>Control</keycap><keycap>Z</keycap></keycombo>
$ psql -d postgres -c "BEGIN;INSERT INTO data(data) VALUES('5');PREPARE TRANSACTION 'test';"
diff --git a/doc/src/sgml/ref/pg_recvlogical.sgml b/doc/src/sgml/ref/pg_recvlogical.sgml
index 63a45c7018a..767d087be07 100644
--- a/doc/src/sgml/ref/pg_recvlogical.sgml
+++ b/doc/src/sgml/ref/pg_recvlogical.sgml
@@ -79,8 +79,8 @@ PostgreSQL documentation
</para>
<para>
- The <option>--two-phase</option> and <option>--failover</option> options
- can be specified with <option>--create-slot</option>.
+ The <option>--enable-two-phase</option> and <option>--enable-failover</option>
+ options can be specified with <option>--create-slot</option>.
</para>
</listitem>
</varlistentry>
@@ -166,7 +166,7 @@ PostgreSQL documentation
</varlistentry>
<varlistentry>
- <term><option>--failover</option></term>
+ <term><option>--enable-failover</option></term>
<listitem>
<para>
Enables the slot to be synchronized to the standbys. This option may
@@ -300,7 +300,7 @@ PostgreSQL documentation
<varlistentry>
<term><option>-t</option></term>
- <term><option>--two-phase</option></term>
+ <term><option>--enable-two-phase</option></term>
<listitem>
<para>
Enables decoding of prepared transactions. This option may only be specified with
diff --git a/src/bin/pg_basebackup/pg_recvlogical.c b/src/bin/pg_basebackup/pg_recvlogical.c
index e6810efe5f0..5c169563d86 100644
--- a/src/bin/pg_basebackup/pg_recvlogical.c
+++ b/src/bin/pg_basebackup/pg_recvlogical.c
@@ -41,8 +41,8 @@ typedef enum
/* Global Options */
static char *outfile = NULL;
static int verbose = 0;
-static bool two_phase = false;
-static bool failover = false;
+static bool two_phase = false; /* enable-two-phase option */
+static bool failover = false; /* enable-failover option */
static int noloop = 0;
static int standby_message_timeout = 10 * 1000; /* 10 sec = default */
static int fsync_interval = 10 * 1000; /* 10 sec = default */
@@ -89,9 +89,9 @@ usage(void)
printf(_(" --drop-slot drop the replication slot (for the slot's name see --slot)\n"));
printf(_(" --start start streaming in a replication slot (for the slot's name see --slot)\n"));
printf(_("\nOptions:\n"));
- printf(_(" -E, --endpos=LSN exit after receiving the specified LSN\n"));
- printf(_(" --failover enable replication slot synchronization to standby servers when\n"
+ printf(_(" --enable-failover enable replication slot synchronization to standby servers when\n"
" creating a slot\n"));
+ printf(_(" -E, --endpos=LSN exit after receiving the specified LSN\n"));
printf(_(" -f, --file=FILE receive log into this file, - for stdout\n"));
printf(_(" -F --fsync-interval=SECS\n"
" time between fsyncs to the output file (default: %d)\n"), (fsync_interval / 1000));
@@ -105,7 +105,7 @@ usage(void)
printf(_(" -s, --status-interval=SECS\n"
" time between status packets sent to server (default: %d)\n"), (standby_message_timeout / 1000));
printf(_(" -S, --slot=SLOTNAME name of the logical replication slot\n"));
- printf(_(" -t, --two-phase enable decoding of prepared transactions when creating a slot\n"));
+ printf(_(" -t, --enable-two-phase enable decoding of prepared transactions when creating a slot\n"));
printf(_(" -v, --verbose output verbose messages\n"));
printf(_(" -V, --version output version information, then exit\n"));
printf(_(" -?, --help show this help, then exit\n"));
@@ -698,9 +698,9 @@ main(int argc, char **argv)
{"file", required_argument, NULL, 'f'},
{"fsync-interval", required_argument, NULL, 'F'},
{"no-loop", no_argument, NULL, 'n'},
- {"failover", no_argument, NULL, 5},
+ {"enable-failover", no_argument, NULL, 5},
+ {"enable-two-phase", no_argument, NULL, 't'},
{"verbose", no_argument, NULL, 'v'},
- {"two-phase", no_argument, NULL, 't'},
{"version", no_argument, NULL, 'V'},
{"help", no_argument, NULL, '?'},
/* connection options */
@@ -928,14 +928,14 @@ main(int argc, char **argv)
{
if (two_phase)
{
- pg_log_error("--two-phase may only be specified with --create-slot");
+ pg_log_error("--enable-two-phase may only be specified with --create-slot");
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
exit(1);
}
if (failover)
{
- pg_log_error("--failover may only be specified with --create-slot");
+ pg_log_error("--enable-failover may only be specified with --create-slot");
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
exit(1);
}
diff --git a/src/bin/pg_basebackup/t/030_pg_recvlogical.pl b/src/bin/pg_basebackup/t/030_pg_recvlogical.pl
index c82e78847b3..381c1ab92cf 100644
--- a/src/bin/pg_basebackup/t/030_pg_recvlogical.pl
+++ b/src/bin/pg_basebackup/t/030_pg_recvlogical.pl
@@ -90,7 +90,7 @@ $node->command_ok(
'--slot' => 'test',
'--dbname' => $node->connstr('postgres'),
'--create-slot',
- '--two-phase',
+ '--enable-two-phase',
],
'slot with two-phase created');
@@ -110,7 +110,7 @@ $node->command_fails(
'--dbname' => $node->connstr('postgres'),
'--start',
'--endpos' => $nextlsn,
- '--two-phase', '--no-loop',
+ '--enable-two-phase', '--no-loop',
'--file' => '-',
],
'incorrect usage');
@@ -142,7 +142,7 @@ $node->command_ok(
'--slot' => 'test',
'--dbname' => $node->connstr('postgres'),
'--create-slot',
- '--failover',
+ '--enable-failover',
],
'slot with failover created');
--
2.43.5
On 17.06.25 20:19, Masahiko Sawada wrote:
Ideally, we should change both to maintain consistency across various
slot options. OTOH, as we have already described these options as: "
The --two-phase and --failover options can be specified with
--create-slot.", it is clear that these are slot options. The previous
version docs have a description: "The --two-phase can be specified
with --create-slot to enable decoding of prepared transactions." which
makes it even more clear that the two-phase is a slot option. The
options are named similarly in pg_create_logical_replication_slot API
and during CREATE SUBSCRIPTION, so, to some level, there is a
consistency in naming of these options across all APIs/tools. But,
their usage in a tool like pg_recvlogical could be perceived
differently as well, so it is also okay to consider naming them
differently.Also note that we have a new pg_createsubscriber --enable-two-phase.
Yeah, I also noticed the precedent.
It would be nice if there was more consistency between similar/related
tools.I've attached the patch. Feedback is very welcome.
This looks fine to me, but I would keep the old name --two-phase as
well. You could mark it as deprecated. No need to make a hard break.
On 22.06.25 15:38, Peter Eisentraut wrote:
On 17.06.25 20:19, Masahiko Sawada wrote:
Ideally, we should change both to maintain consistency across various
slot options. OTOH, as we have already described these options as: "
The --two-phase and --failover options can be specified with
--create-slot.", it is clear that these are slot options. The previous
version docs have a description: "The --two-phase can be specified
with --create-slot to enable decoding of prepared transactions." which
makes it even more clear that the two-phase is a slot option. The
options are named similarly in pg_create_logical_replication_slot API
and during CREATE SUBSCRIPTION, so, to some level, there is a
consistency in naming of these options across all APIs/tools. But,
their usage in a tool like pg_recvlogical could be perceived
differently as well, so it is also okay to consider naming them
differently.Also note that we have a new pg_createsubscriber --enable-two-phase.
Yeah, I also noticed the precedent.
It would be nice if there was more consistency between similar/related
tools.I've attached the patch. Feedback is very welcome.
This looks fine to me, but I would keep the old name --two-phase as
well. You could mark it as deprecated. No need to make a hard break.
I have committed your patch with this change.
On Mon, Jun 30, 2025 at 2:37 AM Peter Eisentraut <peter@eisentraut.org> wrote:
On 22.06.25 15:38, Peter Eisentraut wrote:
On 17.06.25 20:19, Masahiko Sawada wrote:
Ideally, we should change both to maintain consistency across various
slot options. OTOH, as we have already described these options as: "
The --two-phase and --failover options can be specified with
--create-slot.", it is clear that these are slot options. The previous
version docs have a description: "The --two-phase can be specified
with --create-slot to enable decoding of prepared transactions." which
makes it even more clear that the two-phase is a slot option. The
options are named similarly in pg_create_logical_replication_slot API
and during CREATE SUBSCRIPTION, so, to some level, there is a
consistency in naming of these options across all APIs/tools. But,
their usage in a tool like pg_recvlogical could be perceived
differently as well, so it is also okay to consider naming them
differently.Also note that we have a new pg_createsubscriber --enable-two-phase.
Yeah, I also noticed the precedent.
It would be nice if there was more consistency between similar/related
tools.I've attached the patch. Feedback is very welcome.
This looks fine to me, but I would keep the old name --two-phase as
well. You could mark it as deprecated. No need to make a hard break.I have committed your patch with this change.
Thank you for taking over the patch! I was unable to work on this last
week due to other work.
Regards,
--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com