pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Masahiko Sawada <msawada@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Use TidStore for dead tuple TIDs storage during lazy vacuum.
Date: Tue, 02 Apr 2024 01:16:28 +0000
Message-ID: <E1rrSlH-0003wa-I6@gemulon.postgresql.org> (raw)

Use TidStore for dead tuple TIDs storage during lazy vacuum.

Previously, we used a simple array for storing dead tuple IDs during
lazy vacuum, which had a number of problems:

* The array used a single allocation and so was limited to 1GB.
* The allocation was pessimistically sized according to table size.
* Lookup with binary search was slow because of poor CPU cache and
  branch prediction behavior.

This commit replaces that array with the TID store from commit
30e144287a.

Since the backing radix tree makes small allocations as needed, the
1GB limit is now gone. Further, the total memory used is now often
smaller by an order of magnitude or more, depending on the
distribution of blocks and offsets. These two features should make
multiple rounds of heap scanning and index cleanup an extremely rare
event. TID lookup during index cleanup is also several times faster,
even more so when index order is correlated with heap tuple order.

Since there is no longer a predictable relationship between the number
of dead tuples vacuumed and the space taken up by their TIDs, the
number of tuples no longer provides any meaningful insights for users,
nor is the maximum number predictable. For that reason this commit
also changes to byte-based progress reporting, with the relevant
columns of pg_stat_progress_vacuum renamed accordingly to
max_dead_tuple_bytes and dead_tuple_bytes.

For parallel vacuum, both the TID store and supplemental information
specific to vacuum are shared among the parallel vacuum workers. As
with the previous array, we don't take any locks on TidStore during
parallel vacuum since writes are still only done by the leader
process.

Bump catalog version.

Reviewed-by: John Naylor, (in an earlier version) Dilip Kumar
Discussion: https://postgr.es/m/CAD21AoAfOZvmfR0j8VmZorZjL7RhTiQdVttNuC4W-Shdc2a-AA%40mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/667e65aac354975c6f8090c6146fceb8d7b762d6

Modified Files
--------------
doc/src/sgml/config.sgml                        |  12 --
doc/src/sgml/monitoring.sgml                    |   8 +-
src/backend/access/heap/vacuumlazy.c            | 272 +++++++++++-------------
src/backend/catalog/system_views.sql            |   2 +-
src/backend/commands/vacuum.c                   |  78 +------
src/backend/commands/vacuumparallel.c           | 100 ++++++---
src/backend/storage/lmgr/lwlock.c               |   1 +
src/backend/utils/activity/wait_event_names.txt |   1 +
src/include/catalog/catversion.h                |   2 +-
src/include/commands/progress.h                 |   4 +-
src/include/commands/vacuum.h                   |  28 ++-
src/include/storage/lwlock.h                    |   1 +
src/test/regress/expected/rules.out             |   4 +-
src/tools/pgindent/typedefs.list                |   2 +-
14 files changed, 226 insertions(+), 289 deletions(-)



Message-ID: <E1rrSlH-0003wa-I6@gemulon.postgresql.org>
Permalink:  ../E1rrSlH-0003wa-I6@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1rrSlH-0003wa-I6@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: msawada@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Use TidStore for dead tuple TIDs storage during lazy vacuum.
  In-Reply-To: <E1rrSlH-0003wa-I6@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox