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 1rl0yx-00H45U-2j for pgsql-bugs@arkaria.postgresql.org; Fri, 15 Mar 2024 06:23:55 +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 1rl0yv-006Nuz-KE for pgsql-bugs@arkaria.postgresql.org; Fri, 15 Mar 2024 06:23:54 +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 1rl0yv-006Nuq-Ag for pgsql-bugs@lists.postgresql.org; Fri, 15 Mar 2024 06:23:53 +0000 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rl0ys-004bX3-83 for pgsql-bugs@lists.postgresql.org; Fri, 15 Mar 2024 06:23:52 +0000 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-412e784060cso16887995e9.1 for ; Thu, 14 Mar 2024 23:23:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aiven.io; s=google; t=1710483827; x=1711088627; 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=vQygDtkNQ8hqXUSB3Kiq5/MdsevSWjMtrXPnLpRQBrI=; b=ZlX9OOg9Tov/6uY5IznG3Y/zr3wIL06DjUfZxQzyh5xxU+QyY32C53rEtazFw07bIy SRsZxnj4UlPJIKTPvdVLDvTHBdn/M+g5gDFIebCiORdypbYAEhuVwB0E3DstYP19RhxB p3+/DPGaOr+HqqHLh9+lSm58Ac8ysYmIpJBoQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710483827; x=1711088627; 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=vQygDtkNQ8hqXUSB3Kiq5/MdsevSWjMtrXPnLpRQBrI=; b=Y7qKRluPoPOua7bsOOtwEiMx4fHXKh8U7qARh7XqFLT7dwq2K3EkgmeCCwE9A126Kz yK3CvSvGizAfkftR1ykKcMMfulNfGKoJL64LC5iqZk1zzPFW09P4zIoTFv7N15T6W51V IbosuFqVt7nqKUUb6g/Q0Pwz5gmB1nxXRUZJtduYdFLjX0L1jw5JrvsXu6ehA1K9txvj fcZO4rAwsJ7jePb7M4Dd88doMc1dFlH/ck3zSe+s1gFdBEr/OjFYQ3O5OdKg3NjVc7VT VMMwEf9lY4QJH8m3dHqxqJZ4O9m+8OI8Vv1D0hCi0jXp1VkdGeeJSlJh+VFQlKEObJQx sxxQ== X-Forwarded-Encrypted: i=1; AJvYcCW+PmOSkgJEVx//Rmfn2XTV3S5veueT6o1UIf0iKKrcsr+qmyYeQBbSzmF7K0/Iu6B/feVCIWJpnQYv2up1Np9w6c5GnAi0uQ/te6OghPIf X-Gm-Message-State: AOJu0YxesFXEOcRlmBvzZvMnyZ9/ClJpa5z3vof3YgcrfNM9E98f8jQJ 1wqNQwlEJVBV8+k6UvXJBHAjzs/IP872kDL5vxXDFp+54MZpolmpNBZlhpRBMIc= X-Google-Smtp-Source: AGHT+IEB/9C5RXHHlVgCkwXpyEVkjSTUi440klYs0n+Iv06obXrnvdxMLAR3g021FPtVz6uD7qTxUg== X-Received: by 2002:a05:6000:249:b0:33d:d7c7:4c33 with SMTP id m9-20020a056000024900b0033dd7c74c33mr2944014wrz.29.1710483827529; Thu, 14 Mar 2024 23:23:47 -0700 (PDT) Received: from aivenlaptop.localnet ([45.13.105.93]) by smtp.gmail.com with ESMTPSA id bs8-20020a056000070800b0033e3a24f17esm2478518wrb.76.2024.03.14.23.23.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Mar 2024 23:23:47 -0700 (PDT) From: Ronan Dunklau To: Noah Misch Cc: Michael Paquier , pgsql-bugs Subject: Re: FSM Corruption (was: Could not read block at end of the relation) Date: Fri, 15 Mar 2024 07:23:46 +0100 Message-ID: <5784272.DvuYhMxLoT@aivenlaptop> In-Reply-To: <20240313165523.6a@rfd.leadboat.com> References: <3225659.5fSG56mABF@aivenlaptop> <20240313165523.6a@rfd.leadboat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Le mercredi 13 mars 2024, 17:55:23 CET Noah Misch a =C3=A9crit : > On Wed, Mar 13, 2024 at 10:37:21AM +0100, Ronan Dunklau wrote: > > Le mardi 12 mars 2024, 23:08:07 CET Noah Misch a =C3=A9crit : > > > > I would argue this is fine, as corruptions don't happen often, and = =46SM > > > > is > > > > not an exact thing anyway. If we record a block as full, it will ju= st > > > > be > > > > unused until the next vacuum adds it back to the FSM with a correct > > > > value. > > >=20 > > > If this happened only under FSM corruption, it would be fine. I was > > > thinking about normal extension, with an event sequence like this: > > >=20 > > > - RelationExtensionLockWaiterCount() returns 10. > > > - Backend B1 extends by 10 pages. > > > - B1 records 9 pages in the FSM. > > > - B2, B3, ... B11 wake up and fetch from the FSM. In each of those > > > backends, fsm_does_block_exist() returns false, because the cached > > > relation > > > size is stale. Those pages remain unused until VACUUM re-records them > > > in > > > the FSM. > > >=20 > > > PostgreSQL added the multiple-block extension logic (commit 719c84c) > > > from > > > hard-won experience bottlenecking there. If fixing $SUBJECT will lose > > > 1% of that change's benefit, that's probably okay. If it loses 20%, = we > > > should work to do better. While we could rerun the 2016 benchmark to > > > see how the patch regresses it, there might be a simple fix.=20 > > > fsm_does_block_exist()> >=20 > > > could skip the cache when blknumber>=3Dcached, like this: > > > return((BlockNumberIsValid(smgr- >smgr_cached_nblocks[MAIN_FORKNUM]) > >=20 > > && > >=20 > > > blknumber < smgr- > > > > > >smgr_cached_nblocks[MAIN_FORKNUM]) || > > > > > > blknumber < RelationGetNumberOfBlocks(rel)); > > >=20 > > > How do you see it? That still leaves us with an avoidable lseek in B= 2, > > > B3, > > > ... B11, but that feels tolerable. I don't know how to do better > > > without > > > switching to the ReadBufferMode approach. > >=20 > > That makes sense. I'm a bit worried about triggering additional lseeks > > when we in fact have other free pages in the map, that would pass the > > test. I'm not sure how relevant it is given the way we search the FSM > > with fp_next_slot though... >=20 > That's a reasonable thing to worry about. We could do wrong by trying too > hard to use an FSM slot, and we could do wrong by not trying hard enough. >=20 > > To address that, I've given a bit of thought about enabling / disabling > > the > > auto-repair behaviour with a flag in GetPageWithFreeSpace to distinguish > > the cases where we know we have a somewhat up-to-date value compared to > > the case where we don't (as in, for heap, try without repair, then get = an > > uptodate value to try the last block, and if we need to look at the FSM > > again then ask for it to be repaired) but it brings way too much > > complexity and would need careful thought for each AM. > >=20 > > So please find attached a patch with the change you propose. > >=20 > > Do you have a link to the benchmark you mention though to evaluate the > > patch against it ? >=20 > Here is one from the thread that created commit 719c84c: > https://www.postgresql.org/message-id/flat/CA%2BTgmob7xED4AhoqLspSOF0wCMY= Eom > gHfuVdzNJnwWVoE_c60g%40mail.gmail.com >=20 > There may be other benchmarks earlier in that thread. Thank you. I tried to run that benchmark, with 4 clients all copying 10M=20 pgbench_accounts row concurrently. With and without the patch, I ran the=20 benchmark 5 times, and took the average.=20 master: 15.05s patched: 15.24s (+1.25%) If I remove the best and worst run for each of those, the difference falls = at=20 +0.7%.