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 1stiVx-0012Y2-Qo for pgsql-bugs@arkaria.postgresql.org; Thu, 26 Sep 2024 07:02:14 +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 1stiVv-003cPT-HU for pgsql-bugs@arkaria.postgresql.org; Thu, 26 Sep 2024 07:02:11 +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 1stiVu-003cKg-7V for pgsql-bugs@lists.postgresql.org; Thu, 26 Sep 2024 07:02:11 +0000 Received: from fhigh-a4-smtp.messagingengine.com ([103.168.172.155]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1stiVp-0019OG-4f for pgsql-bugs@lists.postgresql.org; Thu, 26 Sep 2024 07:02:09 +0000 Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfhigh.phl.internal (Postfix) with ESMTP id 00901114015E; Thu, 26 Sep 2024 03:02:04 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-10.internal (MEProxy); Thu, 26 Sep 2024 03:02:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1727334123; x=1727420523; bh=p7Tp12jUjS f5PJODDC6RbsBz59Pmy7cISQv2SH+YMzM=; b=C0QD9QxFAx3PxIn4pv/qbcKm1w CSFmRKXTWiM6eJAmvnwLr33mmYExt2Zm1q0E6Y8ITarhs7f8nZuSoQC4ZFosPFAG Cy1cH5W+vVuC0RxEXWnVMU6ftFIYtT8a/cQ64Na8aQdnRnLPfmRcHd27BVK/sKEW gXT2ESL45YTqN0FSz02J8tlRR+ooFm/i6zAFZ6dhWEGimypun9jve9ZUlze0GcD3 xsUD1bj9ikVC/MBXvuZCcc2iyCaiR1jtng6odI4hh618xRR5OKQZh6B4uwAwsRDo tOqw4u8q5vRuqukQpcx64k+kX5ew3YETNyq6kSQ0lJM0hhBRysOl1KNm6L4g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1727334123; x=1727420523; bh=p7Tp12jUjSf5PJODDC6RbsBz59Pm y7cISQv2SH+YMzM=; b=DytVzPlvarVttnRC05yzYkXMKWyNGXLmL5Oldsy8pq89 Fskkc+xfvPIVxQ69N2lp6VTTZD2pTD66hMHu1BQajhlsqJhm8nf0pMpl1G6Pdzf9 4nGaz9VTsDW5gzDHz47LoUtJpaEFQaF1xf0ZRq+G9sQu7L0W42mjecWFcOtsLJRh /vXEMVNWNTI+j2IJpObRyfPuNr0uGihtnQ0Dhh6ErRtllrjox3fBB9d5HFdutd9G W6umi8yoCfGgdq9AIqYtLKoFOFfWmFW+WKynTEx6kiABJ48TizQpkMu0VrPeJUsk WAaktBk6PIuUYdeqL/tNIyJuy7E42zlf1i+fR20bAA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtiedgudduiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenfghrlhcuvffnffculdejtddmnecujfgurhepfffhvfevuffk fhggtggujgesghdtreertddtvdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrh cuoehmihgthhgrvghlsehprghquhhivghrrdighiiiqeenucggtffrrghtthgvrhhnpeet leeifedufffhhfdtteelgeeggeffhfekueevteeigfduudevudetgfegiedvjeenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghl sehprghquhhivghrrdighiiipdhnsggprhgtphhtthhopeefpdhmohguvgepshhmthhpoh huthdprhgtphhtthhopehtnhgurhifrghnghesghhmrghilhdrtghomhdprhgtphhtthho pegvgigtlhhushhiohhnsehgmhgrihhlrdgtohhmpdhrtghpthhtohepphhgshhqlhdqsg hughhssehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Sep 2024 03:02:02 -0400 (EDT) Date: Thu, 26 Sep 2024 16:01:42 +0900 From: Michael Paquier To: Tender Wang Cc: exclusion@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18630: Incorrect memory access inside ReindexIsProcessingIndex() on VACUUM Message-ID: References: <18630-9aed99c38830657d@postgresql.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="sOdwi4Zf5jAWQHGt" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --sOdwi4Zf5jAWQHGt Content-Type: multipart/mixed; boundary="Vg1mJ5IvzsT0S5Um" Content-Disposition: inline --Vg1mJ5IvzsT0S5Um Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Sep 25, 2024 at 06:19:20PM +0800, Tender Wang wrote: > Adding if (flags & REINDEX_REL_SUPPRESS_INDEX_USE) check before calling > RemoveReindexPending() may look better. > Any thoughts? The short answer to that is yes, see below. Alexander's trick presented upthread is funky. I was first confused of what was the point until I noticed that this is just a way to make REINDEX CONCURRENTLY fail and produce an invalid toast index. The first pg_sleep causes REINDEX to fail because we are waiting for the first transaction to complete. So this provides a controlled way to get an index that should never be part of the list reported to SetReindexPending() to begin with. The VACUUM (PROCESS_MAIN FALSE, FULL) is then disturbed. Anyway, PROCESS_MAIN is not related to the failure, as it is just a flavor grammar introduced for the sake of making toast-only rebuilds easier for administrators. The same failure reproduces if switching the test case of upthread to do the REINDEX on the toast table, down to 12 which is as far as I have tested because that's what we support around here. Regarding the fix, we should not disturb the list of indexes in a relation returned by relcache.c, and invalid indexes are part of it. So I'd agree with your point to just remove the index from the pending list because we have to skip invalid toast indexes in the reindex_relation() path as reindex_index() has to generate a hard failure because we can never ever have two valid toast indexes, and that's a guarantee we need to be very careful about. Now, about REINDEX_REL_SUPPRESS_INDEX_USE. Well, that's only used for the VACUUM FULL/CLUSTER path which is where the indexes are marked as being processed, so we have to reomve the invalid toast indexes from the list only if this flag is used. Hence the answer is yes. I'd rather keep the informative warning. That's useful for monitoring purposes. Something worth noting while I have looked at this code.. Non-toast invalid indexes are rebuilt but still marked as !indisvalid, actually. That's a waste and we could just skip them for a CLUSTER/VACUUM FULL. This cannot be true for a REINDEX TABLE, invalid indexes are switched to valid in this case. -- Michael --Vg1mJ5IvzsT0S5Um Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-Remove-invalid-toast-indexes-from-reindex-processing.patch" Content-Transfer-Encoding: quoted-printable =46rom 4dc38bc64d96764c4673a73f646c26252bb7fe33 Mon Sep 17 00:00:00 2001 =46rom: Michael Paquier Date: Thu, 26 Sep 2024 15:59:59 +0900 Subject: [PATCH] Remove invalid toast indexes from reindex processing list = in VACUUM FULL Blah, blah... Backpatch-through: 12 --- src/backend/catalog/index.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index d0dcbf318d..3a4f2e260d 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -3989,6 +3989,14 @@ reindex_relation(const ReindexStmt *stmt, Oid relid,= int flags, errmsg("cannot reindex invalid index \"%s.%s\" on TOAST table, skipp= ing", get_namespace_name(indexNamespaceId), get_rel_name(indexOid)))); + + /* + * Remove this invalid toast index from the reindex pending list, + * as it is skipped here due to the hard failure that would happen + * in reindex_index() should we try to process it. + */ + if (flags & REINDEX_REL_SUPPRESS_INDEX_USE) + RemoveReindexPending(indexOid); continue; } =20 --=20 2.45.2 --Vg1mJ5IvzsT0S5Um-- --sOdwi4Zf5jAWQHGt Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmb1BtYACgkQnvQgOdby QH0Eig//R5FerHruATeF8NnmfJRNnGREgHyVXbU2go0baP9r9/j+WG8uY25rQUE6 71Y9R4vYl9NYEhtHs+dYERJi7eF+FGDNHnGSKu9wR6psBnVhQ0cXLqKanF4z7FX/ XUfohxUdSXhP4qbdlrBOXx001GKFgyZWDGGd6yzdiiV6SyznuIjjVzwPVsNsfax8 /X44tMrdWtM+9Pl2n4rjAyftl8qnjyWo7WA2/TIVnrlLL/Er4AFsBLDA3a4ZHWlq olecUavGD3ECW9wgaLnMsGnIjWcuU7Kpwt+2hAWft8kEaegilTNkW1qH88yNYwPX tl8tJJqoBqEb7YSwCzGDNwCSPVG6BWjEpEQjErhZmBQtjIvDWB6/jcQMcc5Ygm1j GYkTAQ0UDCYNFtwMjhtKbsF/ip4jqiLqDx9wCV5ns/9OZHyZWj8hUe4fgIBdOLEj la1Qe0Lfd1cr2a0rGlJIfen6aQ4hqtKO++aO9GLiZMh2MV8ws0YuC7mzbMf4kV+A mUhcfY60r1kmT81QD5cF2BF3RKYd+0W4g1OIwmhJ65CzHtbldKzYh/Gef2Etxfly JXdjUJYIK7nVUyExsowGp/WQ7fhKmX0CPraVE7SVIHDUOoI+UVwEk4RnUI1SgE1P RioYujfhEvvSC8t50LeOhaz1aZm/cfA9N+sfKd+ze93VR0N9TbQ= =2IBT -----END PGP SIGNATURE----- --sOdwi4Zf5jAWQHGt--