pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Add options to control whether VACUUM runs vac_update_datfrozenx
Date: Fri, 06 Jan 2023 19:17:32 +0000
Message-ID: <E1pDsDb-002N8D-ML@gemulon.postgresql.org> (raw)

Add options to control whether VACUUM runs vac_update_datfrozenxid.

VACUUM normally ends by running vac_update_datfrozenxid(), which
requires a scan of pg_class.  Therefore, if one attempts to vacuum a
database one table at a time --- as vacuumdb has done since v12 ---
we will spend O(N^2) time in vac_update_datfrozenxid().  That causes
serious performance problems in databases with tens of thousands of
tables, and indeed the effect is measurable with only a few hundred.
To add insult to injury, only one process can run
vac_update_datfrozenxid at the same time per DB, so this behavior
largely defeats vacuumdb's -j option.

Hence, invent options SKIP_DATABASE_STATS and ONLY_DATABASE_STATS
to allow applications to postpone vac_update_datfrozenxid() until the
end of a series of VACUUM requests, and teach vacuumdb to use them.

Per bug #17717 from Gunnar L.  Sadly, this answer doesn't seem
like something we'd consider back-patching, so the performance
problem will remain in v12-v15.

Tom Lane and Nathan Bossart

Discussion: https://postgr.es/m/17717-6c50eb1c7d23a886@postgresql.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/a46a7011b27188af526047a111969f257aaf4db8

Modified Files
--------------
doc/src/sgml/ref/vacuum.sgml         | 37 +++++++++++++++++++++++++++++++
src/backend/commands/vacuum.c        | 42 +++++++++++++++++++++++++++++++-----
src/backend/postmaster/autovacuum.c  |  9 ++++++--
src/bin/psql/tab-complete.c          |  5 +++--
src/bin/scripts/t/100_vacuumdb.pl    | 24 ++++++++++-----------
src/bin/scripts/vacuumdb.c           | 33 ++++++++++++++++++++++++++++
src/fe_utils/parallel_slot.c         |  3 +++
src/include/commands/vacuum.h        |  2 ++
src/test/regress/expected/vacuum.out |  6 ++++++
src/test/regress/sql/vacuum.sql      |  7 ++++++
10 files changed, 147 insertions(+), 21 deletions(-)



Message-ID: <E1pDsDb-002N8D-ML@gemulon.postgresql.org>
Permalink:  ../E1pDsDb-002N8D-ML@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1pDsDb-002N8D-ML@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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Add options to control whether VACUUM runs vac_update_datfrozenx
  In-Reply-To: <E1pDsDb-002N8D-ML@gemulon.postgresql.org>
  References: <E1pDsDb-002N8D-ML@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