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 1fpFYk-0008RD-D2 for pgsql-bugs@arkaria.postgresql.org; Mon, 13 Aug 2018 16:19:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fpFYi-00074U-Pl for pgsql-bugs@arkaria.postgresql.org; Mon, 13 Aug 2018 16:19:08 +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_SHA384:256) (Exim 4.89) (envelope-from ) id 1fpFYi-00074N-Js for pgsql-bugs@lists.postgresql.org; Mon, 13 Aug 2018 16:19:08 +0000 Received: from tamriel.snowman.net ([96.255.250.162]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fpFYf-0001sZ-7I for pgsql-bugs@lists.postgresql.org; Mon, 13 Aug 2018 16:19:08 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id 990E05F79C; Mon, 13 Aug 2018 12:19:04 -0400 (EDT) Date: Mon, 13 Aug 2018 12:19:04 -0400 From: Stephen Frost To: Andres Freund Cc: Phil Endecott , pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15323: wal_keep_segments must be >= 1 for WAL archiving + streaming to work Message-ID: <20180813161904.GR3326@tamriel.snowman.net> References: <20180813144534.piruesukkjw6zl4b@alap3.anarazel.de> <1534172372164@dmwebmail.dmwebmail.chezphil.org> <524A7B69-91A8-4F17-805D-9A4DA746B02D@anarazel.de> <20180813152211.GN3326@tamriel.snowman.net> <20180813152712.u2jnag6jv7x5rkor@alap3.anarazel.de> <20180813154247.GO3326@tamriel.snowman.net> <20180813155545.t3xafhk52wbambmv@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="pAMbS1LL1U6QDnK3" Content-Disposition: inline In-Reply-To: <20180813155545.t3xafhk52wbambmv@alap3.anarazel.de> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --pAMbS1LL1U6QDnK3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Greetings, * Andres Freund (andres@anarazel.de) wrote: > On 2018-08-13 11:42:47 -0400, Stephen Frost wrote: > > > > This should really work even without replication slots though. > > >=20 > > > Why? I fail to see what'd be gained by adding "always retain one > > > segment" rule. It'd not make the setup any more reliable. If anything > > > it'd make it harder to spot issues in test setups. > >=20 > > What exactly is wrong with the setup where this should be failing? >=20 > If you want to rely on archiving, you either need to be ok with > arbitrary delays in low activity periods, or use archive timeout. >=20 > If you want to rely on streaming, you need an appropriate WAL retention > policy, i.e. wal_keep_segments or replication slots. >=20 > The setup at hand does doesn't want arbitrary delay in archiving > situations but doesn't use archive_timeout and it retain the necessary > WAL for streaming. The setup doesn't rely on *only* archiving or *only* streaming though- it's set up specifically to work with both and what's happening is that PG is failing to ensure that, when both are used, a replica is able to fully catch up and follow a primary, and there's zero excuse for that as far as I'm concerned. We document explicitly that it should work and it does in almost all cases except this one, and not because we don't know what it'd take to make it work but simply because we fail to account for the primary possibly having removed a WAL file that a replica following the archive will want to start from because that's the last WAL file which was archived. I don't think there's any particular concern about arbitrary delay in archiving situations nor does it have any need for archive_timeout to be set in this case. Setting an archive_timeout likely would also have "solved" this issue, but, again, not because an archive_timeout really needs to be set but because it'd end up papering over this issue. Instead, having archive_timeout would have resulted in a lot of additional WAL ending up being archived than would be actually necessary. I simply don't buy off on these excuses that we're doing the right thing here because there's ways to get around it by using wal_keep_segments or setting archive_timeout or replication slots or just hoping that more data will be written to force another WAL out which will let the replica get a bit farther ahead and then be able to connect to the primary and get access to a WAL file that's still available and just hasn't happened to be removed yet. This could happen when building out a new replica too, btw, as far as I can tell- just restore from a backup and then let the system replay from the WAL archive until it gets to the last WAL segment there and have it try to connect to the primary- if the primary has removed that last WAL segment already and has moved on to the next WAL segment and isn't generating much WAL itself. Thanks! Stephen --pAMbS1LL1U6QDnK3 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJbca94AAoJEO1sijiDR2RV9ecP/0vMMkzgbSGI7cE4rYFMBZWR DJnfud2YNKEDFioCczfZ/OAy8cRbt2HGPWkQfRKN6XLx88QmHqzZvO22jmoNpZkQ iU9uhcL3kusMzmr99MqCyWHIguXUSsA1KNCRdpZtBAqYuA+dWAm/iMfrJCMLVoos TrBoU0LHwRphpRs7DgnvHbHCKj6RwTANoCqrVYIUZd3/I2ktcZhr4VC6+GSmZkF9 4r+YkzeAR/hNI2sSwPBGrzRDjPpPsOWB6IASS8ViL37XKlkdIziWyDgPdjEYXf5K +eJmZcJ8B6c+bMYY+RauzG03mjL2MKTY55Cn012zvxJhSRVC4AUC80tQ6qZ4PARe M9tPwyFbV+VWI2itzyzXimAEc831P7EBHD5HftvDzBzb75nSMJMwI3GE+De2XRwX h72z8DTGMd+aSuQ83YvcsMLLscgNFQjie+nrqawYIo9SA4xzUCtlQK75LMEOM4lJ eeYudHyZun3vKZjxQQVe+Iaj3SXNvEAjsPioCligM+gUwbQapacgIFBI/7UhzZMI bU/CT9x5AbHJSk+DY8AuwOa7/CePbeE1nZm4i4PJaRxzfiAW4KFXdHGbfFVerc7w bgIpg84pa5UGcRm5zq0JR+rNqqBNnKy2xA1UBqlQ+4W/1bdNMr1Rl2Ii7hVUZkzx 33eXEY6VnjxGxhe5li3M =6HHm -----END PGP SIGNATURE----- --pAMbS1LL1U6QDnK3--