Re: vacuumdb changes for stats import/export

Bruce Momjian <bruce@momjian.us>

From: Bruce Momjian <bruce@momjian.us>
To: Frédéric Yhuel <frederic.yhuel@dalibo.com>
Cc: Nathan Bossart <nathandbossart@gmail.com>, Corey Huinker <corey.huinker@gmail.com>, John Naylor <johncnaylorls@gmail.com>, Masahiko Sawada <sawada.mshk@gmail.com>, Jeff Davis <pgsql@j-davis.com>, jian he <jian.universality@gmail.com>, Matthias van de Meent <boekewurm+postgres@gmail.com>, Tom Lane <tgl@sss.pgh.pa.us>, Magnus Hagander <magnus@hagander.net>, Stephen Frost <sfrost@snowman.net>, Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>, Peter Smith <smithpb2250@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, alvherre@alvh.no-ip.org
Date: 2025-07-26T14:22:49Z
Lists: pgsql-hackers
On Wed, Jul 23, 2025 at 02:45:10PM +0200, Frédéric Yhuel wrote:
> 
> 
> On 3/18/25 22:37, Nathan Bossart wrote:
> > Committed with the following small changes:
> 
> Hi, I don't really understand this sentence in
> doc/src/sgml/ref/vacuumdb.sgml:
> 
> > This option prevents vacuumdb from deleting existing statistics so that
> the query optimizer's choices do not become transiently worse.
> 
> I thought that the point was to avoid unnecessary post-upgrade analyzes?

So, the full paragraph is:

+        Only analyze relations that are missing statistics for a column, index
+        expression, or extended statistics object.  This option prevents
+        <application>vacuumdb</application> from deleting existing statistics
+        so that the query optimizer's choices do not become transiently worse.

What it is trying to say is that if you run vacuumedb without this
option, not only will it analyze all tables, including ones that already
have statistics, but will drop statistics on this tables that already
have statistics for a brief period while it installs new statistics. 
During that period, the optimizer will not have any statistics for the
table.  Is there a clearer way to state this?

-- 
  Bruce Momjian  <bruce@momjian.us>        https://momjian.us
  EDB                                      https://enterprisedb.com

  Do not let urgent matters crowd out time for investment in the future.



Commits

  1. doc: Adjust documentation for vacuumdb --missing-stats-only.

  2. Update guidance for running vacuumdb after pg_upgrade.

  3. vacuumdb: Add option for analyzing only relations missing stats.

  4. vacuumdb: Teach vacuum_one_database() to reuse query results.