aboutsummaryrefslogtreecommitdiff
path: root/src/backend/replication/walreceiver.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/replication/walreceiver.c')
-rw-r--r--src/backend/replication/walreceiver.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c
index 77360f1524b..b4641143339 100644
--- a/src/backend/replication/walreceiver.c
+++ b/src/backend/replication/walreceiver.c
@@ -73,6 +73,7 @@
/* GUC variables */
+bool wal_receiver_create_temp_slot;
int wal_receiver_status_interval;
int wal_receiver_timeout;
bool hot_standby_feedback;
@@ -169,6 +170,7 @@ WalReceiverMain(void)
char conninfo[MAXCONNINFO];
char *tmp_conninfo;
char slotname[NAMEDATALEN];
+ bool is_temp_slot;
XLogRecPtr startpoint;
TimeLineID startpointTLI;
TimeLineID primaryTLI;
@@ -230,6 +232,7 @@ WalReceiverMain(void)
walrcv->ready_to_display = false;
strlcpy(conninfo, (char *) walrcv->conninfo, MAXCONNINFO);
strlcpy(slotname, (char *) walrcv->slotname, NAMEDATALEN);
+ is_temp_slot = walrcv->is_temp_slot;
startpoint = walrcv->receiveStart;
startpointTLI = walrcv->receiveStartTLI;
@@ -346,6 +349,44 @@ WalReceiverMain(void)
WalRcvFetchTimeLineHistoryFiles(startpointTLI, primaryTLI);
/*
+ * Create temporary replication slot if no slot name is configured or
+ * the slot from the previous run was temporary, unless
+ * wal_receiver_create_temp_slot is disabled. We also need to handle
+ * the case where the previous run used a temporary slot but
+ * wal_receiver_create_temp_slot was changed in the meantime. In that
+ * case, we delete the old slot name in shared memory. (This would
+ * all be a bit easier if we just didn't copy the slot name into
+ * shared memory, since we won't need it again later, but then we
+ * can't see the slot name in the stats views.)
+ */
+ if (slotname[0] == '\0' || is_temp_slot)
+ {
+ bool changed = false;
+
+ if (wal_receiver_create_temp_slot)
+ {
+ snprintf(slotname, sizeof(slotname),
+ "pg_walreceiver_%d", walrcv_get_backend_pid(wrconn));
+
+ walrcv_create_slot(wrconn, slotname, true, 0, NULL);
+ changed = true;
+ }
+ else if (slotname[0] != '\0')
+ {
+ slotname[0] = '\0';
+ changed = true;
+ }
+
+ if (changed)
+ {
+ SpinLockAcquire(&walrcv->mutex);
+ strlcpy(walrcv->slotname, slotname, NAMEDATALEN);
+ walrcv->is_temp_slot = wal_receiver_create_temp_slot;
+ SpinLockRelease(&walrcv->mutex);
+ }
+ }
+
+ /*
* Start streaming.
*
* We'll try to start at the requested starting point and timeline,