Upgrade PostgreSQL from 10 to 13 on CentOS 7
This article shows how to upgrade PostgreSQL from version 10 to version 13 on CentOS 7. I have tested it several times without any problems. This process typically takes between 20-30 minutes, depending on the size of your database.
If you are looking to upgrade from PostgreSQL version 11 to version 13, click here.
Let's get started!
- Login as root
sudo su - Create a backup of the current database(s)
su - postgres -c "pg_dumpall -p 5432 > /tmp/dump_file.sql" - Install necessary packages
sudo yum -y install postgresql13-server postgresql13-contrib - Inicialize the DB
/usr/pgsql-13/bin/postgresql-13-setup initdb - Stop old PostgreSQL
sudo systemctl stop postgresql-10 - Change user to "postgres"
su - postgres - Change directory to home (required to avoid error in next step)
cd - Check that everything is fine
/usr/pgsql-13/bin/pg_upgrade --old-datadir=/var/lib/pgsql/10/data --new-datadir=/var/lib/pgsql/13/data --old-bindir=/usr/pgsql-10/bin --new-bindir=/usr/pgsql-13/bin --old-options '-c config_file=/var/lib/pgsql/10/data/postgresql.conf' --new-options '-c config_file=/var/lib/pgsql/13/data/postgresql.conf' --check - Run, if everything is fine
/usr/pgsql-13/bin/pg_upgrade --old-datadir=/var/lib/pgsql/10/data --new-datadir=/var/lib/pgsql/13/data --old-bindir=/usr/pgsql-10/bin --new-bindir=/usr/pgsql-13/bin --old-options '-c config_file=/var/lib/pgsql/10/data/postgresql.conf' --new-options '-c config_file=/var/lib/pgsql/13/data/postgresql.conf' - Exit to root
exit - Start the PostgreSQL 13
systemctl start postgresql-13 - Change user to "postgres"
su - postgres - Check version number
psql -c "SELECT version();" - Analyze new cluster
/var/lib/pgsql/analyze_new_cluster.sh - Exit again to root
exit - Copy all config settings from postgresql.conf and pg_hba.conf. If you have any command to do that, share with us in comment section.
- These are located here:
- /var/lib/pgsql/10/data/postgresql.conf
- /var/lib/pgsql/10/data/pg_hba.conf
- /var/lib/pgsql/13/data/postgresql.conf
- /var/lib/pgsql/13/data/pg_hba.conf
- These are located here:
- If you are done with these config files, restart the service
systemctl restart postgresql-13 - Enable auto-start on startup
systemctl enable postgresql-13 - At this point, you have to test your application. You need to restart your application (GitLab or whatever you use). If everything is working fine, let's continue by removing old packages and files:
- sudo yum remove postgresql10*
- rm -rf /var/lib/pgsql/10
- su - postgres -c "/var/lib/pgsql/delete_old_cluster.sh"
That's all.
If you have any questions, feel free to ask in the comment section!
Do you like this article? Support my work by following on Instagram or Facebook page. Thank you!
If you found this article useful and would like to show your appreciation, please consider making a small donation via PayPal. Your support will allow me to continue creating valuable content and make my blog even better. Thank you for your contribution!
Comments