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 1g5OHT-0000eH-JH for pgsql-bugs@arkaria.postgresql.org; Thu, 27 Sep 2018 04:52:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g5OHR-0006DV-Lm for pgsql-bugs@arkaria.postgresql.org; Thu, 27 Sep 2018 04:52:01 +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 1g5OHQ-00069z-KU for pgsql-bugs@lists.postgresql.org; Thu, 27 Sep 2018 04:52:01 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g5OAJ-0000Nh-0y for pgsql-bugs@lists.postgresql.org; Thu, 27 Sep 2018 04:44:43 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id A4DB121347; Thu, 27 Sep 2018 00:44:35 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 27 Sep 2018 00:44:35 -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= fm2; bh=EQeHLenKceYrtNzHCOhWQxQ/o4koE2HgjaneFZBgEss=; b=SxpAHT92 1EkYL1z5wxBrWDsW2cfdVBkUGqwiPda2k89CGjtrjLLNcglWqv6UA3stBGBAWn7n HFv42VFR00suIf6Xmq6nLacLdaGXk0Ya6ci5nRWGoN+Syp8ZgSpNIt0QHiLTiKbE gsrWiAtypvaIzY6PkQpYEZThXkYtc8imDutdRBvnoCTPuV3Z+dtPh03O8hZv6lVj 6Ru8rP7ArAvECzrEG+WPmtYERCcU49ngefTn8fiDGftJFpl/sOnZAH52pGrBGT8O HzXPnmkwyYxO3YB9qjOGjwEj1E4v+pjrPYXFuMjBgetGOroqOAmqRmmf9pKlr8fp JMXo4710tuiqNQ== 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=fm3; bh=EQeHLenKceYrtNzHCOhWQxQ/o4koE 2HgjaneFZBgEss=; b=RMHQo+q5smqUH5fB+8q1WCFo2pEB1yps6/Z+FnDKiuACb GdvQIEmD57Kn3yJUfr4c2IcAGVGFJVaLjPZsc/vf+0E2lv5xxQijHKWPJRi9pTvH 2+G+ABhEL6Y21Tw86heonFsJxBppnKGuJzJFifjzKVnxFreBoDvrCYinZq1IER1d iTOmX71DVFUSpjoKs2jVCkDQzlaxAF27/CyxlUQ9sukFfq+r3UfkqGW2yEiY7AXx UtINsuSikpYUy4wVFXn+CF2x7F6PW2uw0sfM6rzrTJNSTe/8RaGJptYuqzbXjpDj xiljvb1o5VLsLl5SWC0XIdYX/fyezg+wRNSwVZypA== X-ME-Proxy: X-ME-Sender: Received: from paquier.xyz (mp76f1f9c2.ap.nuro.jp [118.241.249.194]) by mail.messagingengine.com (Postfix) with ESMTPA id DC15C102DE; Thu, 27 Sep 2018 00:44:33 -0400 (EDT) Date: Thu, 27 Sep 2018 13:44:30 +0900 From: Michael Paquier To: TAKATSUKA Haruka Cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15402: Hot standby server with archive_mode=on keeps initial WAL segments Message-ID: <20180927044430.GP1659@paquier.xyz> References: <15402-a453c90ed4cf88b2@postgresql.org> <20180926035205.GJ1659@paquier.xyz> <20180926133640.99bfbc7ea82f71aa91a02c11@sraoss.co.jp> <20180926141236.160707712aea82341f01b03f@sraoss.co.jp> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="WTbgq2twYBxfsYA6" Content-Disposition: inline In-Reply-To: <20180926141236.160707712aea82341f01b03f@sraoss.co.jp> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --WTbgq2twYBxfsYA6 Content-Type: multipart/mixed; boundary="3mUD2hqWbnBptYHy" Content-Disposition: inline --3mUD2hqWbnBptYHy Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Sep 26, 2018 at 02:12:36PM +0900, TAKATSUKA Haruka wrote: > I think is it natural that some segments are not archived when you=20 > switch archive_mode back-and-forth. >=20 > I also think a fix to prevent generating .ready file at hot standby > server in this case is better. I don't have a concrete idea to do so now. I looked at this problem, and I completely agree. From what I can see, the restart point run on the standby creates a .ready file for the oldest segment because there were no .done file present in it, so the checkpointer thinks that it should mark the file with .ready, and then makes it ready for archiving, which is never going to happen with archive_mode =3D on. All the newer segments are already marked with =2Edone, so they are getting recycled correctly. Your patch is not completely correct though, as the origin of the problem comes from XLogArchiveCheckDone(), which should be made more solid depending on the archive mode used. The solution attached actually fixes a second bug, which is less annoying by the way, as past backup history files may stay behind on standbys. I looked at all the code paths of XLogArchivingActive() and that's the only problem I can see. In guc.c, SHOW archive_command would print as "(disabled)" on standbys even if archive_mode =3D on, but we lived with this behavior for ages. The user can understand that archiving is enabled only on a primary this way when looking at a standby, so that should not be changed. Takatsuka-san, what do you think? -- Michael --3mUD2hqWbnBptYHy Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="archive-standby-checks.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/access/transam/xlogarchive.c b/src/backend/access/= transam/xlogarchive.c index 4a039b1190..a0e53119ef 100644 --- a/src/backend/access/transam/xlogarchive.c +++ b/src/backend/access/transam/xlogarchive.c @@ -620,9 +620,16 @@ XLogArchiveCheckDone(const char *xlog) { char archiveStatusPath[MAXPGPATH]; struct stat stat_buf; + bool inRecovery =3D RecoveryInProgress(); =20 - /* Always deletable if archiving is off */ - if (!XLogArchivingActive()) + /* + * The file is always deletable if archive_mode is "off". On standbys + * archiving is disabled if archive_mode is "on", and enabled with + * "always". On a primary, archiving is enabled if archive_mode is + * "on" or "always". + */ + if (!((XLogArchivingActive() && !inRecovery) || + (XLogArchivingAlways() && inRecovery))) return true; =20 /* First check for .done --- this means archiver is done with it */ --3mUD2hqWbnBptYHy-- --WTbgq2twYBxfsYA6 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAlusYC4ACgkQnvQgOdby QH1zFQ/6AlegSA1xQaANxU0BrcEtE4gsCv5AMBiiFyTGlrVbXaGAJoZ9bFZ4tASl lNMsvmPIu4pG8bFvurZ5D/c6z9d67wKHqiVZwb+VS2KybPb8vIpgPqefsXq87KXE MxMYvBfV3L9IC5IerJR1qCskEmtpkqjBufQppk6DBIzbTarih6z7iJoI0l6D72Ff sdFeCMgTXTK48A5nDUngOjEMNhvf+d8JQ4ZaJGBngktgLlb3FNuuWl1Ap9BJAvv/ wB3hTDl6FwwvlwYhKH4OUr+qwS3n2+kdZEBFEBn1zh9pKy/ojG4pBAzoSfV8QbcU MW1Etb0EyofoG5fXWK/egsPnR3MmqUBSjKlEzo+6aHQ7zUWG4Xn5YcqlfZkHTH1c uwFpHrKJew0HRXIYFWEnvNe+EMU+zr3xbl3kYWqb6f6wTRtGDo0WLCvAZGUJ27+N qu8mlVcW/uF7xmNpenvCL6IO5m9s8BveGdr9NsfmErF6eH0RwWCDQzxPEYC05xOL cbw0fGQuuT9jnhBWxkgVn3gnJj/WnqXfDFm+FnK4ZM1bwGMfnQHkZ2PdOkKpAcfS N5pPavWYRNaG+oLI1LetM/qJZLgkqujenR5nvaa/l6hjlDz5UkxOP4yP/fC7xzfP anl8ogJK2hkTtO09ZBwie9XJxjbOaJp/JKpx3cPmMKWP/c3M/sw= =GVD2 -----END PGP SIGNATURE----- --WTbgq2twYBxfsYA6--