Further adjust guidance for running vacuumdb after pg_upgrade.
authorNathan Bossart <nathan@postgresql.org>
Wed, 30 Apr 2025 19:12:59 +0000 (14:12 -0500)
committerNathan Bossart <nathan@postgresql.org>
Wed, 30 Apr 2025 19:12:59 +0000 (14:12 -0500)
Since pg_upgrade does not transfer the cumulative statistics used
to trigger autovacuum and autoanalyze, the server may take much
longer than expected to process them post-upgrade.  Currently, we
recommend analyzing only relations for which optimizer statistics
were not transferred by using the --analyze-in-stages and
--missing-stats-only options.  This commit appends another
recommendation to analyze all relations to update the relevant
cumulative statistics by using the --analyze-only option.  This is
similar to the recommendation for pg_stat_reset().

Reported-by: Christoph Berg <myon@debian.org>
Reviewed-by: Christoph Berg <myon@debian.org>
Discussion: https://postgr.es/m/aAfxfKC82B9NvJDj%40msg.df7cb.de

doc/src/sgml/ref/pgupgrade.sgml
src/bin/pg_upgrade/check.c

index df13365b287dc309fc4ccaf42f22196c61e03221..648c6e2967c4310ea3996acc3c17c8d92c34c69c 100644 (file)
@@ -833,17 +833,19 @@ psql --username=postgres --file=script.sql postgres
 
     <para>
      Because not all statistics are not transferred by
-     <command>pg_upgrade</command>, you will be instructed to run a command to
+     <command>pg_upgrade</command>, you will be instructed to run commands to
      regenerate that information at the end of the upgrade.  You might need to
      set connection parameters to match your new cluster.
     </para>
 
     <para>
-     Using <command>vacuumdb --all --analyze-only --missing-stats-only</command>
-     can efficiently generate such statistics.  Alternatively,
+     First, use
      <command>vacuumdb --all --analyze-in-stages --missing-stats-only</command>
-     can be used to generate minimal statistics quickly.  For either command,
-     the use of <option>--jobs</option> can speed it up.
+     to quickly generate minimal optimizer statistics for relations without
+     any.  Then, use <command>vacuumdb --all --analyze-only</command> to ensure
+     all relations have updated cumulative statistics for triggering vacuum and
+     analyze.  For both commands, the use of <option>--jobs</option> can speed
+     it up.
      If <varname>vacuum_cost_delay</varname> is set to a non-zero
      value, this can be overridden to speed up statistics generation
      using <envar>PGOPTIONS</envar>, e.g., <literal>PGOPTIONS='-c
index 18c2d652bb6dac7056757936035a36a10a7c3401..940fc77fc2e8cdc0b73aa0f1a10c691e89d246c1 100644 (file)
@@ -814,9 +814,12 @@ output_completion_banner(char *deletion_script_file_name)
    }
 
    pg_log(PG_REPORT,
-          "Some optimizer statistics may not have been transferred by pg_upgrade.\n"
-          "Once you start the new server, consider running:\n"
-          "    %s/vacuumdb %s--all --analyze-in-stages --missing-stats-only", new_cluster.bindir, user_specification.data);
+          "Some statistics are not transferred by pg_upgrade.\n"
+          "Once you start the new server, consider running these two commands:\n"
+          "    %s/vacuumdb %s--all --analyze-in-stages --missing-stats-only\n"
+          "    %s/vacuumdb %s--all --analyze-only",
+          new_cluster.bindir, user_specification.data,
+          new_cluster.bindir, user_specification.data);
 
    if (deletion_script_file_name)
        pg_log(PG_REPORT,