Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fHkQh-00037r-M2 for pgsql-general@arkaria.postgresql.org; Sun, 13 May 2018 06:24:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fHkQc-0001XP-Aa for pgsql-general@arkaria.postgresql.org; Sun, 13 May 2018 06:24:18 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fHkQa-0001XF-DV for pgsql-general@lists.postgresql.org; Sun, 13 May 2018 06:24:18 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fHkQS-00053y-O4 for pgsql-general@lists.postgresql.org; Sun, 13 May 2018 06:24:15 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id C32BC25C03; Sun, 13 May 2018 02:24:06 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Sun, 13 May 2018 02:24:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:content-type:date:from:in-reply-to:message-id:mime-version :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=BORd43QyAXsnIYkSmubsvJ/km+ULBdF+HvKYuCkT/Dw=; b=eui3+7Pn H7mMmiaTqXrYk0o76LwzIIEb7eOxv4ZXCPJpcx8rs1haIiFZTuEXJ6+m0Qwx5bR2 a1Davza02J8sr9MAa8l71HTRD8tlUmV6f4Qaz7hd6kIZSkhOT5QZu0KIBi5oLpir sqlw0/INp+dkzJKCoi9LyON27ES11tfRVTxU/hK2bJMJjxW2ef5prx37J4SSDtr1 WrOjmTFP5p3+TVIWQWEDNNohwixjjnrHAY3MtjlJ+tRBuCkG/PtCCeP2DXT24Ndu WUFhnBJKurbbVxqxi9jClAyNdNcVmRepBdFHyvx4q1dofciLIlHH/RTpJzUFqHMX 9cErbaRLF161rQ== 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-sender :x-me-sender:x-sasl-enc; s=fm2; bh=BORd43QyAXsnIYkSmubsvJ/km+ULB dF+HvKYuCkT/Dw=; b=aoJNZbSKXRetZ65s81PDDScpGc7gSmt/gv7c9WjXYMu1s psbZ25+HQ2OTg+W6AY1IMoLe5WBeyqx7sdSFg5ZubU0q4ff/FsyfNqgeiLaqIr96 sbajb9fTfhVsE1HOc/JDR4SY+4BHtg8D3DCk3Va8IYcKbunKG/f1WsexibBaTW9b Oz/cl5kRfvxiNB4JrH/B+QjRrGs6INiA77iZxasdENJIfy/Krnvch5YZumarFPIT ABAAkwgvzLVPR53ApLXdLvjxiVUKwS391Nvpc4pQIzSdu5TlJhN64fUG+o/Fe75U KpaK7/fz5dzYeQJ/ZMn2eZq6biKHljbpHZcEf6DsA== X-ME-Sender: Received: from paquier.xyz (c137162.net61215.cablenet.ne.jp [61.215.137.162]) by mail.messagingengine.com (Postfix) with ESMTPA id DE3A71025D; Sun, 13 May 2018 02:24:04 -0400 (EDT) Date: Sun, 13 May 2018 15:23:55 +0900 From: Michael Paquier To: Hannes Erven Cc: pgsql-general@lists.postgresql.org Subject: Re: recovery_target_time and WAL fetch with streaming replication Message-ID: <20180513062355.GA2481@paquier.xyz> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="sdtB3X0nJg68CQEu" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --sdtB3X0nJg68CQEu Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sun, May 13, 2018 at 01:39:48AM +0200, Hannes Erven wrote: > what is Postgresql's strategy when to fetch WAL from the master while in > streaming replication, and could it be tweaked? > > I'm using a physical streaming replication slave to have a database lagging > behind about one month behind the primary, by setting "recovery_target_time" > to the desired point in time. > This setting is periodically advanced by a cronjob to allow the replica to > roll forward. It's a 10.3-1 install on Debian. I think that you are coplicating your life here. Fetching WAL from a primary (or another standby) cannot be directly per se. By definition, any WAL present will e automatically fetched and synced on the standby. Now, it is not usually the moment WAL is fetched and synced on a standby that matters, it is the moment it is replayed. For example, what people usually want to be protected from is an infortunate DROP TABLE on the primary run by an administrator to be immediately replayed on the standby, losing the data. Hence delaying when WAL is replayed can offer some protection, and this can be achieved by setting recovery_min_apply_delay in recovery.conf. This will cause WAL records replaying transactions commits to wait for the amount of time specified by this parameter, giving you the time to recover from any failures with a standby which has a controlled synced delta. > One option of course would be to use some transfer mechanism external to > Postgresql... but so far I'm thinking there must be any easier way? Another option I can think of here is to use a specific restore_command instead of streaming replication. Simply archive a WAL segment on the primary with some meta-data like the time it was archived, and then allow the standby to recover the segment only after a delta has passed. The can allow a more evenly distribution of segments. -- Michael --sdtB3X0nJg68CQEu Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAlr32fsACgkQnvQgOdby QH2s8RAApxuRs5WS5PNGnzpiuOtiOzUdsJ2QU9vJwL1Ps/RIeiAjRs7U0Pn1Hkzh XM4+Uy4CtU7EzxBOIeJ/SFbRz+leEgv7NKA0QSCbgd53YjHKfMY92KM7mnaRbzOy pI442uI/czmSjqF0zDKl9PiY3JWgXGDYyjhWToUI8lPNAZfKXa9noxCNBQ8MPf/f zJSTA6ffIl77FNM2I+4C3JLaeot5TJGrC8hfiBdoDdtUkTD0Ma58q9P7SM9UL4vV okbHNVKKDBC4ChHmJsjtMK9SsoABjmp80m/zQbbz/txZUERqTTGL5shR2zsltbEW gEfc17ZJYalOdB+CDWq/vDfMGfexdUISUj7yVmsMjjfW6dc1UGT/Tckw9UFPxJml 12lqtPZC+MmMX5BzU/VJDlP7QucR1gziRRkAOlBhj+UXgXAJR0hyUdEnYUvBxcas 84f4bfzC7U1H9VSVFexRnyp7RE6ByNMmZ8aOQZfCiRFZCrqCfYRfIhvNRx9U90ij oFewt4enK3qDSqU6H+sNZijLKYJsw2Gm71O2xVbmdK8mZycBKIyKvtJN5A/04r1d Vr3qiSC49G0lxWNR5Ei9oYzie5/12XffAsBHMYdtjYvejBgfdajmhRi0560mxSBh kglhrGHLC/XmfLm+bOx00zaqh6M+boYXnKpuq0/Idd+XD+tnfJ0= =foUA -----END PGP SIGNATURE----- --sdtB3X0nJg68CQEu--