pgsql: Fix GIN VACUUM posting tree root split bug.

From: Peter Geoghegan <pg(at)bowt(dot)ie>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix GIN VACUUM posting tree root split bug.
Date: 2026-08-19 16:31:24
Message-ID: E1wwjCE-00000001Eyw-3rR0@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix GIN VACUUM posting tree root split bug.

ginVacuumPostingTreeLeaves swaps a shared buffer lock for an exclusive
one when it encounters a leaf page. It neglected to re-verify whether a
page that was initially a leaf root page became an internal page due to
a concurrent root page split (during the window when no lock was held).
It was therefore possible for GIN VACUUM to spuriously treat an internal
page as a leaf page, leading to data corruption. VACUUM could miss dead
TIDs that it was required to remove, leaving behind dangling references
in the index.

To fix, re-verify that a leaf page is still a leaf page after an
exclusive lock is acquired. If it isn't, drop our exclusive lock and
acquire a shared lock so that the non-leaf root page gets processed in
the usual way.

Oversight in commit fd83c83d, which fixed a deadlock bug in GIN posting
tree vacuuming.

Author: Peter Geoghegan <pg(at)bowt(dot)ie>
Reviewed-by: Andrey Borodin <x4mmm(at)yandex-team(dot)ru>
Discussion: https://postgr.es/m/CAH2-Wz=RBpJTQgvOxr6C=J04dExmFSt1E3F-r+cRTQ56hEotkg@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/dd1634ddbdbb72deb43482c9b6435c7a9c38da9a

Modified Files
--------------
src/backend/access/gin/ginvacuum.c | 10 ++++++++++
1 file changed, 10 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Previous Message Peter Geoghegan 2026-08-19 16:31:23 pgsql: Fix GIN VACUUM posting tree root split bug.