From: Sergei Kornilov <sk@zsrv.org>
To: Michael Paquier <michael@paquier.xyz>
To: Peter Eisentraut <peter@eisentraut.org>
Cc: Postgres hackers <pgsql-hackers@lists.postgresql.org>
Cc: Andres Freund <andres@anarazel.de>
Subject: Re: pgsql: walreceiver uses a temporary replication slot by default
Date: Wed, 22 Jan 2020 18:58:46 +0300
Message-ID: <753391579708726@iva3-77ae5995f07f.qloud-c.yandex.net> (raw)
In-Reply-To: <20200122055510.GH174860@paquier.xyz>
References: <E1irMhK-00021w-9z@gemulon.postgresql.org>
<20200122055510.GH174860@paquier.xyz>
Hello
> In short, the following things:
> - wal_receiver_create_temp_slot should be made PGC_POSTMASTER,
> similarly to primary_slot_name and primary_conninfo.
> - WalReceiverMain() should not load the parameter from the GUC context
> by itself.
> - RequestXLogStreaming(), called by the startup process, should be in
> charge of defining if a temp slot should be used or not.
I would like to cross-post here a patch with such changes that I posted in "allow online change primary_conninfo" thread.
This thread is more appropriate for discussion about wal_receiver_create_temp_slot.
PS: I posted this patch in both threads mostly to make cfbot happy.
regards, Sergei
Attachments:0001_v7_move_temp_slot_logic_to_startup.patch (text/x-diff, 6.2K) downloaddiff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgmlindex e07dc01e80..14992a08d7 100644--- a/doc/src/sgml/config.sgml+++ b/doc/src/sgml/config.sgml@@ -4137,9 +4137,7 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
has been configured (using <xref linkend="guc-primary-slot-name"/>).
The default is on. The only reason to turn this off would be if the
remote instance is currently out of available replication slots. This
- parameter can only be set in the <filename>postgresql.conf</filename>- file or on the server command line. Changes only take effect when the- WAL receiver process starts a new connection.+ parameter can only be set at server start.
</para>
</listitem>
</varlistentry>
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.cindex 7f4f784c0e..55e9294ae3 100644--- a/src/backend/access/transam/xlog.c+++ b/src/backend/access/transam/xlog.c@@ -283,6 +283,7 @@ bool StandbyModeRequested = false;
char *PrimaryConnInfo = NULL;
char *PrimarySlotName = NULL;
char *PromoteTriggerFile = NULL;
+bool wal_receiver_create_temp_slot = true;
/* are we currently in standby mode? */
bool StandbyMode = false;
diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.cindex a5e85d32f3..264b544194 100644--- a/src/backend/replication/walreceiver.c+++ b/src/backend/replication/walreceiver.c@@ -73,7 +73,6 @@
/* GUC variables */
-bool wal_receiver_create_temp_slot;
int wal_receiver_status_interval;
int wal_receiver_timeout;
bool hot_standby_feedback;
@@ -349,42 +348,23 @@ 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+ * Create temporary replication slot if requested. In that+ * case, we update 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)+ if (is_temp_slot)
{
- bool changed = false;+ snprintf(slotname, sizeof(slotname),+ "pg_walreceiver_%lld",+ (long long int) walrcv_get_backend_pid(wrconn));- if (wal_receiver_create_temp_slot)- {- snprintf(slotname, sizeof(slotname),- "pg_walreceiver_%lld",- (long long int) 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;- }+ walrcv_create_slot(wrconn, slotname, true, 0, NULL);- if (changed)- {- SpinLockAcquire(&walrcv->mutex);- strlcpy(walrcv->slotname, slotname, NAMEDATALEN);- walrcv->is_temp_slot = wal_receiver_create_temp_slot;- SpinLockRelease(&walrcv->mutex);- }+ SpinLockAcquire(&walrcv->mutex);+ strlcpy(walrcv->slotname, slotname, NAMEDATALEN);+ SpinLockRelease(&walrcv->mutex);
}
/*
diff --git a/src/backend/replication/walreceiverfuncs.c b/src/backend/replication/walreceiverfuncs.cindex 89c903e45a..a36bc83d2c 100644--- a/src/backend/replication/walreceiverfuncs.c+++ b/src/backend/replication/walreceiverfuncs.c@@ -248,10 +248,16 @@ RequestXLogStreaming(TimeLineID tli, XLogRecPtr recptr, const char *conninfo,
else
walrcv->conninfo[0] = '\0';
- if (slotname != NULL)+ if (slotname != NULL && slotname[0] != '\0')+ {
strlcpy((char *) walrcv->slotname, slotname, NAMEDATALEN);
+ walrcv->is_temp_slot = false;+ }
else
+ {
walrcv->slotname[0] = '\0';
+ walrcv->is_temp_slot = wal_receiver_create_temp_slot;+ }
if (walrcv->walRcvState == WALRCV_STOPPED)
{
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.cindex 9f179a9129..c4b36eb2ad 100644--- a/src/backend/utils/misc/guc.c+++ b/src/backend/utils/misc/guc.c@@ -1994,7 +1994,7 @@ static struct config_bool ConfigureNamesBool[] =
},
{
- {"wal_receiver_create_temp_slot", PGC_SIGHUP, REPLICATION_STANDBY,+ {"wal_receiver_create_temp_slot", PGC_POSTMASTER, REPLICATION_STANDBY,
gettext_noop("Sets whether a WAL receiver should create a temporary replication slot if no permanent slot is configured."),
},
&wal_receiver_create_temp_slot,
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sampleindex e1048c0047..4454407b7c 100644--- a/src/backend/utils/misc/postgresql.conf.sample+++ b/src/backend/utils/misc/postgresql.conf.sample@@ -322,6 +322,7 @@
# when reading streaming WAL;
# -1 allows indefinite delay
#wal_receiver_create_temp_slot = on # create temp slot if primary_slot_name not set
+ # (change requires restart)
#wal_receiver_status_interval = 10s # send replies at least this often
# 0 disables
#hot_standby_feedback = off # send info from standby to prevent
diff --git a/src/include/access/xlog.h b/src/include/access/xlog.hindex 98b033fc20..12362421d7 100644--- a/src/include/access/xlog.h+++ b/src/include/access/xlog.h@@ -129,6 +129,7 @@ extern int recoveryTargetAction;
extern int recovery_min_apply_delay;
extern char *PrimaryConnInfo;
extern char *PrimarySlotName;
+extern bool wal_receiver_create_temp_slot;
/* indirectly set via GUC system */
extern TransactionId recoveryTargetXid;
diff --git a/src/include/replication/walreceiver.h b/src/include/replication/walreceiver.hindex e08afc6548..9d25a7f91b 100644--- a/src/include/replication/walreceiver.h+++ b/src/include/replication/walreceiver.h@@ -23,7 +23,6 @@
#include "utils/tuplestore.h"
/* user-settable parameters */
-extern bool wal_receiver_create_temp_slot;
extern int wal_receiver_status_interval;
extern int wal_receiver_timeout;
extern bool hot_standby_feedback;
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: sk@zsrv.org, michael@paquier.xyz, peter@eisentraut.org, pgsql-hackers@lists.postgresql.org, andres@anarazel.de
Subject: Re: pgsql: walreceiver uses a temporary replication slot by default
In-Reply-To: <753391579708726@iva3-77ae5995f07f.qloud-c.yandex.net>
References: <E1irMhK-00021w-9z@gemulon.postgresql.org> <20200122055510.GH174860@paquier.xyz> <753391579708726@iva3-77ae5995f07f.qloud-c.yandex.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox