From: Michael Paquier <michael@paquier.xyz>
To: Tender Wang <tndrwang@gmail.com>
Cc: exclusion@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18630: Incorrect memory access inside ReindexIsProcessingIndex() on VACUUM
Date: Thu, 26 Sep 2024 16:01:42 +0900
Message-ID: <ZvUG1qsjXqppi2BO@paquier.xyz> (raw)
In-Reply-To: <CAHewXNkKeE3i7aT_nysWphRHhwMnyG1r55Di=RCNtLa5dRSd4Q@mail.gmail.com>
References: <18630-9aed99c38830657d@postgresql.org>
<CAHewXNnNZXbq_sW=OP-O-1nnMEnpXJX6djbzF52LtDA6tOutiQ@mail.gmail.com>
<CAHewXNkKeE3i7aT_nysWphRHhwMnyG1r55Di=RCNtLa5dRSd4Q@mail.gmail.com>
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
Attachments:0001-Remove-invalid-toast-indexes-from-reindex-processing.patch (text/x-diff, 1.1K) download
From 4dc38bc64d96764c4673a73f646c26252bb7fe33 Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@paquier.xyz>
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.cindex 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, skipping",
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;
}
--
2.45.2
signature.asc (application/pgp-signature, 832B) download
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: michael@paquier.xyz, tndrwang@gmail.com, exclusion@gmail.com, pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18630: Incorrect memory access inside ReindexIsProcessingIndex() on VACUUM
In-Reply-To: <ZvUG1qsjXqppi2BO@paquier.xyz>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox