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 1rhISR-00Ai4V-Hj for pgsql-bugs@arkaria.postgresql.org; Tue, 05 Mar 2024 00:14:59 +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 1rhIRQ-00Bqx6-GK for pgsql-bugs@arkaria.postgresql.org; Tue, 05 Mar 2024 00:13:56 +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 1rhIRQ-00Bqwx-7m for pgsql-bugs@lists.postgresql.org; Tue, 05 Mar 2024 00:13:56 +0000 Received: from mail-yw1-x112a.google.com ([2607:f8b0:4864:20::112a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rhIRL-002nl2-MY for pgsql-bugs@lists.postgresql.org; Tue, 05 Mar 2024 00:13:55 +0000 Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-6096ff3e4abso38229767b3.0 for ; Mon, 04 Mar 2024 16:13:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1709597630; x=1710202430; darn=lists.postgresql.org; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=R8cyFngU/de2U5FIN1MtbgwNMwgX1ZNP/6DmHnsV3Iw=; b=VaLvP/YMsgVDm4gykQSE0gF6lXms9S4nYQ9++PCvAl+GMrF7erbNou8kBf1c1F2dZV 9x3LIFbFK9Pd2Z1mJ+0EpuCD5n9e5CZmtvkBxqV65Q3F9yo4jTNRLcIXHEC78XSX5ofX yNramnGu5fEtR75gzAphRON5WV+oIfPE7fTC4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709597630; x=1710202430; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=R8cyFngU/de2U5FIN1MtbgwNMwgX1ZNP/6DmHnsV3Iw=; b=PGV71Fl7efrPviQ46+stjWv5+UoSgpOgGe3J4+ojtRQxJmDvW8CeUXFfJyMX4+678a AYZRAK0CDFSWA0tllguHcYn4fIkK4MmYCi16D8JYko9e96K4R41L85Yj80XIaJclmmhw vs3DJJqft70uF1EmaZFrPrygPZoGKfDPxqepnoUkVYa014TcdMx54mlMXfnh7+ccj4FZ BlzO9PxY6Sy/VNqVHXQL6PPDCf2UI38uYR+zw14NjnsS7MR13X4hdeI+9TU8Y0+gnCqq oyW4meNjjMCuDuvGZPdN11EgLNnz5ye9C0zf9wdwYDfCcpJcyauGrsol4KAcp/l3spA4 Abvg== X-Gm-Message-State: AOJu0YxW0QdBrjYPyWb4MZU0ucbK9ZTN95P2KgXj80B57zq5e32JEe5k 2ezCmI9Xt5dWzhLba1rMEaY6f9y+Mp4jtZaBC+IkR4ACDZr6zwTGFd2glxREWg== X-Google-Smtp-Source: AGHT+IHnhP7cGY3YP//ObEfdjsE1fKqoDNOpy5wVKYvIalF9DaX4afZStNIYzkfmYZ5sVGGrqT3r3w== X-Received: by 2002:a0d:e941:0:b0:609:a55b:805c with SMTP id s62-20020a0de941000000b00609a55b805cmr3994569ywe.46.1709597630078; Mon, 04 Mar 2024 16:13:50 -0800 (PST) Received: from google.com ([2600:1702:a20:5750::48]) by smtp.gmail.com with ESMTPSA id p80-20020a0de653000000b00609765ff30dsm2668438ywe.24.2024.03.04.16.13.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Mar 2024 16:13:49 -0800 (PST) Date: Mon, 4 Mar 2024 16:13:46 -0800 From: Noah Misch To: Ronan Dunklau Cc: pgsql-bugs Subject: Re: FSM Corruption (was: Could not read block at end of the relation) Message-ID: <20240305001346.35.nmisch@google.com> References: <3549385.iIbC2pHGDl@aivenlaptop> <20240304230503.a4.nmisch@google.com> <3470254.QJadu78ljV@aivenlaptop> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3470254.QJadu78ljV@aivenlaptop> User-Agent: Mutt/2.2.12 (2023-09-09) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Mar 05, 2024 at 12:33:13AM +0100, Ronan Dunklau wrote: > Le mardi 5 mars 2024, 00:05:03 CET Noah Misch a écrit : > > > > - 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()). > > > > > > 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 page > > > in lazy_scan_new_or_empty in the New case as you propose seems a very > > > good idea. > > > > > > 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. > > > > A drawback is that this approach touches several access methods, so > > out-of-tree access methods also likely need changes. Still, this is a good > > backup if the first option measurably slows INSERT throughput. > > Would it actually ? At least for the currently discussed VACUUM case, we will > fall back to a generic FPI for the new page, which should work on any AM. But > the requirement to WAL log the page before recording it in the FSM should be > publicized, and the common infrastructure should adhere to it. I agree each AM can use generic FPI code. I'm looking at code like this as needing change under this candidate design: static void spgvacuumpage(spgBulkDeleteState *bds, BlockNumber blkno) { ... if (PageIsNew(page) || PageIsEmpty(page)) { RecordFreeIndexPage(index, blkno); The change there would be fairly simple, but non-core access methods may require similar simple changes. That's fine if this approach has other reasons to win, but it is a drawback. A grep of pgxn code shows "rum" as the only module containing a RecordFreeIndexPage() call. No module contains a RecordPageWithFreeSpace() call. So this drawback is all but negligible.