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 1iAsTo-00058A-Od for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Sep 2019 09:12:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iAsTm-0005xT-LW for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Sep 2019 09:11:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iAsTm-0005xE-9H for pgsql-hackers@lists.postgresql.org; Thu, 19 Sep 2019 09:11:58 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iAsTf-00074U-Q1 for pgsql-hackers@postgresql.org; Thu, 19 Sep 2019 09:11:57 +0000 Received: by mail-pl1-x644.google.com with SMTP id f19so1309360plr.3 for ; Thu, 19 Sep 2019 02:11:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:to:cc:subject:from:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=JZSAa3dsI3KhCSF52lFriksuxIrmQLsvQQ1OI7OaBYg=; b=GZ7Mr4xLjSw+p76QV4uUy3B76BPc+1E57upBaImafWWaWmq6DW3eawcw34cAhC4Kgw OQsD0puSMBN9XnKym4p3l5LGuyn8mPZtITvt2kAgrr6nK0Dq7IliBF7Z8WJ4u1EMAKAK /Pv2/G4P9Ac25q7xSsZ+66fXb6qWWRgmZWcjZJ8ssph6+oKKaFiX+cFQCI1vDLj4EWzu kBB2asSGmEEf1hfQpTd0e2/nPY3pBAPx2EbPXQ29mcCHlgCDNjq+idEoB+bpNBcd6FrJ 9KkES0vV3/sNcY1MrLhXRQYCDgfer8gXjcM4ruo09igY4YP3e93dy8IQbkxKn/rwF9Xn KBDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:to:cc:subject:from:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=JZSAa3dsI3KhCSF52lFriksuxIrmQLsvQQ1OI7OaBYg=; b=PnIig9Sb9VQwnjZUWUgVmEj/T78m37rRlKo6YcfZ+RHioB/HyLK4W+Okvx9+D+m5gD BdXvMAMg9PevI1AFIes+jdtpvzGzIASVKxAgCshUJwpcw0cCPMFbb/28Mzjk7/b9xsGL 5RT3v6n5kUJcmX5R2VKtqjHh6Wjw3f/mk13KRb6G7fi9yTw5BTzwzDQ+7OLCA1W49I1Q Q4OZJqpxzHhFIZF5Y32wt3eIQfDxcKivxex5f0m7muHLC3fQBYDzFs+if26J7C0fGR4Y o1FycMcrJnr30ySLJ1GB5tCbyJ2XFmXjwJwHncfrgVH+Mm25x1AVIAFWfzzqISW371bA vTkg== X-Gm-Message-State: APjAAAUGOVba8UenaAtM8ziNyyKDp6mqDgqk1UeKW2kefcqOiqcMgC0U pDgYSPOi742kaYWYA3Qp6As= X-Google-Smtp-Source: APXvYqz4E/VmIFdNFca3ZC6kSu9qvLkIKA/tQpB+AdvVhx+vox6z9Q+n/TNT4TckV2uopT7cZ1ozgw== X-Received: by 2002:a17:902:76c2:: with SMTP id j2mr8986696plt.304.1568884309570; Thu, 19 Sep 2019 02:11:49 -0700 (PDT) Received: from localhost (w204177.dynamic.ppp.asahi-net.or.jp. [121.1.204.177]) by smtp.gmail.com with ESMTPSA id n66sm16607144pfn.90.2019.09.19.02.11.45 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 19 Sep 2019 02:11:48 -0700 (PDT) Date: Thu, 19 Sep 2019 18:11:33 +0900 (Tokyo Standard Time) Message-Id: <20190919.181133.15766613.horikyota.ntt@gmail.com> To: sk@zsrv.org Cc: michael@paquier.xyz, andres@anarazel.de, david@pgmasters.net, pgsql-hackers@postgresql.org Subject: Re: allow online change primary_conninfo From: Kyotaro Horiguchi In-Reply-To: <34084371566985786@sas1-0a6c2e2b59d7.qloud-c.yandex.net> References: <2851181561980819@iva7-634c9cb1f49d.qloud-c.yandex.net> <20190730064239.GJ1742@paquier.xyz> <34084371566985786@sas1-0a6c2e2b59d7.qloud-c.yandex.net> User-Agent: Mew version 6.5 on Emacs 22.2 / Mule 5.0 =?iso-2022-jp?B?KBskQjpnGyhCKQ==?= / Meadow-3.01-dev (TSUBO-SUMIRE) Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Thu_Sep_19_18_11_33_2019_126)--" Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ----Next_Part(Thu_Sep_19_18_11_33_2019_126)-- Content-Type: Text/Plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Hello. I looked this and have some comments. At Wed, 28 Aug 2019 12:49:46 +0300, Sergei Kornilov wrote= in <34084371566985786@sas1-0a6c2e2b59d7.qloud-c.yandex.net> sk> Hello sk> = sk> Updated patch attached. (also I merged into one file) sk> = sk> > + sk> > + WAL receiver will be restarted after primary_slot_name= sk> > + was changed. sk> > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 sk> > The sentence sounds strange. Here is a suggestion: sk> > The WAL receiver is restarted after an update of primary_slot_nam= e (or sk> > primary_conninfo). sk> = sk> Changed. - This parameter can only be set at server start. + This parameter can only be set in the postgresql.c= onf + file or on the server command line. I'm not sure it's good to change the context of this description. This was mentioning that changing of this parameter requires server (re)start. So if we want to be on the same context after rewriting, it would be like "This parameter can be set any time and causes WAL receiver restart with the new setting if the server is in standby mode." And If I'm not missing something, I don't find an (explict) paramter of postmaster for setting primary_conninfo. sk> > The comment at the top of the call of ProcessStartupSigHup() in sk> > HandleStartupProcInterrupts() needs to be updated as it mentions = a sk> > configuration file re-read, but that's not the case anymore. sk> = sk> Changed to "Process any requests or signals received recently." lik= e in other places, e.g. syslogger sk> sk> > pendingRestartSource's name does not represent what it does, as i= t is sk> > only associated with the restart of a WAL receiver when in stream= ing sk> > state, and that's a no-op for the archive mode and the local mode= .= sk> = sk> I renamed to pendingWalRcvRestart and replaced switch with simple c= ondition. sk> = sk> > So when shutting down the WAL receiver after a parameter change, = what sk> > happens is that the startup process waits for retrieve_retry_inte= rval sk> > before moving back to the archive mode. Only after scanning again= the sk> > archives do we restart a new WAL receiver. sk> = sk> As I answered earlier, here is no switch to archive or wal_retrieve= _retry_interval waiting in my patch. I recheck on current revision too:= @@ -11787,48 +11793,6 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr,= bool randAccess, if (!StandbyMode) return false; = - /* - * If primary_conninfo is set, launch walreceiver = to try - * to stream the missing WAL. - * - * If fetching_ckpt is true, RecPtr points to the = initial - * checkpoint location. In that case, we use RedoS= tartLSN Mentioning code, the movement of the code block makes the surrounding swtich almost useless and the structure and the result looks somewhat strange. Couldn't we do the same thing by just skipping the wait and setting lastSourceFailed to true in the case of intentional walreceiver restart? The attached is an incomplete (fraction) patch to sketch what is in my mind. With something like this and making ProcessStartupSigHup kill walreceiver would work. regards. -- = Kyotaro Horiguchi NTT Open Source Software Center ----Next_Part(Thu_Sep_19_18_11_33_2019_126)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="immediately_restart_walreceiver_INCOMPLETE.patch" diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 6876537b62..61b235f8f7 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -11881,10 +11881,12 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess, * obtaining the requested WAL. We're going to loop back * and retry from the archive, but if it hasn't been long * since last attempt, sleep wal_retrieve_retry_interval - * milliseconds to avoid busy-waiting. + * milliseconds to avoid busy-waiting. We don't wait if + * explicitly requested to restart. */ now = GetCurrentTimestamp(); - if (!TimestampDifferenceExceeds(last_fail_time, now, + if (!pendingWalRcvRestart && + !TimestampDifferenceExceeds(last_fail_time, now, wal_retrieve_retry_interval)) { long secs, @@ -11905,6 +11907,17 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess, } last_fail_time = now; currentSource = XLOG_FROM_ARCHIVE; + + /* + * If wal receiver is requested to restart, we skip the + * next XLOG_FROM_ARCHIVE to immediately starting it. + */ + if (pendingWalRcvRestart) + { + lastSourceFailed = true; + continue; + } + break; default: ----Next_Part(Thu_Sep_19_18_11_33_2019_126)----