Upgrading PGD clusters with TPA
===============================

..  Note No Postgres major version upgrades::
   TPA doesn't currently support major version upgrades of Postgres.

To perform a major version upgrade of Postgres, see :ref:`In-place Postgres major version upgrades <In-place Postgres major version upgrades>`  .

.. ::
   If you used TPA to install your cluster, you can also use TPA to upgrade it. The techniques outlined here can perform minor and major version upgrades of the PGD software. They can also perform minor version upgrades of Postgres.

You can read more about the capabilities of TPA upgrades in
 :ref:`Upgrading your cluster <Installing PGD CLI with TPA>`  in the TPA documentation.

..  Warning Always test first::
   If possible, always test upgrade processes in a QA environment first. This helps to ensure that there are no unexpected factors to take into account. TPA's ability to reproducibly deploy a PGD configuration makes it much easier to build a test environment to work with. !!!

Minor and major PGD upgrades
----------------------------

TPA automatically manages minor version upgrades of PGD.

Major version upgrades of PGD require changes to the TPA ``config.yml``
file, which contains the deployment configuration.

When upgrading to PGD 5 from previous PGD major versions, you can use
 :ref:`tpaexec reconfigure <Installing PGD CLI with TPA>`  . This command helps you make appropriate modifications to
your deployment configuration.

The ``reconfigure`` command requires settings for architecture (only
``PGD_Always_ON`` and PGD Proxy routing to run. Remember to back up your
deployment configuration before running, and use the ``--describe`` and
``--output`` options to preview the reconfiguration.

Pre-requisites
--------------

-  The cluster configuration directory created when TPA deployed your
   PGD cluster.

-  If performing a major version upgrade of PGD, ensure that
   ``tpaexec reconfigure`` was run and :ref:`appropriate configuration changes <#minor-and-major-pgd-upgrades>`  were made.

Upgrading
---------

Run:

::

   tpaexec upgrade clustername

Where ``clustername`` is the name of the cluster and the path to the
cluster configuration directory. By default, TPA upgrades each node of
the cluster to the latest minor versions of the software the nodes were
configured with.

TPA’s automated rolling upgrade procedure
-----------------------------------------

TPA first tests the cluster and then the nodes.

Each node is then isolated from the cluster, upgraded, and returned to
operation within the cluster.

TPA upgrades - step by step
^^^^^^^^^^^^^^^^^^^^^^^^^^^

-  Checks that all preconditions for upgrading the cluster are met.

-  For each instance in the cluster: - Checks that it has the correct
   repositories configured. - Checks that the required Postgres packages
   are available in those repositories. - For each BDR node in the
   cluster, one at a time: - Fences the node off to ensure that
   pgd-proxy doesn’t send any connections to it. - Stops, updates, and
   restarts Postgres. - Unfences the node so it can receive connections
   again. - Updates pgbouncer, pgd-proxy, and pgd-cli, as applicable for
   this node.
