|
73 | 73 |
|
74 | 74 |
|
75 | 75 | /* GUC variables */
|
| 76 | +bool wal_receiver_create_temp_slot; |
76 | 77 | int wal_receiver_status_interval;
|
77 | 78 | int wal_receiver_timeout;
|
78 | 79 | bool hot_standby_feedback;
|
@@ -169,6 +170,7 @@ WalReceiverMain(void)
|
169 | 170 | char conninfo[MAXCONNINFO];
|
170 | 171 | char *tmp_conninfo;
|
171 | 172 | char slotname[NAMEDATALEN];
|
| 173 | + bool is_temp_slot; |
172 | 174 | XLogRecPtr startpoint;
|
173 | 175 | TimeLineID startpointTLI;
|
174 | 176 | TimeLineID primaryTLI;
|
@@ -230,6 +232,7 @@ WalReceiverMain(void)
|
230 | 232 | walrcv->ready_to_display = false;
|
231 | 233 | strlcpy(conninfo, (char *) walrcv->conninfo, MAXCONNINFO);
|
232 | 234 | strlcpy(slotname, (char *) walrcv->slotname, NAMEDATALEN);
|
| 235 | + is_temp_slot = walrcv->is_temp_slot; |
233 | 236 | startpoint = walrcv->receiveStart;
|
234 | 237 | startpointTLI = walrcv->receiveStartTLI;
|
235 | 238 |
|
@@ -345,6 +348,44 @@ WalReceiverMain(void)
|
345 | 348 | */
|
346 | 349 | WalRcvFetchTimeLineHistoryFiles(startpointTLI, primaryTLI);
|
347 | 350 |
|
| 351 | + /* |
| 352 | + * Create temporary replication slot if no slot name is configured or |
| 353 | + * the slot from the previous run was temporary, unless |
| 354 | + * wal_receiver_create_temp_slot is disabled. We also need to handle |
| 355 | + * the case where the previous run used a temporary slot but |
| 356 | + * wal_receiver_create_temp_slot was changed in the meantime. In that |
| 357 | + * case, we delete the old slot name in shared memory. (This would |
| 358 | + * all be a bit easier if we just didn't copy the slot name into |
| 359 | + * shared memory, since we won't need it again later, but then we |
| 360 | + * can't see the slot name in the stats views.) |
| 361 | + */ |
| 362 | + if (slotname[0] == '\0' || is_temp_slot) |
| 363 | + { |
| 364 | + bool changed = false; |
| 365 | + |
| 366 | + if (wal_receiver_create_temp_slot) |
| 367 | + { |
| 368 | + snprintf(slotname, sizeof(slotname), |
| 369 | + "pg_walreceiver_%d", walrcv_get_backend_pid(wrconn)); |
| 370 | + |
| 371 | + walrcv_create_slot(wrconn, slotname, true, 0, NULL); |
| 372 | + changed = true; |
| 373 | + } |
| 374 | + else if (slotname[0] != '\0') |
| 375 | + { |
| 376 | + slotname[0] = '\0'; |
| 377 | + changed = true; |
| 378 | + } |
| 379 | + |
| 380 | + if (changed) |
| 381 | + { |
| 382 | + SpinLockAcquire(&walrcv->mutex); |
| 383 | + strlcpy(walrcv->slotname, slotname, NAMEDATALEN); |
| 384 | + walrcv->is_temp_slot = wal_receiver_create_temp_slot; |
| 385 | + SpinLockRelease(&walrcv->mutex); |
| 386 | + } |
| 387 | + } |
| 388 | + |
348 | 389 | /*
|
349 | 390 | * Start streaming.
|
350 | 391 | *
|
|
0 commit comments