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.96) (envelope-from ) id 1wgt7P-006TbQ-27 for pgsql-bugs@arkaria.postgresql.org; Mon, 06 Jul 2026 23:52:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wgt6P-003loQ-0J for pgsql-bugs@arkaria.postgresql.org; Mon, 06 Jul 2026 23:51:53 +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.96) (envelope-from ) id 1wgt6O-003loI-2G for pgsql-bugs@lists.postgresql.org; Mon, 06 Jul 2026 23:51:52 +0000 Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wgt6M-00000001vVG-2Vaf for pgsql-bugs@lists.postgresql.org; Mon, 06 Jul 2026 23:51:51 +0000 Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-5aebfa21c62so4276394e87.3 for ; Mon, 06 Jul 2026 16:51:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1783381904; cv=none; d=google.com; s=arc-20260327; b=il8ITzJMWXor+NJQBsgc5hy3r0c8O092sUpccaxqXyO33zQpKnpTBFN0CA8/WJUYPM F0IaNaOe9bNFrqQuycQSJ4zRY6kt64q74Oqk0ziPAZu7OEvH93NkyoDCc61rAWkNdFox /xiKFwg+5i8wzaEMiaGlF5XmkyPD/oTpRMgW9OoRBNKgle3M4y3Rz6/M0zvs//c3F5Pr 1NNfWaCIFu/rtNbbYGTpwNg5gToDG2GWp0MXeX7Ufv6bViwKKB4kYXkSBCvmnch87QIZ ASC9cPjafJQAJ536IB5DZLLIdnDpM6JWsT6TGciZW2MLd8SHtXpY/BVpVBoBe87k4hmG 1plw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=qO1uJw9oOhonwNI3rJkpMIysICvT0RCEJ2yO1VHWLwk=; fh=7Y6LaaeCv2JO+FuLcpHByYJC6jaXC5k6AsaylHLsPPQ=; b=TS4AZe8JQ7fghEzoN7oC+S//vW2J7HXLduInVDoq3xuBQRtaRl6qG1oUb5j1PBhPgQ wy2/njsOs6OD+bVkNjfkJvs2Uo1vDg2rZ2WeItPI1CGldAyaWSVYF9fD6ZFCVO0s7Wvy dTN6RhB9PGHtXObGx678bOx064nM6KZxTjhFlVJna18Mgmd7hhLRwZdoZuA1sKk5Zjb9 mD7/qUWyNmSWRxrBitfcpxa82MY1BsEE0GDV68qUZOVRrQ5Fq4x5zFWNudD4O6p+Tylc VnSEHoWBWbkf4SyM6Dp7xIucy7MX8a2YOqgaLvLvU9OVncMaDOrG6ubs/kTfAp8G/wQO iKng==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783381904; x=1783986704; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=qO1uJw9oOhonwNI3rJkpMIysICvT0RCEJ2yO1VHWLwk=; b=GW/ZSTGFTjptzXni0PHUKO6sk2ZmqYpMY0M78u9V9ADz4s71INfQuvXFbdSnCXVwRy gsY15ZenhBlfHOM/7ktDA/2seGqmnMt3Dvl3THga2vGkz7j19R5AVvd+9KO8x85VnQPM dE7QYKv+CIUdcnNgfvyEn9TGzfy88+tSS+IwtjuNsPVF3NghQNLBOu8TPnU+lbxLBZrV 2gl28UBbbd7BQlGX6WpHv6zKh+2giocpA+OGht5kvvrfBNCfndAE7bIiQeJrpRo/LHI7 IcyicVydIgK4FXtERpKaxkI3HrzflZyAtcQbJmw4S6aKPzihg0LrSOn3Rfx1H9v5kkzo KSZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783381904; x=1783986704; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=qO1uJw9oOhonwNI3rJkpMIysICvT0RCEJ2yO1VHWLwk=; b=agOcrxlQ+jKUtXGhcQbr8TXHLyM9wB51aaMD6aRmg49PjIaQLHRCpFkar48PS/ATYz g9shDsqBa6Z18vqw1AwdIzdtov2uIo/bIm2EZexKvi3X44wltIjDKx6rnZZk0VZGLnkp z1hhuEt1PAK7Icjb9P0wOFcKPZNRi+Cbv4URFUZg2FwzXNXUMMA4o66gSC7p3Sqq7hGn +GJNKJq2wDp7IX8t02umht5M0GJS2si1302IHVTC+d6emCUOV+ZeEvfrxrfJmguQaJRY ZfezrPcHNfTFXqfrlkgOQESI9dA9XOvfLneiRn+OlUx/5iOaMAgKXq6FY+jfqDLI+4Tc VLgA== X-Forwarded-Encrypted: i=1; AHgh+RpsMjRHp/8MebX314PxiHZ2oOlBHHjqpGhUYelWyOgmx+rSDYLGYW+ogfD1SQZ77WNapyc6stLHvqFi@lists.postgresql.org X-Gm-Message-State: AOJu0Yz7YYveT+vs3DHW0HGfT6/m1u8EAOtjif5EBhmTg6iiZqO3DMZM C9OuCsNr9Mhkyi+GusHrP+IHqtnzDtpCpQ2XUKtHK0h2rTWt7ccKePOq2EXh5aZpmbo/Qui6aCc wBlv0jEzNzCy236Sn3aoIk+yarmPGwHqP8HVq X-Gm-Gg: AfdE7cluVlFd3CwcEjNxiK+0z/4v8gvLLwwT83ygcK3U1LnQykGc0vD92taw8+z6B4k 90sOcNVzOOuLY2tu2+gByJApAyJpEFqXjLWNKaorgHwRke/E2u7voWvbT72f8tEHCBmIa/brKpw jELnOeVPPY22MLwB4Huxr5r0ZcNE+rGfSlaD/z/rF6TnljS1duLJnUffLb1aP8/WCe1psJ9nPwZ BDAMOY4CX7BXg6V12QSYI585leTDGNdqrdqRKYy0OxbXtsTtq93RbA0lEJamh1cSLvlI7eA67aK IP3atlW65MF4bXcfRZ4QxV4NCC86Egi1tSUZo1aHH79r45VHAHvOeldpZaOPZ71fnQvLy53C X-Received: by 2002:a05:6512:350a:b0:5ae:c454:3741 with SMTP id 2adb3069b0e04-5b007c2bdedmr642030e87.16.1783381903590; Mon, 06 Jul 2026 16:51:43 -0700 (PDT) MIME-Version: 1.0 References: <19519-fe02d8ff679d834d@postgresql.org> In-Reply-To: From: Matthias van de Meent Date: Tue, 7 Jul 2026 01:51:32 +0200 X-Gm-Features: AVVi8CfdZWhRfV37SaCJwQ9V2atOJ50e9un_ntLkkk81hjuPOAoYplzeFg111vI Message-ID: Subject: Re: BUG #19519: REPACK can fail due to missing chunk for toast value To: Michael Paquier Cc: Imran Zaheer , Srinath Reddy Sadipiralla , Alexander Lakhin , PostgreSQL mailing lists , Konstantin Knizhnik Content-Type: multipart/alternative; boundary="000000000000dcc9560655f9f49e" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000dcc9560655f9f49e Content-Type: text/plain; charset="UTF-8" On Tue, 7 Jul 2026, 01:19 Michael Paquier, wrote: > On Mon, Jul 06, 2026 at 08:21:41PM +0200, Matthias van de Meent wrote: > > So, in effect, this is an issue that's quite similar to the CIC/RIC > > bug of PG14<14.4, except that > > > > 1.) in this case it's SnapshotAny instead of a > > registered-but-invisible MVCC snapshot; > > 2.) the issue in this case only happens when toast pointers were > > cleaned up and then are dereferenced, rather than HOT chains updated > > and reclaimed since the scan started; and finally > > 3.) this issue dates back a very long time, likely since TOAST, but > > defininitely since PG14 introduced the GlobalVisTestFor apis. > > You mean 042b584c7f7d, revert of d9d076222f5b. That rings a bell. > Indeed > > So I think the only way to fix this is either > > 1.) we update every maintenance process that makes use of SnapshotAny > > and could access TOAST tables to handle errors caused by missing TOAST > > data when the base relation's tuple is RECENTLY_DEAD, and treat those > > as "tuple cleanup has already started, we just weren't aware of it > > yet, so ignore this tuple" (as I mentioned in [1]), or > > That seems like an option worth exploring to me, but I doubt that > we'll be able to get something that can be backpatched due to how > invasive it is. I strongly suspect that it would require at least one > table AM change to cope with the fact that we want to let the callers > be OK with TOAST chunks missing in some contexts when grabbing a toast > slice. That's perhaps for the best if we think about potential > regressions, this is scary and old enough that we may still be OK by > living without a backpatch. > I suspect that for indexing we're lucky, in that we have full control internally over which tuple data get fed into IndexBuildCallback. We can make sure only fully detoasted attributes get passed on, and can be implemented with some (a lot) of TRY/CATCH work in or around FormIndexDatum. That said, I don't think that's very nice, and I'm also a bit concerned about leaking things (memory, buffers, ...) in such an approach. For REPACK/VACUUM FULL/CLUSTER, I think we can do something similar, given that this code too has a central loop processing the tuple data, though I suspect it'll need a bit more work than the reindex one. > 2.) we set the xmin of the CI/R backend to the current OldestXmin for > > the relation(s) we're currently processing, and so block all cleanup > > of the relevant (toast) data for the duration of this statement or > > whenever we check for a newer xmin for the relation (whilst ignoring > > our current one). > > Err, I don't think that would be safe anyway? It's rather uncommon in > practice in schemas, but we could trigger function calls, like index > expressions, domains, whatever, that access data of other tables while > processing one table with a SnapshotAny. The CIC revert of 14.4 was > about such cases. > True, but in indexes that is forbidden: mislabeling of non-INMUTABLE functions causes broken indexes every day, and we can't be expected to make it work there. Similarly, for REPACK it shouldn't evaluate any non-indexable expressions, right? Either way, if we can register a snapshot in the REPACK/INDEX backend whose xmin is (*correctly*) registered with the OldestNonRemovableTransactionId() of the relation, then concurrent cleanup won't happen for toast, and we'd also avoid dereferencing those dangling toast pointers. We won't need to actually use that snapshot for any scans; it'll avoid the issue as long as our backend advertises an xmin <= the OldestXmin used in maintenance to hold back pruning/vacuum on the relation. (we can adjust that xmin every once in a while with a newer OldestNonRemovableTransactionId (excl. our own backend) as long as we also adjust the OldestXmin cutoff for the SnapshotAny visibility tests, but I don't suggest to backpatch that even newer system, it'd add significant complications to an already complicated system) - Matthias ps. sorry for the formatting, I'm writing this on my phone. --000000000000dcc9560655f9f49e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable





<= div dir=3D"auto">True, but in indexes that is forbidden: mislabeling of non= -INMUTABLE functions causes broken indexes every day, and we can't be e= xpected to make it work there. Similarly, for REPACK it shouldn't evalu= ate any non-indexable expressions, right?

=
Either way, if we can register a snapshot in the REPACK/I= NDEX backend whose xmin is (*correctly*) registered with the OldestNonRemov= ableTransactionId() of the relation, then concurrent cleanup won't happ= en for toast, and we'd also avoid dereferencing those dangling toast po= inters. We won't need to actually use that snapshot for any scans; it&#= 39;ll avoid the issue as long as our backend advertises an xmin <=3D the= OldestXmin used in maintenance to hold back pruning/vacuum on the relation= .

(we can adjust that xm= in every once in a while with a newer OldestNonRemovableTransactionId (excl= . our own backend) as long as we also adjust the OldestXmin cutoff for the = SnapshotAny visibility tests, but I don't suggest to backpatch that eve= n newer system, it'd add significant complications to an already compli= cated system)


=
- Matthias

ps. sorry for the formatting, I'm writing this on my phone.
<= /div> --000000000000dcc9560655f9f49e--