diff --git a/src/backend/access/heap/visibilitymap.c b/src/backend/access/heap/visibilitymap.c index aeb615ec531..deaeebf02be 100644 --- a/src/backend/access/heap/visibilitymap.c +++ b/src/backend/access/heap/visibilitymap.c @@ -85,8 +85,12 @@ * * Setting or clearing VM bits requires locks on both the heap and VM buffers. * The heap buffer lock keeps the heap page and its VM bits consistent, while - * the exclusive VM buffer lock protects the VM page. Callers acquire the VM - * lock after the heap buffer lock and before entering the critical section. + * the exclusive VM buffer lock protects the VM page. In particular, holding + * the heap buffer lock while setting a bit prevents the race where VACUUM + * sees that all tuples on the page are visible to everyone, but another + * backend modifies the page before VACUUM sets the bit in the visibility map. + * Callers acquire the VM lock after the heap buffer lock and before entering + * the critical section. * Both locks are held throughout the critical section, including WAL insertion * and updating the page LSNs. The VM buffer must remain locked while the WAL * record is constructed, since the record may include a full-page image of it.