Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j3srW-0000bt-Hw for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Feb 2020 02:43:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j3srV-0006aL-9h for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Feb 2020 02:43:49 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j3srU-0006aE-Oy for pgsql-hackers@lists.postgresql.org; Tue, 18 Feb 2020 02:43:49 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j3srR-0003f1-Iz for pgsql-hackers@lists.postgresql.org; Tue, 18 Feb 2020 02:43:47 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 625EF21F55; Mon, 17 Feb 2020 21:43:44 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 17 Feb 2020 21:43:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm1; bh=wQ2BTLzfBhhxD+Ma/bNoRK5P3I3 Fv/KY4nYBXfwFvCY=; b=mWvSOQs5rbramtG9LdCLM9t6IuGlSC7MlzW0hIEINxM v3bFabH3pNicu3qiDlZpdxpTHONNQG8qKepYvynbCFxkKBzQxsxCi1UuVUjVwDAX is4KeV5qCVizQW7WwTpCmtyne1zGziSLispvfrXh4LwxfJ9vBwgfIkqC9GED1EW+ 7EnmkZYUERfxi+cxUTOuNxRtpSMJLsoVtjaX9665xbge/CU4zeQJIzjENl3Y6fYf b2d0A+KQxwOj2jx5HtzSJCsC5jETeFRZyvcKxHs4yuD9BB3pimUQxs/THyw+LM9G ji+R/sXlc6CrlLQBn3Au44kyUS/RRD/TfFueBgQX9yA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=wQ2BTL zfBhhxD+Ma/bNoRK5P3I3Fv/KY4nYBXfwFvCY=; b=m78OA3w3GRAhltCS2lMWrE f13twhdSIFIYAKaOQdl6rfu+utEcNaGA9er/nxQQqV3S/dyV7qmXaZQc0RajIFS6 Uh4YCokcNO8uD1b7ld1ub0ks1ExrsjspfZJR4ikziH6I7C+HVHZ0qWH7IP3qRHGU lWb8J5HaPeoprk4znqB0it2JhKLKIm1Ib30nDJv5JdKsjGnENPy5rkJRFNSjUjqT ADEvY0tA+IV2o7OsKQ/xvNLUTpYd/PZ79awm5IjHakqdJsSFu1yoE+2axNQYFGEe zP6utMJ6H5su7GDHb1HebZ/u/pakuu+hb8r8zHHojIbtuP5gx3BbhqBY0eOobP+g == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrjeejgdeglecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfg hrlhcuvffnffculdefhedmnecujfgurhepfffhvffukfhfgggtuggjsehgtderredttddv necuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesphgrqh huihgvrhdrgiihiieqnecuffhomhgrihhnpehsrghmphhlvgdrrghspdhpohhsthhgrhgv shhqlhdrohhrghenucfkphepudduuddruddtvddrudektddrudekheenucevlhhushhtvg hrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghq uhhivghrrdighiii X-ME-Proxy: Received: from paquier.xyz (ee0822lan1.rev.em-net.ne.jp [111.102.180.185]) by mail.messagingengine.com (Postfix) with ESMTPA id CC9423060C21; Mon, 17 Feb 2020 21:43:41 -0500 (EST) Date: Tue, 18 Feb 2020 11:43:38 +0900 From: Michael Paquier To: Sergei Kornilov Cc: Peter Eisentraut , Postgres hackers , Andres Freund Subject: Re: pgsql: walreceiver uses a temporary replication slot by default Message-ID: <20200218024338.GB4176@paquier.xyz> References: <20200122055510.GH174860@paquier.xyz> <753391579708726@iva3-77ae5995f07f.qloud-c.yandex.net> <20200216060314.GC97911@paquier.xyz> <15987771581947824@iva1-398527a32f9a.qloud-c.yandex.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="OaZoDhBhXzo6bW1J" Content-Disposition: inline In-Reply-To: <15987771581947824@iva1-398527a32f9a.qloud-c.yandex.net> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --OaZoDhBhXzo6bW1J Content-Type: multipart/mixed; boundary="uXxzq0nDebZQVNAZ" Content-Disposition: inline --uXxzq0nDebZQVNAZ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Feb 17, 2020 at 04:57:04PM +0300, Sergei Kornilov wrote: > Thank you, here is updated patch Thanks > I changed this comments because they describes behavior during > change value of wal_receiver_create_temp_slot. But yes, I need to > add some comments to RequestXLogStreaming. I have reworked that part, adding more comments about the use of GUC parameters when establishing the connection to the primary for a WAL receiver. And also I have added an extra comment to walreceiver.c about the use of GUcs in general, to avoid this stuff again in the future. There were some extra nits with the format of postgresql.conf.sample. >> As per the discussion done on this thread, let's also switch the >> parameter default to be disabled. >=20 > Done (my vote is also for disabling this option by default). We visibly tend to move in this direction, at least based on our discussion. Let's see where this leads. For now, I have registered this patch to next CF (https://commitfest.postgresql.org/27/2456/), with yourself as author and myself as reviewer, and then let's wait for mainly Peter E. and others for more input.=20 -- Michael --uXxzq0nDebZQVNAZ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-v3-change-wal_receiver_create_temp_slot.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h index 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; =20 /* indirectly set via GUC system */ extern TransactionId recoveryTargetXid; diff --git a/src/include/replication/walreceiver.h b/src/include/replicatio= n/walreceiver.h index e08afc6548..cf3e43128c 100644 --- a/src/include/replication/walreceiver.h +++ b/src/include/replication/walreceiver.h @@ -23,7 +23,6 @@ #include "utils/tuplestore.h" =20 /* 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; @@ -321,7 +320,8 @@ extern void ShutdownWalRcv(void); extern bool WalRcvStreaming(void); extern bool WalRcvRunning(void); extern void RequestXLogStreaming(TimeLineID tli, XLogRecPtr recptr, - const char *conninfo, const char *slotname); + const char *conninfo, const char *slotname, + bool create_temp_slot); extern XLogRecPtr GetWalRcvWriteRecPtr(XLogRecPtr *latestChunkStart, TimeL= ineID *receiveTLI); extern int GetReplicationApplyDelay(void); extern int GetReplicationTransferLatency(void); diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam= /xlog.c index 3813eadfb4..e0f3ed5c2a 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -283,6 +283,7 @@ bool StandbyModeRequested =3D false; char *PrimaryConnInfo =3D NULL; char *PrimarySlotName =3D NULL; char *PromoteTriggerFile =3D NULL; +bool wal_receiver_create_temp_slot =3D false; =20 /* are we currently in standby mode? */ bool StandbyMode =3D false; @@ -11901,7 +11902,7 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool= randAccess, } curFileTLI =3D tli; RequestXLogStreaming(tli, ptr, PrimaryConnInfo, - PrimarySlotName); + PrimarySlotName, wal_receiver_create_temp_slot); receivedUpto =3D 0; } =20 diff --git a/src/backend/replication/walreceiver.c b/src/backend/replicatio= n/walreceiver.c index 2ab15c3cbb..ff45482faa 100644 --- a/src/backend/replication/walreceiver.c +++ b/src/backend/replication/walreceiver.c @@ -15,6 +15,12 @@ * WalRcv->receivedUpto variable in shared memory, to inform the startup * process of how far it can proceed with XLOG replay. * + * WAL receivers cannot load directly GUC parameters used when establishing + * their connection to the primary, and rely on parameter values passed do= wn + * by the startup process when WAL streaming is requested. This applies + * to for example the replication slot creation and the connection string = to + * use for the connection with the primary. + * * If the primary server ends streaming, but doesn't disconnect, walreceiv= er * goes into "waiting" mode, and waits for the startup process to give new * instructions. The startup process will treat that the same as @@ -73,7 +79,6 @@ =20 =20 /* GUC variables */ -bool wal_receiver_create_temp_slot; int wal_receiver_status_interval; int wal_receiver_timeout; bool hot_standby_feedback; @@ -348,42 +353,23 @@ WalReceiverMain(void) WalRcvFetchTimeLineHistoryFiles(startpointTLI, primaryTLI); =20 /* - * 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] =3D=3D '\0' || is_temp_slot) + if (is_temp_slot) { - bool changed =3D false; + snprintf(slotname, sizeof(slotname), + "pg_walreceiver_%lld", + (long long int) walrcv_get_backend_pid(wrconn)); =20 - 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); =20 - walrcv_create_slot(wrconn, slotname, true, 0, NULL); - changed =3D true; - } - else if (slotname[0] !=3D '\0') - { - slotname[0] =3D '\0'; - changed =3D true; - } - - if (changed) - { - SpinLockAcquire(&walrcv->mutex); - strlcpy(walrcv->slotname, slotname, NAMEDATALEN); - walrcv->is_temp_slot =3D wal_receiver_create_temp_slot; - SpinLockRelease(&walrcv->mutex); - } + SpinLockAcquire(&walrcv->mutex); + strlcpy(walrcv->slotname, slotname, NAMEDATALEN); + SpinLockRelease(&walrcv->mutex); } =20 /* diff --git a/src/backend/replication/walreceiverfuncs.c b/src/backend/repli= cation/walreceiverfuncs.c index 89c903e45a..821680a857 100644 --- a/src/backend/replication/walreceiverfuncs.c +++ b/src/backend/replication/walreceiverfuncs.c @@ -215,13 +215,19 @@ ShutdownWalRcv(void) /* * Request postmaster to start walreceiver. * - * recptr indicates the position where streaming should begin, conninfo - * is a libpq connection string to use, and slotname is, optionally, the n= ame - * of a replication slot to acquire. + * "recptr" indicates the position where streaming should begin. "conninf= o" + * is a libpq connection string to use. "slotname" is, optionally, the na= me + * of a replication slot to acquire. "create_temp_slot" indicates to crea= te + * a temporary slot when no "slotname" is given. + * + * WAL receivers do not directly load GUC parameters used for the connecti= on + * to the primary, and rely on the values passed down by the caller of this + * routine instead. Hence, the addition of any new parameters should happ= en + * through this code path. */ void RequestXLogStreaming(TimeLineID tli, XLogRecPtr recptr, const char *connin= fo, - const char *slotname) + const char *slotname, bool create_temp_slot) { WalRcvData *walrcv =3D WalRcv; bool launch =3D false; @@ -248,10 +254,22 @@ RequestXLogStreaming(TimeLineID tli, XLogRecPtr recpt= r, const char *conninfo, else walrcv->conninfo[0] =3D '\0'; =20 + /* + * Use configured replication slot if present, and ignore the value + * of create_temp_slot as the slot name should be persistent. Otherwise, + * use create_temp_slot to determine whether this WAL receiver should + * create a temporary slot by itself and use it, or not. + */ if (slotname !=3D NULL) + { strlcpy((char *) walrcv->slotname, slotname, NAMEDATALEN); + walrcv->is_temp_slot =3D false; + } else + { walrcv->slotname[0] =3D '\0'; + walrcv->is_temp_slot =3D create_temp_slot; + } =20 if (walrcv->walRcvState =3D=3D WALRCV_STOPPED) { diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 8228e1f390..ec9cd3696c 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -2029,11 +2029,11 @@ static struct config_bool ConfigureNamesBool[] =3D }, =20 { - {"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 rep= lication slot if no permanent slot is configured."), }, &wal_receiver_create_temp_slot, - true, + false, NULL, NULL, NULL }, =20 diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/ut= ils/misc/postgresql.conf.sample index e1048c0047..1dd2a86567 100644 --- a/src/backend/utils/misc/postgresql.conf.sample +++ b/src/backend/utils/misc/postgresql.conf.sample @@ -321,7 +321,9 @@ #max_standby_streaming_delay =3D 30s # max delay before canceling queries # when reading streaming WAL; # -1 allows indefinite delay -#wal_receiver_create_temp_slot =3D on # create temp slot if primary_slot_n= ame not set +#wal_receiver_create_temp_slot =3D off # Create temp slot if primary_slot_= name + # is not set. + # (change requires restart) #wal_receiver_status_interval =3D 10s # send replies at least this often # 0 disables #hot_standby_feedback =3D off # send info from standby to prevent diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index c1128f89ec..683d87c491 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -4140,11 +4140,7 @@ ANY num_sync ( ). - The default is on. The only reason to turn this off would be if t= he - remote instance is currently out of available replication slots. = This - parameter can only be set in the postgresql.conf - file or on the server command line. Changes only take effect when= the - WAL receiver process starts a new connection. + The default is off. This parameter can only be set at server star= t. --uXxzq0nDebZQVNAZ-- --OaZoDhBhXzo6bW1J Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAl5LT1oACgkQnvQgOdby QH1TFg//XxOSjmJskZwEQy1JvBK61E5B6MqwFa7S0sTvZPKiuZ8XwosPvQakbLlp SMJVs+wZ9zG91yE586K6tCVefS7lKbGrd45GUpfPPpxFGB0ogGdE3jmkvWUZTIuc wYkFF9ezU5OlVdwmFPhBt9mtAsH8Z5DE2mEBWctQ02MeKJLfAmK/uWneJIPmrtFe Ko5kqwi+SBvaf1Z07yPDVxMUzWagAh2Zx8fupZsVvwTn4IF1/AFlCe8ZXEtw9trF bIt06PvGM5ojrhdjDQcfHEnILP7PZQ8itowyqvKVK4bm5BHbycbk4XjBejmMAxnk kZuHyIJWa9/YOjbb6g8ysPCRxUgNl/ugyPS+d8vdCOl128SYP1Dz6qKCilVRSEkK 7JtRVpoeotDj/KH6UObD7KETtmeIBC4DUySgCmg3IodElWH3rkr6F9o04NjGbPYc FONwuvwMiaQKML3j6fez4GN9USVAIqt8OOQkO1afQULwpw3bdqCQSz3H3ABTyVkV 0iyiWMmv3D7QPzPKyw69eiEZK9PE2VLcY84iAFqdB0Cn6YHVsHiu65kVGPwq7bH3 VQEqZGCKpAcxgjG1POACPCE8LkWSQSa6o2oB6PtAz+Cm+Y3xmqamWN0cY1/FxL/2 bq8JPzVtXcZmtLmaOGPdWVCyJ6YhNBXptIgXugJcU+9bapGQdyU= =iHJT -----END PGP SIGNATURE----- --OaZoDhBhXzo6bW1J--