Recommendations for upgrading Carbonio to version 24.03
The latest Carbonio 24.03 update adds support for Ubuntu 22.04 and PostgreSQL 16. Those who previously installed Carbonio on Ubuntu 20.04 and RHEL8 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, saving all the data.
The instructions are suitable for both users of the free version of Carbonio CE and users of the commercial version of Carbonio.
Note that users of the commercial version of Carbonio have the option of taking a backup copy of the original Carbonio infrastructure and then deploying it on a target infrastructure deployed from scratch. This method is the safest and recommended. The process of restoring from a backup is described in our article on this topic.
If this is not possible, then before starting the update it is recommended to create snapshots or clone virtual machines in order to be able to roll back in case of problems, or to be able to safely test the update process.
Updating PostgreSQL on Ubuntu 20.04
If you intend to upgrade PostgreSQL before upgrading the Ubuntu version, the upgrade process will be different from the standard one.
First of all, you will need to install the appropriate repository and the key for it:
sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
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 PostgreSQL clusters – pg_lsclusters
Stop PosgreSQL – systemctl stop postgresql
Rename the default PostgreSQL cluster created – pg_renamecluster 16 main main_pristine
Update your cluster to version 16 – pg_upgradecluster 12 main
Enable PostgreSQL – systemctl start postgresql
Check 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 when 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.
Removing a PostgreSQL 12 cluster – pg_dropcluster 12 main –stop
Removing a PostgreSQL 16 backup cluster – pg_dropcluster 16 main_pristine –stop
Updating PostgreSQL on Ubuntu 22.04
Set the keys for the PostrgreSQL 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 PostgreSQL clusters – pg_lsclusters
Stop PosgreSQL – systemctl stop postgresql
Rename the default PostgreSQL cluster created – pg_renamecluster 16 main main_pristine
Update your cluster to version 16 – pg_upgradecluster 12 main
Enable PostgreSQL – systemctl start postgresql
Check 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 when 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.
Removing a PostgreSQL 12 cluster – pg_dropcluster 12 main –stop
Removing a PostgreSQL 16 backup cluster – pg_dropcluster 16 main_pristine –stop
Updating PostgreSQL on RHEL8
Add PostgreSQL 16 repository to your system
dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
Install PostgreSQL 16 and create a default database in it
dnf install postgresql16 postgresql16-server
/usr/pgsql-16/bin/postgresql-16-setup initdb
Check cluster health and compatibility
su - postgres -c '/usr/pgsql-16/bin/pg_upgrade -b /usr/pgsql-12/bin/ -B /usr/pgsql-16/bin/ -d /var/lib/pgsql/12/data/ -D /var/lib/pgsql/16/data/ -c'
Start the data update and migration procedure. For this:
Check the status and compatibility of clusters – su – postgres -c '/usr/pgsql-16/bin/pg_upgrade -b /usr/pgsql-12/bin/ -B /usr/pgsql-16/bin/ -d /var/lib/pgsql/12/data / -D /var/lib/pgsql/16/data/ -c'
Stop PosgreSQL – systemctl stop postgresql-12.service
Run the update – su – postgres -c '/usr/pgsql-16/bin/pg_upgrade -b /usr/pgsql-12/bin/ -B /usr/pgsql-16/bin/ -d /var/lib/pgsql/12/data / -D /var/lib/pgsql/16/data/'
Make a backup of the hba.conf file from a previous version of PostgreSQL – mv /var/lib/pgsql/16/data/pg_hba.conf /var/lib/pgsql/16/data/pg_hba.conf_orig
Copy the hba.conf file from the previous version of PostgreSQL to the new one – cp /var/lib/pgsql/12/data/pg_hba.conf /var/lib/pgsql/16/data/pg_hba.conf
Set the necessary access rights to the copied file – chown postgres:postgres /var/lib/pgsql/16/data/pg_hba.conf
Launch the new version of the DBMS – systemctl start postgresql-16.service
Disable the old version of the DBMS – systemctl mask postgresql-12.service
Enable the use of the new DBMS version by default – systemctl enable postgresql-16.service
Check that all databases are listed in the PostgreSQL cluster you are using. If they have all migrated correctly, you can remove the unused PSQL clusters. To do this, run the commands:
su - postgres -c '/usr/pgsql-16/bin/vacuumdb --all --analyze-in-stages'
/var/lib/pgsql/delete_old_cluster.sh
Update also PGPool2:
dnf remove pgpool-II pgdg-redhat-repo
dnf install https://www.pgpool.net/yum/rpms/4.5/redhat/rhel-8-x86_64/pgpool-II-pg16-4.5.1-1pgdg.rhel8.x86_64.rpm
Problems updating PostgreSQL
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.
In order to avoid this and update, you need to change the port on which PostgreSQL runs. For this:
Change port=5432 to port=5433 in /etc/postgresql/12/main/postgresql.conf
Stop PostgreSQL service – systemctl stop postgresql.service
Check that no cluster is running pg_lsclusters.
In case some cluster is running, run the command pg_ctlcluster 12 main stop (replacing the cluster name and version with those corresponding to the running cluster)
Rerun the command pg_upgradecluster
Change the port used to 5432 in the /etc/postgresql/16/main/postgresql.conf file.
Restart PostgreSQL service – systemctl restart postgresql.service
Ubuntu update
Updating Ubuntu from version 20.04 is performed according to the usual scheme on each infrastructure node:
Carbonio stops – su – zextras -c 'zmcontrol stop'
Installing the latest packages for Ubuntu 20.04 – apt update && apt upgrade -y
The distribution is being updated – do-release-upgrade
The Carbonio component auto-tuning command is executed – pending-setups -a
During the update process, you may receive several warnings and require some decisions to be made.
After the update, you should check that the Carbonio repository added to the system matches the version of the Ubuntu distribution. To do this, open the file /etc/apt/sources.list.d/zextras.list and check that the repository name contains the word jammy. If this is not the case, replace the name focal with jammy manually and save the changes.
After updating, you should run the command again apt update && apt upgrade -yto reinstall accumulated updates and, due to a change in the version of Perl used, reinstall all Carbonio packages associated with it:
dpkg -l |grep carbonio.*perl|awk '{ printf " "$2 }' > list.log
apt install --reinstall $(cat list.log)
After that, run the command again pending-setups -a and run Carbonio su – zextras -c 'zmcontrol start'.
For questions regarding testing, purchasing, licensing and consultations, please contact sales@svzcloud.ru to exclusive partner Zextras.
You can get information and exchange information about Carbonio CE in Telegram groups CarbonioMail And Carbonio CE Unofficial