pg.ddx.io pgvector/pgvector GitHub issues and pull requests
help / color / mirror / Atom feed[pgvector/pgvector] issue #993: HNSW VACUUM can fail with "hnsw graph not repaired" under concurrent insert/delete workload
6+ messages / 2 participants
[nested] [flat]
* [pgvector/pgvector] issue #993: HNSW VACUUM can fail with "hnsw graph not repaired" under concurrent insert/delete workload
@ 2026-06-30 06:05 "cxyybless (@cxyybless)" <noreply+cxyybless@github.com>
0 siblings, 0 replies; 6+ messages in thread
From: cxyybless (@cxyybless) @ 2026-06-30 06:05 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Hi, I'm seeing `ERROR: hnsw graph not repaired` during HNSW
vacuuming when `VACUUM` runs concurrently with an insert/delete/query
workload.
This reproduces with upstream PostgreSQL and upstream pgvector, using a
single table and a single HNSW index.
## Environment
- PostgreSQL: 16.14
- pgvector commit: `f1dd4e3`
- pgvector describe: `v0.8.3-16-gf1dd4e3`
- extension version: `0.8.3`
- OS/arch: Linux x86_64
Recent pgvector commits:
```text
f1dd4e3 Updated urls [skip ci]
7d067d7 Updated changelog [skip ci]
d4dd73d Moved repair confirmation after lock wait to catch more potential issues
ffe28bb Fix HNSW insert and vacuum race
```
PostgreSQL version:
```sql
SELECT version();
```
Output:
```text
PostgreSQL 16.14 on x86_64-pc-linux-gnu, compiled by gcc, 64-bit
```
Extension version:
```sql
SELECT extversion FROM pg_extension WHERE extname = 'vector';
```
Output:
```text
0.8.3
```
## Reproduction
### 1. Create the test table and HNSW index
```sql
CREATE EXTENSION IF NOT EXISTS vector;
DROP SCHEMA IF EXISTS community_repro CASCADE;
CREATE SCHEMA community_repro;
CREATE TABLE community_repro.t (
id bigserial PRIMARY KEY,
v vector(16),
payload text
);
ALTER TABLE community_repro.t SET (autovacuum_enabled = false);
INSERT INTO community_repro.t(v, payload)
SELECT ARRAY[
random(), random(), random(), random(),
random(), random(), random(), random(),
random(), random(), random(), random(),
random(), random(), random(), random()
]::vector,
md5(g::text)
FROM generate_series(1, 8000) g;
CREATE INDEX t_hnsw_l2
ON community_repro.t
USING hnsw (v vector_l2_ops)
WITH (m = 16, ef_construction = 64);
ANALYZE community_repro.t;
SELECT count(*) FROM community_repro.t;
```
Output:
```text
count
-------
8000
```
### 2. Run concurrent insert/delete/query workload
Create `hnsw_repro.sql`:
```sql
\set id random(1, 10000000)
BEGIN;
SET LOCAL hnsw.ef_search = 64;
INSERT INTO community_repro.t(v, payload)
VALUES (
ARRAY[
random(), random(), random(), random(),
random(), random(), random(), random(),
random(), random(), random(), random(),
random(), random(), random(), random()
]::vector,
md5((:id)::text || random()::text)
);
SELECT id
FROM community_repro.t
ORDER BY v <-> ARRAY[
random(), random(), random(), random(),
random(), random(), random(), random(),
random(), random(), random(), random(),
random(), random(), random(), random()
]::vector
LIMIT 8;
DELETE FROM community_repro.t
WHERE id = (
SELECT id
FROM community_repro.t
ORDER BY id
LIMIT 1
FOR UPDATE SKIP LOCKED
);
COMMIT;
```
Run pgbench:
```bash
pgbench -n -c 8 -j 4 -T 60 -P 10 -f hnsw_repro.sql postgres
```
### 3. Run VACUUM concurrently in another session
While pgbench is running, run:
```bash
while true; do
date '+%F %T'
psql -v ON_ERROR_STOP=1 -c "VACUUM (ANALYZE) community_repro.t;"
sleep 1
done
```
## Actual result
The pgbench workload completed successfully:
```text
pgbench (16.14)
progress: 10.0 s, 1137.0 tps, lat 7.030 ms stddev 0.722, 0 failed
progress: 20.0 s, 1094.7 tps, lat 7.308 ms stddev 0.360, 0 failed
progress: 30.0 s, 1062.8 tps, lat 7.527 ms stddev 0.415, 0 failed
progress: 40.0 s, 1030.1 tps, lat 7.767 ms stddev 0.464, 0 failed
progress: 50.0 s, 1000.0 tps, lat 7.999 ms stddev 0.450, 0 failed
progress: 60.0 s, 967.5 tps, lat 8.267 ms stddev 0.473, 0 failed
number of transactions actually processed: 62929
number of failed transactions: 0 (0.000%)
tps = 1048.793488
```
However, one of the concurrent VACUUM attempts failed:
```text
2026-06-30 05:37:53
VACUUM
2026-06-30 05:37:54
VACUUM
2026-06-30 05:37:57
ERROR: hnsw graph not repaired
CONTEXT: while vacuuming index "t_hnsw_l2" of relation "community_repro.t"
```
PostgreSQL server log:
```text
ERROR: XX000: hnsw graph not repaired
CONTEXT: while vacuuming index "t_hnsw_l2" of relation "community_repro.t"
```
The server did not crash.
After the workload stopped, a manual VACUUM succeeded:
```sql
VACUUM (ANALYZE) community_repro.t;
```
And HNSW index scans still worked:
```sql
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
SELECT id
FROM community_repro.t
ORDER BY v <-> ARRAY[
0.11,0.12,0.13,0.14,
0.15,0.16,0.17,0.18,
0.19,0.20,0.21,0.22,
0.23,0.24,0.25,0.26
]::vector
LIMIT 5;
```
Plan:
```text
Limit (actual rows=5 loops=1)
-> Index Scan using t_hnsw_l2 on t (actual rows=5 loops=1)
Order By: (v <-> '[0.11,0.12,0.13,0.14,0.15,0.16,0.17,0.18,0.19,0.2,0.21,0.22,0.23,0.24,0.25,0.26]'::vector)
```
## Expected behavior
I'm not sure what the intended behavior should be here.
Is `ERROR: hnsw graph not repaired` expected as a defensive failure during
concurrent HNSW VACUUM, or should VACUUM avoid exposing this error to
users by retrying/repairing until the graph is fully repaired?
This looks related to the recent HNSW vacuum fixes around #988 and the
post-repair confirmation pass. This test was run on current master after
those changes, so I wanted to check whether this is a known remaining
race or if it should be investigated as a new issue.
## Notes
- The reproduction uses only one table and one HNSW index.
- `autovacuum` is disabled for the test table, and VACUUM is run manually
in a loop.
- The workload keeps the table size roughly stable by inserting one row
and deleting one row per transaction.
- The failure did not crash the server, but it caused the concurrent
VACUUM command to fail.
^ permalink raw [nested|flat] 6+ messages in thread
* Re: [pgvector/pgvector] issue #993: HNSW VACUUM can fail with "hnsw graph not repaired" under concurrent insert/delete workload
@ 2026-06-30 06:31 "ankane (@ankane)" <noreply+ankane@github.com>
4 siblings, 0 replies; 6+ messages in thread
From: ankane (@ankane) @ 2026-06-30 06:31 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Hi @cxyybless, thanks for reporting. Will see what's going on.
^ permalink raw [nested|flat] 6+ messages in thread
* Re: [pgvector/pgvector] issue #993: HNSW VACUUM can fail with "hnsw graph not repaired" under concurrent insert/delete workload
@ 2026-06-30 07:04 "ankane (@ankane)" <noreply+ankane@github.com>
4 siblings, 0 replies; 6+ messages in thread
From: ankane (@ankane) @ 2026-06-30 07:04 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
It looks like the error is a false positive. Will spend some time tomorrow to figure out the best way to resolve (possibly removing the check).
^ permalink raw [nested|flat] 6+ messages in thread
* Re: [pgvector/pgvector] issue #993: HNSW VACUUM can fail with "hnsw graph not repaired" under concurrent insert/delete workload
@ 2026-06-30 07:36 "ankane (@ankane)" <noreply+ankane@github.com>
4 siblings, 0 replies; 6+ messages in thread
From: ankane (@ankane) @ 2026-06-30 07:36 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
@ankane closed this.
^ permalink raw [nested|flat] 6+ messages in thread
* Re: [pgvector/pgvector] issue #993: HNSW VACUUM can fail with "hnsw graph not repaired" under concurrent insert/delete workload
@ 2026-06-30 07:40 "ankane (@ankane)" <noreply+ankane@github.com>
4 siblings, 0 replies; 6+ messages in thread
From: ankane (@ankane) @ 2026-06-30 07:40 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Pushed a fix in the commit above (which should also eliminate unnecessary vacuuming).
^ permalink raw [nested|flat] 6+ messages in thread
* Re: [pgvector/pgvector] issue #993: HNSW VACUUM can fail with "hnsw graph not repaired" under concurrent insert/delete workload
@ 2026-06-30 22:29 "ankane (@ankane)" <noreply+ankane@github.com>
4 siblings, 0 replies; 6+ messages in thread
From: ankane (@ankane) @ 2026-06-30 22:29 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
0.8.4 is now available with the fix.
^ permalink raw [nested|flat] 6+ messages in thread
end of thread, other threads:[~2026-06-30 22:29 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-06-30 06:05 [pgvector/pgvector] issue #993: HNSW VACUUM can fail with "hnsw graph not repaired" under concurrent insert/delete workload "cxyybless (@cxyybless)" <noreply+cxyybless@github.com>
2026-06-30 06:31 ` "ankane (@ankane)" <noreply+ankane@github.com>
2026-06-30 07:04 ` "ankane (@ankane)" <noreply+ankane@github.com>
2026-06-30 07:36 ` "ankane (@ankane)" <noreply+ankane@github.com>
2026-06-30 07:40 ` "ankane (@ankane)" <noreply+ankane@github.com>
2026-06-30 22:29 ` "ankane (@ankane)" <noreply+ankane@github.com>
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