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 1retJq-00E5EA-7C for pgsql-bugs@arkaria.postgresql.org; Tue, 27 Feb 2024 09:00:10 +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 1retJn-001i81-6N for pgsql-bugs@arkaria.postgresql.org; Tue, 27 Feb 2024 09:00:07 +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 1retJm-001i6k-U5 for pgsql-bugs@lists.postgresql.org; Tue, 27 Feb 2024 09:00:07 +0000 Received: from mail-lf1-x135.google.com ([2a00:1450:4864:20::135]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1retJj-001Rti-Hl for pgsql-bugs@lists.postgresql.org; Tue, 27 Feb 2024 09:00:06 +0000 Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-51197ca63f5so6031109e87.1 for ; Tue, 27 Feb 2024 01:00:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709024403; x=1709629203; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=qEuhNQqLj07guQJ6pa9JnjDmMNKJC9vIISLd/eb7xik=; b=UTwZgUGz3EWkhN5hCBBrpOxRsQPZSDcnGgPCr46qY74N417GL/qujGkKoIKjYqNzBv wsVu+OP8JOpboP7UNk4ynM5RyG2bggjbytaV70cNysvNUpn+scPWflp3KVSIRLgKdPlr RgFPX9P3VL0Pv4rL/VI8zbvhUGZbleQ2281S1Zcxlv3o3TrTnUCLwp8MqEfnWuqXLaIq LsS/xD1OUZhqOdAQ7K0NNHfTf8S1Q3blLtvjZYoUT7mFO8iambymqqwEyV6mnZzpDKTP 1DB/M0ziQ2NDMrNFfNOtWqq51WR0MacU2miLO3uBNbL3vSxnAvAQsWk5ucn2gp9qe+qz yS7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709024403; x=1709629203; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qEuhNQqLj07guQJ6pa9JnjDmMNKJC9vIISLd/eb7xik=; b=rza+1jubhVd5uVyKbZDH/72gO8ZFviBkii6h7TDvaLS/Epf2kDPC0nXErRDyIl/mun FRs/Rz5uLjZJZPvP8yJtaAeva52MY3LpnPBlIJZm5NQ6Hni7U4dgQtmhTJkKUJGzr4XX XeYai/BQYg5VebCB475tPGPMJNICy/VhNah2LvvzmY7um7vdtZie4kAoJfXcMuhin0sl dlJqj6mGGs2/bpHAfZgYt9byLC3wZS7NuXAzTTArjHCqam95CGOWqtHpabuqANmuAQvk RY/hV+1T1MUviFHY4B74s/4idSPwDY+J7HiUjpPeJyc3cNI/f+KTcyYAEhRgHC5aUaLX 7+2g== X-Gm-Message-State: AOJu0YzYbjujOuFoKX8IDroaWFGAU38VYZ8bHodbevgN6zxdJa8wQRwg qOjpQ2cFhNgwJ3Y0dc0ETZ+9zZWhBm6aya0tg0upi4JR9JTxk2nX1Md6dqxd X-Google-Smtp-Source: AGHT+IHlKK0TnJlUbjw7nda6yIu0uzKooH/tFlYfBdQfHc0XyfcuWe+JkuMjbrs60UxKFltQEP5ezw== X-Received: by 2002:ac2:4e09:0:b0:512:a9b7:c637 with SMTP id e9-20020ac24e09000000b00512a9b7c637mr7722440lfr.29.1709024402950; Tue, 27 Feb 2024 01:00:02 -0800 (PST) Received: from [1.0.0.7] ([91.185.78.44]) by smtp.gmail.com with ESMTPSA id j30-20020a056512029e00b00512e263d246sm1114886lfp.296.2024.02.27.01.00.01 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 27 Feb 2024 01:00:02 -0800 (PST) Message-ID: <80abbbf0-588b-f808-c264-77c3ebee83f3@gmail.com> Date: Tue, 27 Feb 2024 12:00:01 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: BUG #18351: VACUUM FULL fails with error: missing chunk number 0 for toast value XXX To: pgsql-bugs@lists.postgresql.org References: <18351-f6e06364b3a2e669@postgresql.org> Content-Language: en-US From: Alexander Lakhin In-Reply-To: <18351-f6e06364b3a2e669@postgresql.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 17.02.2024 23:00, PG Bug reporting form wrote: > The following bug has been logged on the website: > > Bug reference: 18351 > > The following script: > ... > VACUUM tbl; > VACUUM FULL tbl; > " | psql -d db$c >psql-2-$c.log 2>&1 & > done > wait > grep 'missing chunk number' server.log && break; > done > > So it looks like recently dead tuples might have no correspondent toast > values to detoast attributes of such tuples. > > Reproduced on REL_12_STABLE .. master. > Probably, the same issue was reported some time ago: > https://www.postgresql.org/message-id/flat/CALdSSPhmqoN02ciT4UxS6ax0N84NpRwPWm87nKJ_%2B0G-Na8qOQ%40mail.gmail.com I've discovered the old bug #5998 https://www.postgresql.org/message-id/flat/201104291506.p3TF6dA9003698%40wwwmaster.postgresql.org with similar symptoms and a very relevant question: > So, how is it that the vacuum removed the underlying toast data but not > the putatively-recently-dead tuple? In fact, the script presented here, produces the error even on 83b758494, so this anomaly is pretty old. But for the given case, the answer to that question is different. With additional debug and verbose logging (on REL_13_STABLE, as lazy_scan_heap() was more flat back then) I see: 2024-02-27 08:22:04.859 UTC|law|db9|65dd9bac.12914b|LOG:  statement: VACUUM (VERBOSE) tbl; 2024-02-27 08:22:04.859 UTC|law|db9|65dd9bac.12914b|LOG: !!!vacuum_rel: relid: 16980, snapshot->xmin: 845, snapshot->xmax: 865 2024-02-27 08:22:04.859 UTC|law|db9|65dd9bac.12914b|LOG: !!!lazy_scan_heap| relname: tbl, blkno: 0, offnum: 1, ItemIdIsDead(itemid): 0 2024-02-27 08:22:04.859 UTC|law|db9|65dd9bac.12914b|LOG: !!!lazy_scan_heap| relname: tbl, blkno: 0, offnum: 1, tuple.t_data->t_choice.t_heap.t_xmin: 859, tuple.t_data->t_choice.t_heap.t_xmax: 864, OldestXmin: 845, HeapTupleSatisfiesVacuum(&tuple, OldestXmin, buf): 2 ### The tbl's tuple is RECENTLY_DEAD ### 2024-02-27 08:22:04.860 UTC|law|db9|65dd9bac.12914b|INFO:  "tbl": found 0 removable, 1 nonremovable row versions in 1 out of 1 pages 2024-02-27 08:22:04.860 UTC|law|db9|65dd9bac.12914b|DETAIL:  1 dead row versions cannot be removed yet, oldest xmin: 845     There were 0 unused item identifiers.     Skipped 0 pages due to buffer pins, 0 frozen pages.     0 pages are entirely empty.     CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s. 2024-02-27 08:22:04.860 UTC|law|db9|65dd9bac.12914b|LOG: !!!lazy_scan_heap| relname: pg_toast_16980, blkno: 0, offnum: 1, ItemIdIsDead(itemid): 1 2024-02-27 08:22:04.860 UTC|law|db9|65dd9bac.12914b|CONTEXT:  while scanning block 0 of relation "pg_toast.pg_toast_16980" 2024-02-27 08:22:04.860 UTC|law|db9|65dd9bac.12914b|LOG: !!!lazy_scan_heap| relname: pg_toast_16980, blkno: 0, offnum: 2, ItemIdIsDead(itemid): 1 2024-02-27 08:22:04.860 UTC|law|db9|65dd9bac.12914b|CONTEXT:  while scanning block 0 of relation "pg_toast.pg_toast_16980" ### But the toast's tuples are DEAD according to their lp_flags ### 2024-02-27 08:22:04.860 UTC|law|db9|65dd9bac.12914b|INFO: "pg_toast_16980": found 2 removable, 0 nonremovable row versions in 1 out of 1 pages 2024-02-27 08:22:04.860 UTC|law|db9|65dd9bac.12914b|DETAIL:  0 dead row versions cannot be removed yet, oldest xmin: 866     There were 0 unused item identifiers.     Skipped 0 pages due to buffer pins, 0 frozen pages.     0 pages are entirely empty.     CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s. 2024-02-27 08:22:04.861 UTC|law|db9|65dd9bac.12914b|STATEMENT: VACUUM FULL tbl; 2024-02-27 08:22:04.862 UTC|law|db9|65dd9bac.12914b|ERROR:  missing chunk number 0 for toast value 17045 in pg_toast_16980 So in this case, the heap tuple and the pg_toast_xxx tuples are out-of-sync in regard to their DEAD status after DELETE, then VACUUM removes dead tuples from pg_toast_xxx, and the following VACUUM FULL (heapam_relation_copy_for_cluster()) fails to copy the heap tuple in absence of corresponding toast tuples. Best regards, Alexander