How to Upgrade Carbonio Community Edition to PostgreSQL 16 in 22.04 | Carbonio CE

The latest Carbonio CE 24.03 update adds support for PostgreSQL 16. Those who previously installed Carbonio on Ubuntu 22.04 using PostgreSQL 12 were faced with the need to update the distribution and version of PostgreSQL they were using to the current version. In this instruction, we will tell you how to do this.

Set keys for PostgreSQL 16 repository:

wget -O- "https://www.postgresql.org/media/keys/ACCC4CF8.asc" | \
gpg --dearmor | sudo tee /usr/share/keyrings/postgres.gpg > \
/dev/null

chmod 644 /usr/share/keyrings/postgres.gpg
sed -i 's/deb/deb [signed-by=\/usr\/share\/keyrings\/postgres.gpg] /' /etc/apt/sources.list.d/pgdg.list

After adding the repository, update the list of available packages and update to PostgreSQL 16

apt update
apt -y install postgresql-16

Migrate data from PostgreSQL 12 to PostgreSQL 16. To do this:

  • Check the list of installed clusters PostgreSQL – pg_lsclusters
  • Stop PostgreSQL – systemctl stop postgresql
  • Rename the default PostgreSQL cluster created – pg_renamecluster 16 main main_pristine
  • Upgrade your cluster to version 16 – pg_upgradecluster 12 main
  • Boot PostgreSQL – systemctl start postgresql
  • Verify that the PostgreSQL cluster has become the default – pg_lsclusters

Verify that all databases have moved to the new cluster.

su - postgres
psql
\l

If at any stage of the instructions an error occurred due to the port being busy and the database migration did not take place, please refer to the section “Problems Updating PostgreSQL

If the cluster used is PostgreSQL 16 and it displays a complete list of databases, the migration was successful and you can delete unused clusters.

  • Deleting PostgreSQL 12 cluster – pg_dropcluster 12 main --stop
  • Deleting PostgreSQL 16 reserve cluster – pg_dropcluster 16 main_pristine --stop

During the PostgreSQL update process, an error may occur due to a port conflict.

Error: Port conflict: another instance is already running on /var/run/postgresql with port 5432
Error: Could not start target cluster

This error is reproduced even if the PostgreSQL service is stopped. If you ignore this error, all databases will be lost when migrating to a new version of PostgreSQL.

To avoid this and update, you need to change the port on which PostgreSQL runs. For this:

  • Change parameter port = 5432 to the port = 5433 in file /etc/postgresql/12/main/postgresql.conf
  • Stop PostgreSQL service – systemctl stop postgresql.service
  • Verify that no clusters are running – pg_lsclusters.
  • In case any cluster is running execute pg_ctlcluster 12 main stop command (replacing the cluster name and version with the ones that are used in your infrastructure)
  • Run again pg_upgradecluster
  • Change the used port to 5432 in the file /etc/postgresql/16/main/postgresql.conf.

Reboot PostgreSQL – systemctl restart postgresql.service

Post your comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

How to Upgrade Carbonio Community Edition to PostgreSQL 16 in Ubuntu 20.04 | Carbonio CE
How to Upgrade Carbonio Community Edition to PostgreSQL 16 in RHEL 8 | Carbonio CE