Hi,
This is my very first message to this mailing list. Please advise if I am
making any mistakes in the procedure.
The attached patch enables pg_recvlogical to create a temporary slot.
What is the next step in the process to get this change into official
postgres?
Thanks,
Torsten
diff --git a/src/bin/pg_basebackup/pg_recvlogical.c b/src/bin/pg_basebackup/pg_recvlogical.c
index 3db520ed38..22ab96129c 100644
--- a/src/bin/pg_basebackup/pg_recvlogical.c
+++ b/src/bin/pg_basebackup/pg_recvlogical.c
@@ -50,6 +50,7 @@ static int fsync_interval = 10 * 1000; /* 10 sec = default */
static XLogRecPtr startpos = InvalidXLogRecPtr;
static XLogRecPtr endpos = InvalidXLogRecPtr;
static bool do_create_slot = false;
+static bool slot_is_temporary = false;
static bool slot_exists_ok = false;
static bool do_start_slot = false;
static bool do_drop_slot = false;
@@ -104,6 +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(_(" --temporary-slot the slot created by --create-slot exists until the connection is dropped\n"));
printf(_(" -t, --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"));
@@ -227,10 +229,24 @@ StreamLogicalLog(void)
* Connect in replication mode to the server
*/
if (!conn)
+ {
conn = GetConnection();
- if (!conn)
- /* Error message already written in GetConnection() */
- return;
+ if (!conn)
+ /* Error message already written in GetConnection() */
+ return;
+
+ /* Recreate a replication slot. */
+ if (do_create_slot && slot_is_temporary)
+ {
+ if (verbose)
+ pg_log_info("recreating replication slot \"%s\"", replication_slot);
+
+ if (!CreateReplicationSlot(conn, replication_slot, plugin, slot_is_temporary,
+ false, false, slot_exists_ok, two_phase))
+ goto error;
+ startpos = InvalidXLogRecPtr;
+ }
+ }
/*
* Start the replication
@@ -719,6 +735,7 @@ main(int argc, char **argv)
{"start", no_argument, NULL, 2},
{"drop-slot", no_argument, NULL, 3},
{"if-not-exists", no_argument, NULL, 4},
+ {"temporary-slot", no_argument, NULL, 5},
{NULL, 0, NULL, 0}
};
int c;
@@ -847,6 +864,9 @@ main(int argc, char **argv)
case 4:
slot_exists_ok = true;
break;
+ case 5:
+ slot_is_temporary = true;
+ break;
default:
/* getopt_long already emitted a complaint */
@@ -981,7 +1001,7 @@ main(int argc, char **argv)
if (verbose)
pg_log_info("creating replication slot \"%s\"", replication_slot);
- if (!CreateReplicationSlot(conn, replication_slot, plugin, false,
+ if (!CreateReplicationSlot(conn, replication_slot, plugin, slot_is_temporary,
false, false, slot_exists_ok, two_phase))
exit(1);
startpos = InvalidXLogRecPtr;