Home Explore Blog CI



postgresql

12th chunk of `doc/src/sgml/ref/pgupgrade.sgml`
fb51bdf57e8c700f4925e2367a1927db22d4bf5694b173d40000000100000fa4
 </caution>
   </step>

   <step>
    <title>Statistics</title>

    <para>
     Unless the <option>--no-statistics</option> option is specified,
     <command>pg_upgrade</command> will transfer most optimizer statistics
     from the old cluster to the new cluster.  However, some statistics may
     not be transferred, such as those created explicitly with <xref
     linkend="sql-createstatistics"/> or custom statistics added by an
     extension.
    </para>

    <para>
     Because not all statistics are transferred by
     <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>
     First, use
     <command>vacuumdb --all --analyze-in-stages --missing-stats-only</command>
     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
     vacuum_cost_delay=0' vacuumdb ...</literal>.
    </para>
   </step>

   <step>
    <title>Delete old cluster</title>

    <para>
     Once you are satisfied with the upgrade, you can delete the old
     cluster's data directories by running the script mentioned when
     <command>pg_upgrade</command> completes. (Automatic deletion is not
     possible if you have user-defined tablespaces inside the old data
     directory.)  You can also delete the old installation directories
     (e.g., <filename>bin</filename>, <filename>share</filename>).
    </para>
   </step>

   <step id="pgupgrade-step-revert" performance="optional">
    <title>Reverting to old cluster</title>

    <para>
     If, after running <command>pg_upgrade</command>, you wish to revert to the old cluster,
     there are several options:

     <itemizedlist>
      <listitem>
       <para>
        If the <option>--check</option> option was used, the old cluster
        was unmodified;  it can be restarted.
       </para>
      </listitem>

      <listitem>
       <para>
        If neither <option>--link</option> nor <option>--swap</option> was
        used, the old cluster was unmodified;  it can be restarted.
       </para>
      </listitem>

      <listitem>
       <para>
        If the <option>--link</option> option was used, the data
        files might be shared between the old and new cluster:

        <itemizedlist>
         <listitem>
          <para>
           If <command>pg_upgrade</command> aborted before linking started,
           the old cluster was unmodified;  it can be restarted.
          </para>
         </listitem>

         <listitem>
          <para>
           If you did <emphasis>not</emphasis> start the new cluster, the old
           cluster was unmodified except that, when linking started, a
           <literal>.old</literal> suffix was appended to
           <filename>$PGDATA/global/pg_control</filename>.  To reuse the old
           cluster, remove the <filename>.old</filename> suffix from
           <filename>$PGDATA/global/pg_control</filename>; you can then restart
           the old cluster.
          </para>
         </listitem>

         <listitem>
          <para>
           If you did start the new cluster, it has written to shared files
           and it is unsafe to use the old cluster.  The old cluster will
           need to be restored from backup in this case.
          </para>
         </listitem>

        </itemizedlist></para>
      </listitem>

      <listitem>
       <para>
        If the <option>--swap</option> option was used, the old cluster might

Title: Statistics, Deleting Old Cluster, and Reverting to Old Cluster
Summary
This section details post-upgrade steps including statistics generation and deleting the old cluster. It describes how pg_upgrade transfers optimizer statistics but instructs users to regenerate missing statistics using vacuumdb. It also explains how to delete the old cluster's data directories after confirming the upgrade's success. Finally, it provides instructions for reverting to the old cluster, covering various scenarios depending on the options used during pg_upgrade (e.g., --check, --link, --swap) and whether the new cluster was started.