BUG #19686: Rolling back SET TABLESPACE + INSERT leads to index corruption

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: exclusion(at)gmail(dot)com
Subject: BUG #19686: Rolling back SET TABLESPACE + INSERT leads to index corruption
Date: 2026-09-13 16:00:01
Message-ID: 19686-30f4da834585129f@postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 19686
Logged by: Alexander Lakhin
Email address: exclusion(at)gmail(dot)com
PostgreSQL version: 19beta3
Operating system: Ubuntu 24.04
Description:

The following script:
rm -rf /tmp/ts
mkdir /tmp/ts

echo "
CREATE TABLESPACE ts LOCATION '/tmp/ts';
CREATE TABLE t (a int);
CREATE INDEX ON t(a);

BEGIN;
ALTER TABLE t SET TABLESPACE ts;
INSERT INTO t VALUES (0);
ROLLBACK;
INSERT INTO t VALUES (0);
INSERT INTO t SELECT i FROM generate_series(1, 4000) i;
" | psql

triggers:
2026-09-13 18:09:42.598 EEST|postgres|regression|6aa6bcb6.297fd6|LOG:
statement: INSERT INTO t SELECT i FROM generate_series(1, 4000) i;
TRAP: failed Assert("_bt_posting_valid(itup)"), File: "nbtdedup.c", Line:
900, PID: 2719702
ExceptionalCondition at assert.c:51:13
_bt_form_posting at nbtdedup.c:905:7
_bt_dedup_finish_pending at nbtdedup.c:584:11
_bt_dedup_pass at nbtdedup.c:173:15
_bt_delete_or_dedup_one_page at nbtinsert.c:2827:3
_bt_findinsertloc at nbtinsert.c:918:4
_bt_doinsert at nbtinsert.c:261:16
btinsert at nbtree.c:219:11
index_insert at indexam.c:231:9

The assertion failure is reproduced starting from 0d861bbb7.

The index corruption is also reproduced with gist:
echo "
CREATE TABLESPACE ts LOCATION '/tmp/ts';
CREATE TABLE t (a int4range);
CREATE INDEX ON t USING gist (a);

BEGIN;
ALTER TABLE t SET TABLESPACE ts;
INSERT INTO t VALUES (int4range(0, 5));
ROLLBACK;
INSERT INTO t VALUES (int4range(0, 5));
" | psql

echo "
SELECT * FROM t;
SET enable_seqscan = off;
SET enable_bitmapscan = off;
EXPLAIN SELECT * FROM t WHERE a && int4range(0, 100);
SELECT * FROM t WHERE a && int4range(0, 100);
" | psql

returns:
ROLLBACK
INSERT 0 1
a
-------
[0,5)
(1 row)

SET
SET
QUERY PLAN
-------------------------------------------------------------------------
Index Only Scan using t_a_idx on t (cost=0.14..40.39 rows=14 width=32)
Index Cond: (a && '[0,100)'::int4range)
(2 rows)

a
-------
[0,5)
[0,5)
(2 rows)

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message shihao zhong 2026-09-14 02:35:00 Re: REPACK (CONCURRENTLY) doesn't handle invalid indexes
Previous Message Álvaro Herrera 2026-09-13 12:27:13 Re: REPACK (CONCURRENTLY) doesn't handle invalid indexes