It’s been a while since I wrote the blog post about PostgreSQL 13 and Patroni 2.0. On this blog I received a comment, if it’s possible to explain, how to upgrade from Patroni 1.6 to 2. So let’s make a short blog about the upgrade procedure of Patroni.

For my initial installation is used python pip, not the rpm packages. But the upgrade with pip is also really simple and straight forward. There is no need to stop Patroni. But as usual, be sure you have a backup of you database or a snapshot of your server, if applicable.

In first step, let’s check the current version of Patroni and upgrade pip itself and the setuptools to be sure to have it on the newest version as well.

postgres@patroni1:/u02/pgdata/ [PG1] patronictl version
patronictl version 1.6.4
postgres@patroni1:/u02/pgdata/ [PG1] python3 -m pip install --upgrade pip
Defaulting to user installation because normal site-packages is not writeable
Collecting pip
  Downloading pip-21.3.1-py3-none-any.whl (1.7 MB)
     |████████████████████████████████| 1.7 MB 2.0 MB/s
Installing collected packages: pip
Successfully installed pip-21.3.1
postgres@patroni1:/u02/pgdata/ [PG1] python3 -m pip install --upgrade --user setuptools
Requirement already satisfied: setuptools in /home/postgres/.local/lib/python3.6/site-packages (45.2.0)
Collecting setuptools
  Downloading setuptools-59.6.0-py3-none-any.whl (952 kB)
     |████████████████████████████████| 952 kB 1.6 MB/s
Installing collected packages: setuptools
  Attempting uninstall: setuptools
    Found existing installation: setuptools 45.2.0
    Uninstalling setuptools-45.2.0:
      Successfully uninstalled setuptools-45.2.0
Successfully installed setuptools-59.6.0
postgres@patroni3:/u01/app/postgres/product/ [PG1]

Afterwards we upgrade Patroni itself. Which is also done using python pip with –upgrade option.

postgres@patroni1:/u02/pgdata/ [PG1]  python3 -m pip install --upgrade  --user patroni[etcd]
Requirement already satisfied: patroni[etcd] in /home/postgres/.local/lib/python3.6/site-packages (1.6.4)
Collecting patroni[etcd]
  Downloading patroni-2.1.3-py3-none-any.whl (222 kB)
     |████████████████████████████████| 222 kB 1.6 MB/s
Requirement already satisfied: psutil>=2.0.0 in /home/postgres/.local/lib/python3.6/site-packages (from patroni[etcd]) (5.7.0)
Requirement already satisfied: six>=1.7 in /home/postgres/.local/lib/python3.6/site-packages (from patroni[etcd]) (1.14.0)
Requirement already satisfied: urllib3!=1.21,>=1.19.1 in /home/postgres/.local/lib/python3.6/site-packages (from patroni[etcd]) (1.25.8)
Collecting ydiff>=1.2.0
  Downloading ydiff-1.2.tar.gz (42 kB)
     |████████████████████████████████| 42 kB 2.1 MB/s
  Preparing metadata ( ... done
Requirement already satisfied: click>=4.1 in /home/postgres/.local/lib/python3.6/site-packages (from patroni[etcd]) (7.0)
Requirement already satisfied: PyYAML in /home/postgres/.local/lib/python3.6/site-packages (from patroni[etcd]) (5.3)
Requirement already satisfied: prettytable>=0.7 in /home/postgres/.local/lib/python3.6/site-packages (from patroni[etcd]) (0.7.2)
Requirement already satisfied: python-dateutil in /home/postgres/.local/lib/python3.6/site-packages (from patroni[etcd]) (2.8.1)
Requirement already satisfied: python-etcd=0.4.3 in /home/postgres/.local/lib/python3.6/site-packages (from patroni[etcd]) (0.4.5)
Requirement already satisfied: dnspython>=1.13.0 in /home/postgres/.local/lib/python3.6/site-packages (from python-etcd=0.4.3->patroni[etcd])                                                                                                                                                            (1.16.0)
Using legacy ' install' for ydiff, since package 'wheel' is not installed.
Installing collected packages: ydiff, patroni
    Running install for ydiff ... done
  Attempting uninstall: patroni
    Found existing installation: patroni 1.6.4
    Uninstalling patroni-1.6.4:
      Successfully uninstalled patroni-1.6.4
Successfully installed patroni-2.1.3 ydiff-1.2
postgres@patroni3:/u01/app/postgres/product/ [PG1] 

To be sure everything works as expected, check the version in the last step and the cluster itself

postgres@patroni1:/u02/pgdata/ [PG1]  patronictl list
+ Cluster: PG1 (7093128570847303467) -+---------+----+-----------+
| Member   | Host           | Role    | State   | TL | Lag in MB |
| patroni1 | | Leader  | running |  4 |           |
| patroni2 | | Replica | running |  4 |         0 |
| patroni3 | | Replica | running |  4 |         0 |

postgres@patroni1:/u02/pgdata/ [PG1] patroni --version
patroni 2.1.3

Once this this is finished successfully on one node, you can go on with the other nodes in the cluster.