|
15 | 15 | * WalRcv->receivedUpto variable in shared memory, to inform the startup
|
16 | 16 | * process of how far it can proceed with XLOG replay.
|
17 | 17 | *
|
| 18 | + * A WAL receiver cannot directly load GUC parameters used when establishing |
| 19 | + * its connection to the primary. Instead it relies on parameter values |
| 20 | + * that are passed down by the startup process when streaming is requested. |
| 21 | + * This applies, for example, to the replication slot and the connection |
| 22 | + * string to be used for the connection with the primary. |
| 23 | + * |
18 | 24 | * If the primary server ends streaming, but doesn't disconnect, walreceiver
|
19 | 25 | * goes into "waiting" mode, and waits for the startup process to give new
|
20 | 26 | * instructions. The startup process will treat that the same as
|
|
73 | 79 | #include "utils/timestamp.h"
|
74 | 80 |
|
75 | 81 |
|
76 |
| -/* GUC variables */ |
77 |
| -bool wal_receiver_create_temp_slot; |
| 82 | +/* |
| 83 | + * GUC variables. (Other variables that affect walreceiver are in xlog.c |
| 84 | + * because they're passed down from the startup process, for better |
| 85 | + * synchronization.) |
| 86 | + */ |
78 | 87 | int wal_receiver_status_interval;
|
79 | 88 | int wal_receiver_timeout;
|
80 | 89 | bool hot_standby_feedback;
|
@@ -236,6 +245,12 @@ WalReceiverMain(void)
|
236 | 245 | startpoint = walrcv->receiveStart;
|
237 | 246 | startpointTLI = walrcv->receiveStartTLI;
|
238 | 247 |
|
| 248 | + /* |
| 249 | + * At most one of is_temp_slot and slotname can be set; otherwise, |
| 250 | + * RequestXLogStreaming messed up. |
| 251 | + */ |
| 252 | + Assert(!is_temp_slot || (slotname[0] == '\0')); |
| 253 | + |
239 | 254 | /* Initialise to a sanish value */
|
240 | 255 | walrcv->lastMsgSendTime =
|
241 | 256 | walrcv->lastMsgReceiptTime = walrcv->latestWalEndTime = now;
|
@@ -349,42 +364,21 @@ WalReceiverMain(void)
|
349 | 364 | WalRcvFetchTimeLineHistoryFiles(startpointTLI, primaryTLI);
|
350 | 365 |
|
351 | 366 | /*
|
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.) |
| 367 | + * Create temporary replication slot if requested, and update slot |
| 368 | + * name in shared memory. (Note the slot name cannot already be set |
| 369 | + * in this case.) |
361 | 370 | */
|
362 |
| - if (slotname[0] == '\0' || is_temp_slot) |
| 371 | + if (is_temp_slot) |
363 | 372 | {
|
364 |
| - bool changed = false; |
365 |
| - |
366 |
| - if (wal_receiver_create_temp_slot) |
367 |
| - { |
368 |
| - snprintf(slotname, sizeof(slotname), |
369 |
| - "pg_walreceiver_%lld", |
370 |
| - (long long int) walrcv_get_backend_pid(wrconn)); |
| 373 | + snprintf(slotname, sizeof(slotname), |
| 374 | + "pg_walreceiver_%lld", |
| 375 | + (long long int) walrcv_get_backend_pid(wrconn)); |
371 | 376 |
|
372 |
| - walrcv_create_slot(wrconn, slotname, true, 0, NULL); |
373 |
| - changed = true; |
374 |
| - } |
375 |
| - else if (slotname[0] != '\0') |
376 |
| - { |
377 |
| - slotname[0] = '\0'; |
378 |
| - changed = true; |
379 |
| - } |
| 377 | + walrcv_create_slot(wrconn, slotname, true, 0, NULL); |
380 | 378 |
|
381 |
| - if (changed) |
382 |
| - { |
383 |
| - SpinLockAcquire(&walrcv->mutex); |
384 |
| - strlcpy(walrcv->slotname, slotname, NAMEDATALEN); |
385 |
| - walrcv->is_temp_slot = wal_receiver_create_temp_slot; |
386 |
| - SpinLockRelease(&walrcv->mutex); |
387 |
| - } |
| 379 | + SpinLockAcquire(&walrcv->mutex); |
| 380 | + strlcpy(walrcv->slotname, slotname, NAMEDATALEN); |
| 381 | + SpinLockRelease(&walrcv->mutex); |
388 | 382 | }
|
389 | 383 |
|
390 | 384 | /*
|
|
0 commit comments