Home Explore Blog CI



postgresql

26th chunk of `doc/src/sgml/runtime.sgml`
67c9040ce11935e19b0c48b032a71c3b89c2c8e5e42a2a130000000100000fa4
 linkend="backup-dump-all"/> for more details.  For best
      results, however, try to use the <application>pg_dumpall</application>
      command from <productname>PostgreSQL</productname> &version;,
      since this version contains bug fixes and improvements over older
      versions.  While this advice might seem idiosyncratic since you
      haven't installed the new version yet, it is advisable to follow
      it if you plan to install the new version in parallel with the
      old version.  In that case you can complete the installation
      normally and transfer the data later.  This will also decrease
      the downtime.
     </para>
    </step>

    <step>
     <para>
      Shut down the old server:
<screen>
<userinput>pg_ctl stop</userinput>
</screen>
      On systems that have <productname>PostgreSQL</productname> started at boot time,
      there is probably a start-up file that will accomplish the same thing. For
      example, on a <systemitem class="osname">Red Hat Linux</systemitem> system one
      might find that this works:
<screen>
<userinput>/etc/rc.d/init.d/postgresql stop</userinput>
</screen>
      See <xref linkend="runtime"/> for details about starting and
      stopping the server.
     </para>
    </step>

    <step>
     <para>
      If restoring from backup, rename or delete the old installation
      directory if it is not version-specific.  It is a good idea to
      rename the directory, rather than
      delete it, in case you have trouble and need to revert to it.  Keep
      in mind the directory might consume significant disk space.  To rename
      the directory, use a command like this:
<screen>
<userinput>mv /usr/local/pgsql /usr/local/pgsql.old</userinput>
</screen>
     (Be sure to move the directory as a single unit so relative paths
     remain unchanged.)
     </para>
    </step>

    <step>
     <para>
      Install the new version of <productname>PostgreSQL</productname> as
      outlined in <xref linkend="installation"/>.
     </para>
    </step>

    <step>
     <para>
      Create a new database cluster if needed.  Remember that you must
      execute these commands while logged in to the special database user
      account (which you already have if you are upgrading).
<programlisting>
<userinput>/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data</userinput>
</programlisting>
     </para>
    </step>

    <step>
     <para>
      Restore your previous <filename>pg_hba.conf</filename> and any
      <filename>postgresql.conf</filename> modifications.
     </para>
    </step>

    <step>
     <para>
      Start the database server, again using the special database user
      account:
<programlisting>
<userinput>/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data</userinput>
</programlisting>
     </para>
    </step>

    <step>
     <para>
      Finally, restore your data from backup with:
<screen>
<userinput>/usr/local/pgsql/bin/psql -d postgres -f <replaceable>outputfile</replaceable></userinput>
</screen>
      using the <emphasis>new</emphasis> <application>psql</application>.
     </para>
    </step>
   </procedure>

   <para>
    The least downtime can be achieved by installing the new server in
    a different directory and running both the old and the new servers
    in parallel, on different ports. Then you can use something like:

<programlisting>
pg_dumpall -p 5432 | psql -d postgres -p 5433
</programlisting>
    to transfer your data.
   </para>

  </sect2>

  <sect2 id="upgrading-via-pg-upgrade">
   <title>Upgrading Data via <application>pg_upgrade</application></title>

   <para>
    The <xref linkend="pgupgrade"/> module allows an installation to
    be migrated in-place from one major <productname>PostgreSQL</productname>
    version to another.  Upgrades can be performed in minutes,
    particularly with <option>--link</option> mode.  It requires steps similar to
    <application>pg_dumpall</application> above, e.g.,  starting/stopping the server,
    running

Title: Completing the PostgreSQL Upgrade Process
Summary
This section outlines the remaining steps to complete a PostgreSQL upgrade, including shutting down the old server, renaming or deleting the old installation directory, installing the new version, creating a new database cluster, restoring configuration files and data from backup, and starting the new server, with an alternative method using pg_upgrade for in-place migration.