Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qVjQi-0013iR-4C for pgsql-bugs@arkaria.postgresql.org; Tue, 15 Aug 2023 02:05:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qVjQg-0094Hm-MC for pgsql-bugs@arkaria.postgresql.org; Tue, 15 Aug 2023 02:05:06 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qVjQe-0094C9-Ue for pgsql-bugs@lists.postgresql.org; Tue, 15 Aug 2023 02:05:06 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qVjQc-000B7B-07 for pgsql-bugs@lists.postgresql.org; Tue, 15 Aug 2023 02:05:03 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id C8E475C0118; Mon, 14 Aug 2023 22:04:59 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Mon, 14 Aug 2023 22:04:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; t=1692065099; x=1692151499; bh=d0 WjALLp355DRVpL6eqA8a1BWn/Gr9ihrkfMi/ko0hA=; b=bEEfXdrFw80Fz3qjxW k58M4LT7ph5bdOhTadtOLuEovjy5k8mCPHMgV0J6TvlbY1Qw3wIKHPZPtv7xpqHv P6yGKFUg1595mIPxhwgNSAMWnIq3DGT2WyyQZaVeMyuGtqUaH9cn39ZLTjwqnVe8 IGg/FothsFdMGw0gDxREl/bNBj+l5Y1rja3rQIDy80ddFJVkuQUjO/uR5sMZsRMd ViTmMTIyHA6twOyoFR/dyr7wrR5b0eABFiC8PwnuDUu5EppGWMe+4AFbcDfd12Si 6W4CyJyZa+2FF6owqw6dCz6rkOfbI8gv/CZSO3KX2gT4S8y7e4QWAYscmT22/2AC XEfw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1692065099; x=1692151499; bh=d0WjALLp355DR VpL6eqA8a1BWn/Gr9ihrkfMi/ko0hA=; b=hmhCuFuBHkCW3z5hibMmnnDcnj7Ky Pu1Im7443uCDmA1FCIyU/1A8H2L+dmaatfD2NZJgzNHzG3EFCBW99VAXqTqh1xsi qBs3grs9q1BGt9tT6THLzxLbw+1xVhYoNm0pnI/m04wSPJynZloZMKXByN7nbX3U UEhu9vY7kKCB7tmgdSuIKe0D/h1wdnTXsIKABPbtlWo5J+xwwuCwZRu54nyAONzj c3kb6X0BsqKl7IqBS+FNSd/gVkfnxVvc6c3z+kalSghhuXJ+BvVv4fST7VC671IN V/ArjxPLD6n98kbNnEIcL8XLtaNgeYTWRTcfLhaHcqEAXGkd0IAMQEEfw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedruddtiedgheduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredt tddvnecuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesph grqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepteelieefudffhffhtdetleeg geegfffhkeeuveetiefgudduvedutefggeeivdejnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiih ii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 14 Aug 2023 22:04:55 -0400 (EDT) Date: Tue, 15 Aug 2023 11:04:49 +0900 From: Michael Paquier To: Thomas Munro Cc: Noah Misch , Tom Lane , Kyotaro Horiguchi , exclusion@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17928: Standby fails to decode WAL on termination of primary Message-ID: References: <20230811140008.GB2261449@rfd.leadboat.com> <351991.1691800320@sss.pgh.pa.us> <20230812211327.GB2326466@rfd.leadboat.com> <20230813033034.GD2326466@rfd.leadboat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="4dPjKVRtycWHQF7D" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --4dPjKVRtycWHQF7D Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Aug 14, 2023 at 10:28:54PM +1200, Thomas Munro wrote: > Something like this... patches for 12 and master attached. Needs a > lot more testing. I really want to figure out how to get > deterministic tests... Interesting, thanks for the quick patch! /* * Try to find space to decode this record, if we can do so without * calling palloc. If we can't, we'll try again below after we've * validated that total_len isn't garbage bytes from a recycled WAL pag= e. */ decoded =3D XLogReadRecordAlloc(state, total_len, false /* allow_oversized */ ); The patch relies on total_len before the header validation is completed, meaning that this value of total_len could be invalid because it comes from the partially-read header.. Oh wait, that's actually OK because an oversized allocation is not allowed yet and the decode buffer would not be able to store more than what it can? Perhaps this comment should be updated to tell something like, adding that total_len can be garbage, but we don't care because we don't allocate anything that the decode buffer cannot hold. #ifndef FRONTEND =20 - /* - * Note that in much unlucky circumstances, the random data read from a - * recycled segment can cause this routine to be called with a size - * causing a hard failure at allocation. For a standby, this would cause - * the instance to stop suddenly with a hard failure, preventing it to - * retry fetching WAL from one of its sources which could allow it to move - * on with replay without a manual restart. If the data comes from a past - * recycled segment and is still valid, then the allocation may succeed - * but record checks are going to fail so this would be short-lived. If - * the allocation fails because of a memory shortage, then this is not a - * hard failure either per the guarantee given by MCXT_ALLOC_NO_OOM. - */ if (!AllocSizeIsValid(newSize)) return false; Wouldn't it be OK to drop entirely this check? I'm fine to keep it as a safety measure, but it should not be necessary now that it gets called only once the header is validated? Regarding the tests, I have been using this formula to produce the number of bytes until the next page boundary: select setting::int - ((pg_current_wal_lsn() - '0/0') % setting::int) from pg_settings where name =3D 'wal_block_size'; Using pg_logical_emit_message() non-transactional with an empty set of strings generates records of 56 bytes, so I was thinking about the following: - Generate a bunch of small records with pg_logical_emit_message(), or records based on the threshold with the previous formula. - Loop until we reach a page limit, at 24 bytes (?). - Generate one last record to cut through. - Stop the node in immediate mode. - Write some garbage bytes on the last page generated to emulate the recycled contents and an allocation=20 - Start the node, which should be able to startup. With wal_level =3D minimal, autovacuum =3D off and a large checkpoint_timeout, any other records are minimized. That's fancy, though. Do you think that this could work reliably? -- Michael --4dPjKVRtycWHQF7D Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmTa3UEACgkQnvQgOdby QH0alg//Web6M+hH4+DcansHQ/e+RwFcp6A+9K3ROO9cAFjB8BS2ridKiOVmFkGf 1e1/h8gA6L4S2j2ojhujuMpe4rBRVynqI5HCz3k/ldJ2d744czguaNZqvbhjc8Bv XTpSerhGDA5L3E3qX+GgadwEKvzHyz7cROl7cYXzbAA9Y1cYEcA/TpKFEYoaXw0Q cMt2wbCJqGWoIRv+OwD1jQR9d/EOag/d3VCbn8C3ncRVpBm1K7KAlit4oGUSZVLw cNJDhXmufncQlRImBz94/ysyjZfgMn04fX8Yk+z1T9bA+LQxmElACz51qLbeFaAj omA8CFBczC924tePr3zeKx1CEkvMZLV709H85qu6NbhYdNaD0HZAOswP7G2MdFe/ PcVFqPpOgf3oNtYO2VcBeAATi0lwkod0O0WC4ZJWpc+f9tNs1aoqOYlIkZkRKWKf eQXGmLsj6HFZ8OLm1Xvd1tgGA6gdtdBAgB7mbQ0thvmaLsgehpNTEsKfjCfnIvQR CHaxA8TGS2x5v2D0L/hcnRVyVMioUTbHNe96OFyqugGJnI41ekOh06bnQEBDDL+2 lpbXyRkg0J+yHF4ys/W0v/8HoeV6ry5FVZYta3+jQ7+gkWHGTvEhVByztCTCRoiZ tVbnJCUSgf0UUaFPLRDy/x/sifZtQSFX0Qt3l7PiZ2V6gjVRQLU= =wXpr -----END PGP SIGNATURE----- --4dPjKVRtycWHQF7D--