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 1fvNAW-0006tk-46 for pgsql-bugs@arkaria.postgresql.org; Thu, 30 Aug 2018 13:39:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fvNAS-0006H9-Ai for pgsql-bugs@arkaria.postgresql.org; Thu, 30 Aug 2018 13:39:24 +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 1fvNAQ-0006Gj-N9 for pgsql-bugs@lists.postgresql.org; Thu, 30 Aug 2018 13:39:24 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fvNAM-0004K9-09 for pgsql-bugs@lists.postgresql.org; Thu, 30 Aug 2018 13:39:21 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id BDA86225; Thu, 30 Aug 2018 09:39:15 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 30 Aug 2018 09:39:16 -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=gk/v7uWLdSAbohtYjjMTPHi7MilY8VMae82QzDPZvpE=; b=F3zcx/tq 7b46KgLiYM2wjfuT35yyL8AgCbVKDBiQFe8yuiVsiVFTWR606VO0MxWpKuHRGpuW Yh+QC6eKWi0jb1MpvMFrjgVH8w5GAPwR6Y71u/6CFFiZVxmxfu9k9Idx0CPgpLpn 6WX+ojEaEQhIk9hAQr+4aViIcGgZI7S2SSgiy+3kFqBeOIkDjZDwpgkmQIaM1hWM 5VuRbNUezHSxrcsu1S2kWUG9jIWpM/gJIL//lenLFfCnHIYENPqXInbWuodauqv7 y6MAaVKUDdVji8/sRcplyQhVL8HGCJTiU77WH6jqu6X2vNFQ+o79ZVNPp0EyoiWK WKDQwB25WQLUOA== 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=gk/v7uWLdSAbohtYjjMTPHi7MilY8 VMae82QzDPZvpE=; b=VKIik2ATicVxXuYn/40GQ1J5L6E5uYbSLuSSIzzahl45b nyjhLUuZjF/vK/0YUX1S6dg+7++l3ukcQdxqfg/OUAmOGu5O4faZDjkAKomcGn4+ 57jYMNRmNbUmn6G4frtvS19yD6QjFaJBeUQdBSZANgXbI25a8tRG+TY3rqX3IAxN e+D7J/wuH9tTrI9+G5jA+VcUp8pzXFZjGJ8kj1g+hSJV5sJnKSmzZjYcTtOaQBjg aOkacwvb/80vIYY6uP8iR/EK1LOotnN4ca+WIgrb4K6aLyrKdDQfaNhZ0m05pKPl J5eUio0z4X783qmUl87RFbwyWGZF5RRtb7lzQnShA== X-ME-Proxy: X-ME-Sender: Received: from paquier.xyz (unknown [66.201.48.83]) by mail.messagingengine.com (Postfix) with ESMTPA id BC9791029C; Thu, 30 Aug 2018 09:39:13 -0400 (EDT) Date: Thu, 30 Aug 2018 06:39:11 -0700 From: Michael Paquier To: Alexander Kukushkin Cc: PostgreSQL-development , Alvaro Herrera , Dmitry Dolgov <9erthalion6@gmail.com>, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15346: Replica fails to start after the crash Message-ID: <20180830133911.GA15446@paquier.xyz> References: <20180823041420.GA1158@paquier.xyz> <20180829061723.GA5903@paquier.xyz> <20180829121051.GC5903@paquier.xyz> <20180829205436.GE5903@paquier.xyz> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="XOIedfhf+7KOe/yw" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --XOIedfhf+7KOe/yw Content-Type: multipart/mixed; boundary="huq684BweRXVnRxX" Content-Disposition: inline --huq684BweRXVnRxX Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Aug 30, 2018 at 10:55:23AM +0200, Alexander Kukushkin wrote: > Bgwriter itself never changes updateMinRecoveryPoint to true and boom, > we can get a lot of pages written to disk, but minRecoveryPoint in the > pg_control won't be updated! That's indeed obvious by reading the code. The bgwriter would be started only once a consistent point has been reached, so the startup process would have normally already updated the control file to the consistent point. Something like the attached should take care of the problem. As the updates of the local copy of minRecoveryPoint strongly rely on if the startup process is used, I think that we should use InRecovery for the sanity checks. I'd like to also add a TAP test for that, which should be easy enough if we do sanity checks by looking up at the output of the control file. I'll try to put more thoughts on that. Does it take care of the problem? -- Michael --huq684BweRXVnRxX Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="min-consistent-update-v1.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam= /xlog.c index 493f1db7b9..f9c52fb9d8 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -2723,9 +2723,14 @@ UpdateMinRecoveryPoint(XLogRecPtr lsn, bool force) * i.e., we're doing crash recovery. We never modify the control file's * value in that case, so we can short-circuit future checks here too. The * local values of minRecoveryPoint and minRecoveryPointTLI should not be - * updated until crash recovery finishes. + * updated until crash recovery finishes. We only do this for the startup + * process replaying WAL which needs to keep clean references of + * minRecoveryPoint until it is made sure that it has replayed all WAL + * available for crash recovery. Other processes would be started after + * the consistency point has been reached on a standby, so it would be + * actually safe to update the control file in this case. */ - if (XLogRecPtrIsInvalid(minRecoveryPoint)) + if (XLogRecPtrIsInvalid(minRecoveryPoint) && InRecovery) { updateMinRecoveryPoint =3D false; return; @@ -2737,7 +2742,9 @@ UpdateMinRecoveryPoint(XLogRecPtr lsn, bool force) minRecoveryPoint =3D ControlFile->minRecoveryPoint; minRecoveryPointTLI =3D ControlFile->minRecoveryPointTLI; =20 - if (force || minRecoveryPoint < lsn) + if (XLogRecPtrIsInvalid(minRecoveryPoint)) + updateMinRecoveryPoint =3D false; + else if (force || minRecoveryPoint < lsn) { XLogRecPtr newMinRecoveryPoint; TimeLineID newMinRecoveryPointTLI; --huq684BweRXVnRxX-- --XOIedfhf+7KOe/yw Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAluH838ACgkQnvQgOdby QH2NMRAAqLIIGiuwyLSZTYrRsYz3VVIHx7evDtgvDsRbPDyh66wFtuBg8wjvx04u dxW1IvgWh+yahJbIP1p/kCEJf0zHCcn11WQb1Nym5eoJQFZOmi7yZt8kAmLCFHJR nb0LqSa+H1e6/Suytl5ySD2gFnsEZGU1jkMJ4qzKSpeA1qB2cIu9qKgMXFj83M6l XToH06JdBYG9e4KDpsrZ3TlfGJpNyHhD8UrzfncNI9rLEMTyQBg9wkHRUwBaT8W5 h61b3o6CPHw3Zz6d0z2NTcmNctjZJGgvml26YyUllcB8SWBGHJMz4PQRZdbfxFpB XvLYYEAZMnO0FaUo27+jRxuWh4ZzNSdpVR8j6O70WKJB8mwKrRGZOs4bzdjLl0KR XQeAAwTxozzA1z53cl0JF6WEzhZoBeIRBrmAsTxvP21zS7zUyxwgysJwycieW0iH gtdLZvc/AGjKeJ+ocaUumADcSY8M5HAg5w6DjcBiE19TcKOJ2lS/TYc/Tbn/NUcF m1va14XGHJiKXfNF2gYeRfAVviS85TxBl18CqGFeCfjI4kGue75nzZgNGnq6skE+ C7C0if1WO7XhVt7M6zzk1QYzq89VEvjWc8dgs2sNqhoiVRClk+3NGMaoRN0BZ+ee rOzGzueaeKSGfr03TrHztp07KsJRcknDlhzExI6PFM+9pbH/6nw= =g7Ou -----END PGP SIGNATURE----- --XOIedfhf+7KOe/yw--