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 1rhHoD-00AeSn-PW for pgsql-bugs@arkaria.postgresql.org; Mon, 04 Mar 2024 23:33:26 +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 1rhHoC-00Bkj0-Ai for pgsql-bugs@arkaria.postgresql.org; Mon, 04 Mar 2024 23:33:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rhHoC-00Bkis-16 for pgsql-bugs@lists.postgresql.org; Mon, 04 Mar 2024 23:33:24 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rhHo5-002nWN-4D for pgsql-bugs@lists.postgresql.org; Mon, 04 Mar 2024 23:33:23 +0000 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-33da51fd636so2560966f8f.3 for ; Mon, 04 Mar 2024 15:33:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aiven.io; s=google; t=1709595196; x=1710199996; darn=lists.postgresql.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4VxLT0636BoGSSq7XGvSMcIYn+Tr4TeJQm483EFOE7M=; b=bGmcVYHb8GIBS/pRYNk9WCUpY2EhFhUaPErvs/0spau38cD4VnhXoHBxvyteUSA2Vh qlOqSbYiR3YfNFCJvWXGeIu48iAlIk/UA2UModH5BIvGg8o2GboySnwbLT0BKvHBTe3I nI828nfmY4y1u7VLgTHhVcL/YxDyM7wQPfriI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709595196; x=1710199996; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4VxLT0636BoGSSq7XGvSMcIYn+Tr4TeJQm483EFOE7M=; b=engsWH/cadVBJrdrfzvkQ5PNzWW/cXyqx2Bgj0KmmRvYZwe5a9U57R96czrsHVBWjJ quZGWUUd1bwnQ6bbgzGlzkMyzQTWtXBEgjUFK4Hp+M/BO45ZOhnCg9ex9siRvFI+QHdT 66uGtyJixhJd5JSbWw5u4xbwszXOr0GG9NW87d1YdLRIPMGNKTmrhdjdkOF1P2kensrX K4HiLFUoqDXnGOEt2lPVFZ9xaumzVs9VilFnBCpcStKfWq1EtOoAgYlbWSQDOlpru8Iy B2MFviTl6l/FnSzBUxQxE0G9qOfaH3xE1XKcU8aplPHObySSLiWWm7tWgVfyEmmRPM2E Gzhg== X-Gm-Message-State: AOJu0YxhvljtdBFXNF+pUYb5qAh46na4sAAdOPJ0COJF3Gq43t8ohwiD a16PjfaxsjANgkY+m8JB70IleUOYGn1qd0FTueIyxkctHvfOCmD0HniAnz02YW1yBfek9rHAhXF 0 X-Google-Smtp-Source: AGHT+IG62nWECUdi4ExXqm/87AChkMyfWrxDVBdlo97Y8py659AuScWeSixz40yEbodYC1uzUGC1Kw== X-Received: by 2002:a5d:6645:0:b0:33d:2b3d:a02a with SMTP id f5-20020a5d6645000000b0033d2b3da02amr8313158wrw.62.1709595195767; Mon, 04 Mar 2024 15:33:15 -0800 (PST) Received: from aivenlaptop.localnet ([45.13.105.93]) by smtp.gmail.com with ESMTPSA id az23-20020adfe197000000b0033e4403c6a9sm2322629wrb.22.2024.03.04.15.33.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 15:33:15 -0800 (PST) From: Ronan Dunklau To: Noah Misch Cc: pgsql-bugs Subject: Re: FSM Corruption (was: Could not read block at end of the relation) Date: Tue, 05 Mar 2024 00:33:13 +0100 Message-ID: <3470254.QJadu78ljV@aivenlaptop> In-Reply-To: <20240304230503.a4.nmisch@google.com> References: <3549385.iIbC2pHGDl@aivenlaptop> <20240304230503.a4.nmisch@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Le mardi 5 mars 2024, 00:05:03 CET Noah Misch a =E9crit : > Does that procedure alone reproduce the ERROR, without any replica promot= e, > postmaster restart, etc.? That, I do not have reason to expect. Oh no sorrry for not being clear: it needs to go through recovery either=20 through a backup restoration, a replica or anything else. This is why I've= =20 been struggling to reproduce the issue, it didn't occur to me that the fsm = was=20 only sane on the primary, as the extensions were not wal logged. >=20 > > > I think the fix is one of: > > >=20 > > > - Revoke the undocumented rule. Make FSM consumers resilient to the = =46SM > > >=20 > > > returning a now-too-large block number. > >=20 > > Performance wise, that seems to be the better answer >=20 > I would guess this one is more risky from a performance perspective, since > we'd be adding to a hotter path under RelationGetBufferForTuple(). Still, > it's likely fine. Makes sense.=20 >=20 > > but won't this kind of > > built-in resilience encourage subtle bugs creeping in ? >=20 > Since the !wal_log_hints case avoids WAL for FSM, we've already accepted > subtle bugs. I bet an unlucky torn FSM page could reach the ERROR you > reached, even if we introduced a "main-fork WAL before FSM" rule. We'll > have plenty of need for resilience. Hence, I'd lean toward this approach. > > > - Enforce a new "main-fork WAL before FSM" rule for logged rels. For > > > example, in each PageIsNew() case, either don't update FSM or WAL-log= an > > > init (like lazy_scan_new_or_empty() does when PageIsEmpty()). > >=20 > > The FSM is not updated by the caller: in the bulk insert case, we > > intentionally don't add them to the FSM. So having VACUUM WAL-log the p= age > > in lazy_scan_new_or_empty in the New case as you propose seems a very > > good idea. > >=20 > > Performance wise that would keep the WAL logging outside of the backend > > performing the preventive work for itself or others, and it should not = be > > that many pages that it gives VACUUM too much work. >=20 > A drawback is that this approach touches several access methods, so > out-of-tree access methods also likely need changes. Still, this is a go= od > backup if the first option measurably slows INSERT throughput. Would it actually ? At least for the currently discussed VACUUM case, we wi= ll=20 fall back to a generic FPI for the new page, which should work on any AM. B= ut=20 the requirement to WAL log the page before recording it in the FSM should b= e=20 publicized, and the common infrastructure should adhere to it. I'd have to= =20 look into the other cases you mentioned where that can happen. >=20 > > I can try my hand at such a patch it if looks like a good idea. >=20 > Please do. >=20 > > Thank you very much for your insights. >=20 > Thanks for the detailed report that made it possible.