﻿# PostgreSQL fixes GIN VACUUM paths that could leave dead index entries behind

GIN cleanup fixes prevent missed removals during multi-pass VACUUM and page-split races; suspected existing index corruption still calls for REINDEX.

Author: Retrivium team
Updated: 2026-11-15
Canonical URL: https://retrivium.ai/journal/week46-ops-postgres-gin-vacuum-multiple-scans/
Language: en

PostgreSQL 18.7 repairs GIN cleanup when a VACUUM needs multiple index scans and a related race with leaf-page splits. Missed removals could eventually leave index entries pointing to unrelated table rows. The release recommends REINDEX if this damage is suspected. A completed maintenance command is therefore not sufficient evidence that old GIN contents are sound; the patch prevents specific cleanup failures while existing corruption needs its own assessment.

## Force more than one cleanup pass

The release says one VACUUM may require several index scans when it removes more tuples than it can hold in memory at once. A small fixture that fits entirely in one pass cannot establish the repaired multi-pass behavior. A proposed regression exercise deliberately exceeds that working set and verifies cleanup across passes. The notes do not give a universal tuple threshold; memory settings and index contents define whether the relevant path is reached.

## Dead entries can become wrong references

The documented consequence is not only wasted index space. Entries that should have been removed can later refer to unrelated rows as table storage is reused. Qualification should therefore inspect query correctness and relevant index state, rather than treating reduced index size as the sole success criterion. A smaller index is not proof that every stale reference disappeared. The release identifies a corruption risk, not merely an opportunity to make routine VACUUM more compact.

## Page-split concurrency is a distinct trigger

The same release entry links a second fix involving leaf-page splits during cleanup. A serial multi-pass test does not establish that race handling is correct. Where a concurrency test is used, it needs controlled overlap between mutation and VACUUM plus a correctness oracle, not merely a long stress run that finishes. These are proposed qualification requirements. The release does not publish the probability of the race or a production incident rate that could justify a fixed test duration.

## Preventive maintenance and repair are different

Installing 18.7 prevents the described missed-removal paths going forward. The notes recommend REINDEX when existing damage is suspected, which is a separate repair decision. Record affected GIN indexes, the evidence behind suspicion and any rebuild outcome. A routine VACUUM after updating should not be presented as an automatic reconstruction of every previously corrupted reference. The practical scope is truthful: new cleanup behavior is fixed, while old index integrity must be evaluated and repaired where needed.

## Sources

- [PostgreSQL 18.7 release notes](https://www.postgresql.org/docs/release/18.7/)
- [PostgreSQL upstream change b0a36462b](https://postgr.es/c/b0a36462b)
- [PostgreSQL upstream change 9900966c7](https://postgr.es/c/9900966c7)

## Related reading

- [PostgreSQL and pgvector for RAG on an existing server](/journal/pgvector-rag-server/)
- [A consistent PostgreSQL restore can predate a document deletion](/journal/field-sovereign-postgres-recovery-target-deleted-document-eligibility/)
