Re: Removing more vacuumlazy.c special cases, relfrozenxid optimizations - Mailing list pgsql-hackers
From | Masahiko Sawada |
---|---|
Subject | Re: Removing more vacuumlazy.c special cases, relfrozenxid optimizations |
Date | |
Msg-id | CAD21AoCc48SseGYWFyxaddz41MWDyyOyQDdmNWTfHOpYeNZmww@mail.gmail.com Whole thread Raw |
In response to | Re: Removing more vacuumlazy.c special cases, relfrozenxid optimizations (Peter Geoghegan <pg@bowt.ie>) |
Responses |
Re: Removing more vacuumlazy.c special cases, relfrozenxid optimizations
|
List | pgsql-hackers |
On Thu, Dec 16, 2021 at 5:27 AM Peter Geoghegan <pg@bowt.ie> wrote: > > On Fri, Dec 10, 2021 at 1:48 PM Peter Geoghegan <pg@bowt.ie> wrote: > > * I'm still working on the optimization that we discussed on this > > thread: the optimization that allows the final relfrozenxid (that we > > set in pg_class) to be determined dynamically, based on the actual > > XIDs we observed in the table (we don't just naively use FreezeLimit). > > Attached is v4 of the patch series, which now includes this > optimization, broken out into its own patch. In addition, it includes > a prototype of opportunistic freezing. > > My emphasis here has been on making non-aggressive VACUUMs *always* > advance relfrozenxid, outside of certain obvious edge cases. And so > with all the patches applied, up to and including the opportunistic > freezing patch, every autovacuum of every table manages to advance > relfrozenxid during benchmarking -- usually to a fairly recent value. > I've focussed on making aggressive VACUUMs (especially anti-wraparound > autovacuums) a rare occurrence, for truly exceptional cases (e.g., > user keeps canceling autovacuums, maybe due to automated script that > performs DDL). That has taken priority over other goals, for now. Great! I've looked at 0001 patch and here are some comments: @@ -535,8 +540,16 @@ heap_vacuum_rel(Relation rel, VacuumParams *params, xidFullScanLimit); aggressive |= MultiXactIdPrecedesOrEquals(rel->rd_rel->relminmxid, mxactFullScanLimit); + skipwithvm = true; if (params->options & VACOPT_DISABLE_PAGE_SKIPPING) + { + /* + * Force aggressive mode, and disable skipping blocks using the + * visibility map (even those set all-frozen) + */ aggressive = true; + skipwithvm = false; + } vacrel = (LVRelState *) palloc0(sizeof(LVRelState)); @@ -544,6 +557,7 @@ heap_vacuum_rel(Relation rel, VacuumParams *params, vacrel->rel = rel; vac_open_indexes(vacrel->rel, RowExclusiveLock, &vacrel->nindexes, &vacrel->indrels); + vacrel->aggressive = aggressive; vacrel->failsafe_active = false; vacrel->consider_bypass_optimization = true; How about adding skipwithvm to LVRelState too? --- /* - * The current block is potentially skippable; if we've seen a - * long enough run of skippable blocks to justify skipping it, and - * we're not forced to check it, then go ahead and skip. - * Otherwise, the page must be at least all-visible if not - * all-frozen, so we can set all_visible_according_to_vm = true. + * The current page can be skipped if we've seen a long enough run + * of skippable blocks to justify skipping it -- provided it's not + * the last page in the relation (according to rel_pages/nblocks). + * + * We always scan the table's last page to determine whether it + * has tuples or not, even if it would otherwise be skipped + * (unless we're skipping every single page in the relation). This + * avoids having lazy_truncate_heap() take access-exclusive lock + * on the table to attempt a truncation that just fails + * immediately because there are tuples on the last page. */ - if (skipping_blocks && !FORCE_CHECK_PAGE()) + if (skipping_blocks && blkno < nblocks - 1) Why do we always need to scan the last page even if heap truncation is disabled (or in the failsafe mode)? Regards, -- Masahiko Sawada EDB: https://www.enterprisedb.com/
pgsql-hackers by date: