Re: eliminate xl_heap_visible to reduce WAL (and eventually set VM on-access)
Melanie Plageman <melanieplageman@gmail.com>
Commits
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Remove table_scan_analyze_next_tuple unneeded parameter OldestXmin
- 284925508ae6 19 (unreleased) landed
-
Simplify visibility check in heap_page_would_be_all_visible()
- 3efe58febc3c 19 (unreleased) landed
-
Eliminate use of cached VM value in lazy_scan_prune()
- 648a7e28d7c2 19 (unreleased) landed
-
Combine visibilitymap_set() cases in lazy_scan_prune()
- 21796c267d0a 19 (unreleased) landed
-
Fix const qualification in prune_freeze_setup()
- 4877391ce894 19 (unreleased) landed
-
Simplify vacuum visibility assertion
- bd298f54a0d6 19 (unreleased) landed
-
Split heap_page_prune_and_freeze() into helpers
- e135e044572e 19 (unreleased) landed
-
Assert that cutoffs are provided if freezing will be attempted
- cd38b7e77315 19 (unreleased) landed
-
Split PruneFreezeParams initializers to one field per line
- 1e14edcea5e1 19 (unreleased) landed
-
Refactor heap_page_prune_and_freeze() parameters into a struct
- 1937ed70621e 19 (unreleased) landed
-
Make heap_page_is_all_visible independent of LVRelState
- 3e4705484e0c 19 (unreleased) landed
-
Inline TransactionIdFollows/Precedes[OrEquals]()
- 43b05b38ea4d 19 (unreleased) landed
-
Add helper for freeze determination to heap_page_prune_and_freeze
- c8dd6542bae4 19 (unreleased) landed
-
Bump XLOG_PAGE_MAGIC after xl_heap_prune change
- 4a8fb58671d3 19 (unreleased) landed
-
Correct prune WAL record opcode name in comment
- ae8ea7278c16 19 (unreleased) landed
-
Add error codes when vacuum discovers VM corruption
- 8ec97e78a771 19 (unreleased) landed
-
Remove unused xl_heap_prune member, reason
- 4b5f206de2bb 19 (unreleased) landed
-
Remove unneeded VM pin from VM replay
- 3399c265543e 19 (unreleased) landed
-
Add assert and log message to visibilitymap_set
- e3d5ddb7ca91 19 (unreleased) landed
-
Add error codes to some corruption log messages
- fd6ec93bf890 13.0 cited
Attachments
- v15-0002-Reorder-heap_page_prune_and_freeze-parameters.patch (text/x-patch) patch v15-0002
- v15-0004-Rename-PruneState.freeze-to-attempt_freeze.patch (text/x-patch) patch v15-0004
- v15-0005-Add-helper-for-freeze-determination-to-heap_page.patch (text/x-patch) patch v15-0005
- v15-0003-Keep-all_frozen-updated-in-heap_page_prune_and_f.patch (text/x-patch) patch v15-0003
- v15-0001-Eliminate-COPY-FREEZE-use-of-XLOG_HEAP2_VISIBLE.patch (text/x-patch) patch v15-0001
- v15-0006-Update-PruneState.all_-visible-frozen-sooner-in-.patch (text/x-patch) patch v15-0006
- v15-0008-Combine-vacuum-phase-I-VM-update-cases.patch (text/x-patch) patch v15-0008
- v15-0009-Vacuum-phase-III-set-PD_ALL_VISIBLE-in-vacuum-WA.patch (text/x-patch) patch v15-0009
- v15-0007-Set-PD_ALL_VISIBLE-in-heap_page_prune_and_freeze.patch (text/x-patch) patch v15-0007
- v15-0010-Log-setting-empty-pages-PD_ALL_VISIBLE-with-XLOG.patch (text/x-patch) patch v15-0010
- v15-0011-Remove-heap-buffer-from-XLOG_HEAP2_VISIBLE-WAL-c.patch (text/x-patch) patch v15-0011
- v15-0012-Make-heap_page_is_all_visible-independent-of-LVR.patch (text/x-patch) patch v15-0012
- v15-0013-Eliminate-XLOG_HEAP2_VISIBLE-from-vacuum-phase-I.patch (text/x-patch) patch v15-0013
- v15-0014-Set-empty-pages-all-visible-in-XLOG_HEAP2_PRUNE_.patch (text/x-patch) patch v15-0014
- v15-0016-Eliminate-XLOG_HEAP2_VISIBLE-from-vacuum-phase-I.patch (text/x-patch) patch v15-0016
- v15-0017-Remove-XLOG_HEAP2_VISIBLE-entirely.patch (text/x-patch) patch v15-0017
- v15-0018-Rename-GlobalVisTestIsRemovableXid-to-GlobalVisX.patch (text/x-patch) patch v15-0018
- v15-0015-Set-VM-in-heap_page_prune_and_freeze.patch (text/x-patch) patch v15-0015
- v15-0020-Inline-TransactionIdFollows-Precedes.patch (text/x-patch) patch v15-0020
- v15-0021-Unset-all-visible-sooner-if-not-freezing.patch (text/x-patch) patch v15-0021
- v15-0019-Use-GlobalVisState-to-determine-page-level-visib.patch (text/x-patch) patch v15-0019
- v15-0022-Allow-on-access-pruning-to-set-pages-all-visible.patch (text/x-patch) patch v15-0022
- v15-0023-Set-pd_prune_xid-on-insert.patch (text/x-patch) patch v15-0023
On Thu, Sep 18, 2025 at 12:48 PM Andres Freund <andres@anarazel.de> wrote:
>
> On 2025-09-17 20:10:07 -0400, Melanie Plageman wrote:
>
> > + /*
> > + * Now read and update the VM block.
> > + *
> > + * Note that the heap relation may have been dropped or truncated, leading
> > + * us to skip updating the heap block due to the LSN interlock.
>
> I don't fully understand this - how does dropping/truncating the relation lead
> to skipping due to the LSN interlock?
Yes, this wasn't right. I misunderstood.
What I think it should say is that if the heap update was skipped due
to LSN interlock we still have to replay the updates to the VM because
each vm page contains bits for multiple heap blocks and if the record
included a vm page FPI, subsequent updates to the VM may rely on this
FPI to avoid torn pages. We don't condition it on the heap redo having
been an FPI, probably because it is not worth it -- but I wonder if
that is worth calling out in the comment?
Do we also need to replay it when the heap redo returns BLK_NOTFOUND?
I assume this can happen in the case of relation dropped or truncated
-- but in this case there wouldn't be subsequent records updating the
VM for other heap blocks that we need to replay because the other heap
blocks won't be found either, right?
> > + if (xlrec->flags & XLH_INSERT_ALL_FROZEN_SET &&
> > + XLogReadBufferForRedoExtended(record, 1, RBM_ZERO_ON_ERROR, false,
> > + &vmbuffer) == BLK_NEEDS_REDO)
> > + {
>
> Why are we using RBM_ZERO_ON_ERROR here? I know it's copied from
> heap_xlog_visible(), but I don't immediately understand (or remember) why we
> do so there either?
It has been RBM_ZERO_ON_ERROR since XLogReadBufferForRedoExtended()
was introduced here in 2c03216d8311.
I think we probably do this because vm_readbuf() passes ReadBuffer()
RBM_ZERO_ON_ERROR and has this comment
* For reading we use ZERO_ON_ERROR mode, and initialize the page if
* necessary. It's always safe to clear bits, so it's better to clear
* corrupt pages than error out.
Do you think I also should have a comment in heap_xlog_multi_insert()?
> > + Page vmpage = BufferGetPage(vmbuffer);
> > + Relation reln = CreateFakeRelcacheEntry(rlocator);
>
> Hm. Do we really need to continue doing this ugly fake relcache stuff? I'd
> really like to eventually get rid of that and given that the new "code shape"
> delegates a lot more responsibility to the redo routines, they should have a
> fairly easy time not needing a fake relcache? Afaict the relation already is
> not used outside of debugging paths?
Yes, interestingly we don't have the relname in recovery anyway, so it
does all this fake relcache stuff only to convert the relfilenode to a
string and uses that.
The fake relcache stuff will still be used by visibilitymap_pin()
which callers like heap_xlog_delete() use to get the VM page. And I
don't think it is worth coming up with a version of that that doesn't
use the relcache. But you're right that the Relation is not needed for
visibilitymap_set_vmbits(). I've changed it to just take the relation
name as a string.
> > + /* initialize the page if it was read as zeros */
> > + if (PageIsNew(vmpage))
> > + PageInit(vmpage, BLCKSZ, 0);
> > +
> > + visibilitymap_set_vmbits(reln, blkno,
> > + vmbuffer,
> > + VISIBILITYMAP_ALL_VISIBLE |
> > + VISIBILITYMAP_ALL_FROZEN);
> > +
> > + /*
> > + * It is not possible that the VM was already set for this heap page,
> > + * so the vmbuffer must have been modified and marked dirty.
> > + */
>
> I assume that's because we a) checked the LSN interlock b) are replaying
> something that needed to newly set the bit?
Yes, perhaps it is not worth having the assert since it attracts extra
attention to an invariant that is unlikely to be in danger of
regression.
> Seems 0002 should just be applied...
Done
> Re 0003: I wonder if it's getting to the point that a struct should be used as
> the argument.
I have been thinking about this. I have yet to come up with a good
idea for a struct name or multiple struct names that seem to fit here.
I could move the other output parameters into the PruneFreezeResult
and then maybe make some kind of PruneFreezeParameters struct or
something?
- Melanie