-
Notifications
You must be signed in to change notification settings - Fork 94
BM25 index scan inside a transaction that is rolled back crashes the PostgreSQL server #247
Copy link
Copy link
Labels
bugSomething isn't workingSomething isn't working
Description
Bug Description
A clear and concise description of the bug.
Environment
- pg_textsearch: 0.5.1
- PostgreSQL: 18.3 (Postgres.app) on aarch64-apple-darwin23.6.0, compiled by Apple clang 15.0.0
- Platform: macOS, Apple Silicon (arm64)
Steps to Reproduce
Minimal reproduction
Any of these three sequences crash the server:
-- (1) ROLLBACK TO SAVEPOINT after BM25 scan
CREATE TEMP TABLE t (id serial, body text);
INSERT INTO t VALUES (DEFAULT, 'hello world'), (DEFAULT, 'foo bar baz');
CREATE INDEX t_idx ON t USING bm25(body) WITH (text_config = 'english');
SAVEPOINT sp1;
SELECT body <@> 'hello' FROM t LIMIT 1;
ROLLBACK TO SAVEPOINT sp1; -- server crashes here
-- (2) Plain ROLLBACK after BM25 scan (same result)
BEGIN;
CREATE TEMP TABLE t2 (id serial, body text);
INSERT INTO t2 VALUES (DEFAULT, 'hello world');
CREATE INDEX t2_idx ON t2 USING bm25(body) WITH (text_config = 'english');
SELECT body <@> 'hello' FROM t2 LIMIT 1;
ROLLBACK; -- server crashes hereExpected Behavior
Server to not crash.
Actual Behavior
Result in both cases:
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
connection to server was lost
Secondary effects
- Connection corruption in application code — when psycopg3 uses a nested transaction (savepoint) to isolate the BM25 query, it logs ResourceOwnerEnlarge called
after release started during the savepoint rollback before the crash fully propagates. The connection ends up in [INERROR] state, is returned to the pool, and the
pool's rollback attempt also fails — discarding the connection and returning a 500 to the client. - Index TOAST corruption after repeated crashes — after the server crashes, subsequent queries against the index fail with:
INFO: Recovering pg_textsearch index NNNN from disk
ERROR: missing chunk number 2 for toast value NNNNN in pg_toast_NNNNN - The index must be dropped and recreated (DROP INDEX … ; CREATE INDEX … USING bm25 …).
Additional Context
n/a
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working