Home Explore Blog CI



postgresql

7th chunk of `doc/src/sgml/ref/pgupgrade.sgml`
f98910820681feae7b67a205ec8cbf666af423bc41683ced0000000100000fa4
 PostgreSQL cluster</title>

    <para>
     Initialize the new cluster using <command>initdb</command>.
     Again, use compatible <command>initdb</command>
     flags that match the old cluster. Many
     prebuilt installers do this step automatically. There is no need to
     start the new cluster.
    </para>
   </step>

   <step>
    <title>Install extension shared object files</title>

    <para>
     Many extensions and custom modules, whether from
     <filename>contrib</filename> or another source, use shared object
     files (or DLLs), e.g., <filename>pgcrypto.so</filename>.  If the old
     cluster used these, shared object files matching the new server binary
     must be installed in the new cluster, usually via operating system
     commands.  Do not load the schema definitions, e.g., <command>CREATE
     EXTENSION pgcrypto</command>, because these will be duplicated from
     the old cluster.  If extension updates are available,
     <application>pg_upgrade</application> will report this and create
     a script that can be run later to update them.
    </para>
   </step>

   <step>
    <title>Copy custom full-text search files</title>

    <para>
     Copy any custom full text search files (dictionary, synonym,
     thesaurus, stop words) from the old to the new cluster.
    </para>
   </step>

   <step>
    <title>Adjust authentication</title>

    <para>
     <command>pg_upgrade</command> will connect to the old and new servers several
     times, so you might want to set authentication to <literal>peer</literal>
     in <filename>pg_hba.conf</filename> or use a <filename>~/.pgpass</filename> file
     (see <xref linkend="libpq-pgpass"/>).
    </para>
   </step>

   <step>
    <title>Stop both servers</title>

    <para>
     Make sure both database servers are stopped using, on Unix, e.g.:

<programlisting>
pg_ctl -D /opt/PostgreSQL/12 stop
pg_ctl -D /opt/PostgreSQL/&majorversion; stop
</programlisting>

     or on Windows, using the proper service names:

<programlisting>
NET STOP postgresql-12
NET STOP postgresql-&majorversion;
</programlisting>
    </para>

    <para>
     Streaming replication and log-shipping standby servers must be
     running during this shutdown so they receive all changes.
    </para>
   </step>

   <step>
    <title>Prepare for standby server upgrades</title>

    <para>
     If you are upgrading standby servers using methods outlined in section <xref
     linkend="pgupgrade-step-replicas"/>, verify that the old standby
     servers are caught up by running <application>pg_controldata</application>
     against the old primary and standby clusters.  Verify that the
     <quote>Latest checkpoint location</quote> values match in all clusters.
     Also, make sure <varname>wal_level</varname> is not set to
     <literal>minimal</literal> in the <filename>postgresql.conf</filename> file on the
     new primary cluster.
    </para>
   </step>

   <step>
    <title>Run <application>pg_upgrade</application></title>

    <para>
     Always run the <application>pg_upgrade</application> binary of the new server, not the old one.
     <application>pg_upgrade</application> requires the specification of the old and new cluster's
     data and executable (<filename>bin</filename>) directories. You can also specify
     user and port values, and whether you want the data files linked, cloned, or swapped
     instead of the default copy behavior.
    </para>

    <para>
     If you use link mode, the upgrade will be much faster (no file
     copying) and use less disk space, but you will not be able to access
     your old cluster
     once you start the new cluster after the upgrade.  Link mode also
     requires that the old and new cluster data directories be in the
     same file system.  (Tablespaces and <filename>pg_wal</filename> can be on
     different file systems.)
     Clone mode provides the same speed and disk space advantages but
     does not cause the old cluster to be unusable once

Title: pg_upgrade Usage Steps: Configuring and Executing the Upgrade
Summary
This section details the subsequent steps for upgrading PostgreSQL using `pg_upgrade`. It covers copying custom full-text search files, adjusting authentication settings in `pg_hba.conf`, and stopping both the old and new servers, ensuring replication servers receive all changes. The section also highlights preparations for standby server upgrades, verifying checkpoint locations. Finally, it instructs users to run the `pg_upgrade` binary from the new server, specifying old and new cluster directories, and explains the implications of using link or clone mode for faster upgrades with trade-offs.