aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Geoghegan <pg@bowt.ie>2023-06-21 17:41:50 -0700
committerPeter Geoghegan <pg@bowt.ie>2023-06-21 17:41:50 -0700
commit355917c07c633ab00e41c91eef262b3e438a63e4 (patch)
treed1a47144c8714e14e140cb2f0fa9b211e93a4454
parent9b4c44fef81918393fd2e770867041601d9a40c2 (diff)
downloadpostgresql-355917c07c633ab00e41c91eef262b3e438a63e4.tar.gz
postgresql-355917c07c633ab00e41c91eef262b3e438a63e4.zip
nbtree VACUUM: cope with topparent inconsistencies.
Avoid "right sibling %u of block %u is not next child" errors when vacuuming a corrupt nbtree index. Just LOG the issue and press on. That way VACUUM will have a decent chance of finishing off all required processing for the index (and for the table as a whole). This is similar to recent work from commit 5abff197, as well as work from commit 5b861baa (later backpatched as commit 43e409ce), which taught nbtree VACUUM to keep going when its "re-find" check fails. The hardening added by this commit takes place directly after the "re-find" check, right before the critical section for the first stage of page deletion. Author: Peter Geoghegan <pg@bowt.ie> Discussion: https://postgr.es/m/CAH2-Wz=dayg0vjs4+er84TS9ami=csdzjpuiCGbEw=idhwqhzQ@mail.gmail.com Backpatch: 11- (all supported versions).
-rw-r--r--src/backend/access/nbtree/nbtpage.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/backend/access/nbtree/nbtpage.c b/src/backend/access/nbtree/nbtpage.c
index 5ebfd845cf8..0d731b18016 100644
--- a/src/backend/access/nbtree/nbtpage.c
+++ b/src/backend/access/nbtree/nbtpage.c
@@ -1686,9 +1686,19 @@ _bt_mark_page_halfdead(Relation rel, Buffer leafbuf, BTStack stack)
itemid = PageGetItemId(page, nextoffset);
itup = (IndexTuple) PageGetItem(page, itemid);
if (BTreeInnerTupleGetDownLink(itup) != rightsib)
- elog(ERROR, "right sibling %u of block %u is not next child %u of block %u in index \"%s\"",
- rightsib, target, BTreeInnerTupleGetDownLink(itup),
- BufferGetBlockNumber(topparent), RelationGetRelationName(rel));
+ {
+ ereport(LOG,
+ (errcode(ERRCODE_INDEX_CORRUPTED),
+ errmsg_internal("right sibling %u of block %u is not next child %u of block %u in index \"%s\"",
+ rightsib, target,
+ BTreeInnerTupleGetDownLink(itup),
+ BufferGetBlockNumber(topparent),
+ RelationGetRelationName(rel))));
+
+ _bt_relbuf(rel, topparent);
+
+ return false;
+ }
/*
* Any insert which would have gone on the leaf block will now go to its