postgres.git / summary / log / commit / refs
commit e1a327dc4dcbd6ecbc8b97b57a2ffdb20ca2e3f5
Author: Álvaro Herrera <alvherre@kurilemu.de>
Date: Wed Jan 21 17:55:43 2026 +0000
First released in: 14.21, 15.16, 16.12, 17.8, 18.2
amcheck: Fix snapshot usage in bt_index_parent_check
We were using SnapshotAny to do some index checks, but that's wrong and
causes spurious errors when used on indexes created by CREATE INDEX
CONCURRENTLY. Fix it to use an MVCC snapshot, and add a test for it.
Backpatch of 6bd469d26aca to branches 14-16. I previously misidentified
the bug's origin: it came in with commit 7f563c09f890 (pg11-era, not
5ae2087202af as claimed previously), so all live branches are affected.
Also take the opportunity to fix some comments that we failed to update
in the original commits and apply pgperltidy. In branch 14, remove the
unnecessary test plan specification (which would have need to have been
changed anyway; c.f. commit 549ec201d613.)
Diagnosed-by: Donghang Lin <donghanglin@gmail.com>
Author: Mihail Nikalayeu <mihailnikalayeu@gmail.com>
Reviewed-by: Andrey Borodin <x4mmm@yandex-team.ru>
Backpatch-through: 17
Discussion: https://postgr.es/m/CANtu0ojmVd27fEhfpST7RG2KZvwkX=dMyKUqg0KM87FkOSdz8Q@mail.gmail.com
contrib/amcheck/t/002_cic.pl | 3 ++-
contrib/amcheck/verify_nbtree.c | 4 +++-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/contrib/amcheck/t/002_cic.pl b/contrib/amcheck/t/002_cic.pl
index eb41f3bea7c..b49acb2b9ef 100644
--- a/contrib/amcheck/t/002_cic.pl
+++ b/contrib/amcheck/t/002_cic.pl
@@ -74,7 +74,8 @@ $in_progress_h->query_safe(q(BEGIN; SELECT pg_current_xact_id();));
# delete one row from table, while background transaction is in progress
$node->safe_psql('postgres', q(DELETE FROM quebec WHERE i = 1;));
# create index concurrently, which will skip the deleted row
-$node->safe_psql('postgres', q(CREATE INDEX CONCURRENTLY oscar ON quebec(i);));
+$node->safe_psql('postgres',
+ q(CREATE INDEX CONCURRENTLY oscar ON quebec(i);));
# check index using bt_index_parent_check
$result = $node->psql('postgres',
diff --git a/contrib/amcheck/verify_nbtree.c b/contrib/amcheck/verify_nbtree.c
index 32648c6c6d0..120f02cf237 100644
--- a/contrib/amcheck/verify_nbtree.c
+++ b/contrib/amcheck/verify_nbtree.c
@@ -90,9 +90,11 @@ typedef struct BtreeCheckState
BufferAccessStrategy checkstrategy;
/*
- * Info for uniqueness checking. Fill these fields once per index check.
+ * Info for uniqueness checking. Fill this field and the one below once
+ * per index check.
*/
IndexInfo *indexinfo;
+ /* Table scan snapshot for heapallindexed and checkunique */
Snapshot snapshot;
/*
[parent: ad569b54a106]