agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Fujii Masao <fujii@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: vacuumdb: Use ANALYZE ONLY for partitioned tables
Date: Thu, 13 Aug 2026 05:25:47 +0000
Message-ID: <E1wuNwo-00000000Mev-04B5@gemulon.postgresql.org> (raw)

vacuumdb: Use ANALYZE ONLY for partitioned tables

When vacuumdb --analyze-only or --analyze-in-stages enumerates
tables itself, it can select both a partitioned table and its
partitions as separate work items. Previously, it generated plain
ANALYZE for the partitioned table, which recursively analyzed its
partitions as well.

This caused duplicate work when the partitions were already selected by
vacuumdb. With --analyze-in-stages, the redundant work could be
repeated at every stage.

Fix this by generating ANALYZE ONLY for automatically selected
partitioned tables when connected to servers that support it. This
updates inherited statistics for the partitioned table while leaving
per-partition statistics to the separately selected partition entries.
For older servers that do not support ANALYZE ONLY, vacuumdb falls back
to the previous plain ANALYZE command.

This also applies when partitioned tables are selected by schema
filters. In that case, partitions matching the filters are analyzed as
separate targets, while per-partition statistics for partitions outside
the filters are not updated via the partitioned parent.

This commit does not change the behavior for partitioned tables
specified explicitly with --table, i.e., in that case, vacuumdb
continues to generate plain ANALYZE, recursively analyzing the specified
partitioned table and its partitions.

Suggested-by: Justin Pryzby <pryzby@telsasoft.com>
Author: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Discussion: https://postgr.es/m/aKZ7lMYGnnIo35c0@pryzbyj2023
Backpatch-through: 19

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/9e725e77a5d8356a2237a15025b57d75b08e87e4

Modified Files
--------------
src/bin/scripts/t/100_vacuumdb.pl |   8 ++-
src/bin/scripts/vacuuming.c       | 120 +++++++++++++++++++++++++-------------
src/tools/pgindent/typedefs.list  |   2 +
3 files changed, 88 insertions(+), 42 deletions(-)



view thread (2+ messages)

Message-ID: <E1wuNwo-00000000Mev-04B5@gemulon.postgresql.org>
Permalink:  ../E1wuNwo-00000000Mev-04B5@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1wuNwo-00000000Mev-04B5@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: fujii@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: vacuumdb: Use ANALYZE ONLY for partitioned tables
  In-Reply-To: <E1wuNwo-00000000Mev-04B5@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 agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox