Re: New strategies for freezing, advancing relfrozenxid early
Peter Geoghegan <pg@bowt.ie>
From: Peter Geoghegan <pg@bowt.ie>
To: Jeff Davis <pgsql@j-davis.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, Masahiko Sawada <sawada.mshk@gmail.com>
Date: 2022-09-13T17:53:06Z
Lists: pgsql-hackers
Attachments
- v4-0001-Add-page-level-freezing-to-VACUUM.patch (application/octet-stream) patch v4-0001
- v4-0003-Add-eager-freezing-strategy-to-VACUUM.patch (application/octet-stream) patch v4-0003
- v4-0006-Size-VACUUM-s-dead_items-space-using-VM-snapshot.patch (application/octet-stream) patch v4-0006
- v4-0005-Avoid-allocating-MultiXacts-during-VACUUM.patch (application/octet-stream) patch v4-0005
- v4-0004-Unify-aggressive-VACUUM-with-antiwraparound-VACUU.patch (application/octet-stream) patch v4-0004
- v4-0002-Teach-VACUUM-to-use-visibility-map-snapshot.patch (application/octet-stream) patch v4-0002
On Thu, Sep 8, 2022 at 1:23 PM Peter Geoghegan <pg@bowt.ie> wrote: > Attached is v3. There is a new patch included here -- v3-0004-*patch, > or "Unify aggressive VACUUM with antiwraparound VACUUM". No other > notable changes. > > I decided to work on this now because it seems like it might give a > more complete picture of the high level direction that I'm pushing > towards. Perhaps this will make it easier to review the patch series > as a whole, even. This needed to be rebased over the guc.c work recently pushed to HEAD. Attached is v4. This isn't just to fix bitrot, though; I'm also including one new patch -- v4-0006-*.patch. This small patch teaches VACUUM to size dead_items while capping the allocation at the space required for "scanned_pages * MaxHeapTuplesPerPage" item pointers. In other words, we now use scanned_pages instead of rel_pages to cap the size of dead_items, potentially saving quite a lot of memory. There is no possible downside to this approach, because we already know exactly how many pages will be scanned from the VM snapshot -- there is zero added risk of a second pass over the indexes. This is still only scratching the surface of what is possible with dead_items. The visibility map snapshot concept can enable a far more sophisticated approach to resource management in vacuumlazy.c. It could help us to replace a simple array of item pointers (the current dead_items array) with a faster and more space-efficient data structure. Masahiko Sawada has done a lot of work on this recently, so this may interest him. We don't just have up-front knowledge of the total number of scanned_pages with VM snapshots -- we also have up-front knowledge of which specific pages will be scanned. So we have reliable information about the final distribution of dead_items (which specific heap blocks might have dead_items) right from the start. While this extra information/context is not a totally complete picture, it still seems like it could be very useful as a way of driving how some new dead_items data structure compresses TIDs. That will depend on the distribution of TIDs -- the final "heap TID key space". VM snapshots could also make it practical for the new data structure to spill to disk to avoid multiple index scans/passed by VACUUM. Perhaps this will result in behavior that's similar to how hash joins spill to disk -- having 90% of the memory required to do everything in-memory *usually* has similar performance characteristics to just doing everything in memory. Most individual TID lookups from ambulkdelete() will find that the TID *doesn't* need to be deleted -- a little like a hash join with low join selectivity (the common case for hash joins). It's not like a merge join + sort, where we must either spill everything or nothing (a merge join can be better than a hash join with high join selectivity). -- Peter Geoghegan
Commits
-
Revert "Add eager and lazy freezing strategies to VACUUM."
- 6c6b49726644 16.0 landed
-
Add eager and lazy freezing strategies to VACUUM.
- 4d4179926139 16.0 landed
-
Refine the definition of page-level freezing.
- b37a08323964 16.0 landed
-
Avoid special XID snapshotConflictHorizon values.
- 6daeeb1f9196 16.0 cited
-
Add page-level freezing to VACUUM.
- 1de58df4fec7 16.0 landed
-
Remove overzealous MultiXact freeze assertion.
- 63c844a0a5d7 16.0 landed
-
Refactor how VACUUM passes around its XID cutoffs.
- 4ce3afb82ecf 16.0 landed
-
Deduplicate freeze plans in freeze WAL records.
- 9e5405993c1e 16.0 cited
-
Set relfrozenxid to oldest extant XID seen by VACUUM.
- 0b018fabaaba 15.0 cited
-
Only skip pages marked as clean in the visibility map, if the last 32
- bf136cf6e376 8.4.0 cited
-
Add vacuum_freeze_table_age GUC option, to control when VACUUM should
- 6587818542e7 8.4.0 cited