Use GlobalVisState in vacuum to determine page level visibility
Melanie Plageman <melanieplageman@gmail.com>
Author:
Melanie Plageman <melanieplageman@gmail.com>
Date: 2026-03-24T18:50:59Z
Releases:
19 (unreleased)
Use GlobalVisState in vacuum to determine page level visibility During vacuum's first and third phases, we examine tuples' visibility to determine if we can set the page all-visible in the visibility map. Previously, this check compared tuple xmins against a single XID chosen at the start of vacuum (OldestXmin). We now use GlobalVisState, which enables future work to set the VM during on-access pruning, since ordinary queries have access to GlobalVisState but not OldestXmin. This also benefits vacuum: in some cases, GlobalVisState may advance during a vacuum, allowing more pages to become considered all-visible. And, in the future, we could easily add a heuristic to update GlobalVisState more frequently during vacuums of large tables. OldestXmin is still used for freezing and as a backstop to ensure we don't freeze a dead tuple that wasn't yet prunable according to GlobalVisState in the rare occurrences where GlobalVisState moves backwards. Because comparing a transaction ID against GlobalVisState is more expensive than comparing against a single XID, we defer this check until after scanning all tuples on the page. Therefore, we perform the GlobalVisState check only once per page. This is safe because visibility_cutoff_xid records the newest live xmin on the page; if it is globally visible, then the entire page is all-visible. Using GlobalVisState means on-access pruning can also maintain visibility_cutoff_xid, which is required to set the visibility map on-access in the future. Author: Melanie Plageman <melanieplageman@gmail.com> Reviewed-by: Andres Freund <andres@anarazel.de> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Reviewed-by: Kirill Reshke <reshkekirill@gmail.com> Discussion: https://postgr.es/m/flat/bqc4kh5midfn44gnjiqez3bjqv4zogydguvdn446riw45jcf3y%404ez66il7ebvk#c755ef151507aba58471ffaca607e493
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/access/heap/heapam_visibility.c | modified | +3 −2 |
| src/backend/access/heap/pruneheap.c | modified | +28 −26 |
| src/backend/access/heap/vacuumlazy.c | modified | +42 −18 |
| src/backend/access/spgist/spgvacuum.c | modified | +1 −1 |
| src/backend/storage/ipc/procarray.c | modified | +39 −6 |
| src/include/utils/snapmgr.h | modified | +9 −2 |
Discussion
Cited messages not in the archive:
flat/bqc4kh5midfn44gnjiqez3bjqv4zogydguvdn446riw45jcf3y@4ez66il7ebvk#c755ef151507aba58471ffaca607e493