- Download and install a PostgresSQL 9.6 binary since I have upgraded the host to Fedora 31 and the old binary was gone. For this, instead of building it from source, I took advantage of the Interactive installer from EnterpriseDB. Download the installer and bring it to the Fedora Host:
- Running the installer. This is as simple as running the installer from the command line as,
chmod +x ./postgresql-9.6.15-2-linux-x64.run sudo ./postgresql-9.6.15-2-linux-x64.run
Following the prompts given by the installer, I installed the binary at/opt/PostgreSQL/9.6/
. - Disable and stop the 9.6 version of the database service
sudo systemctl disable postgresql-9.6.service sudo systemctl stop postgresql-9.6.service
- The 11.5 version of the database service should not be running because this is why we are doing this. However, it does not hurt to make sure it is down:
sudo systemctl stop postgresql.service
- Switch to user
postgres
sudo su - postgres
- Initialize a 11.5 database. Assuming we want the database to reside at directory
/mnt/data/postgres/data11
, we run version 11.5'sinitdb
:
mkdir /mnt/data/postgres/data11 initdb /mnt/data/postgres/data11
- Start the 11.5 service for the initialized 11.5 database using the installed 11.5's binary:
postgres -D /mnt/data/postgres/data11
- Open another terminal Window, and in the new terminal Window, start the upgrade process using the
pg_upgrade
. We take a two-step approach.- First check whether everything is OK with the upgrade using the
-c
option:sudo pg_upgrade -b /opt/PostgreSQL/9.6/ -B /usr/bin \ -d /mnt/data/postgres/data96/ -D /mnt/data/postgres/data11 \ -c
- If
pg_upgrade
does not complain, we go ahead with the upgrade
sudo pg_upgrade -b /opt/PostgreSQL/9.6/ -B /usr/bin \ -d /mnt/data/postgres/data96/ -D /mnt/data/postgres/data11 \
- First check whether everything is OK with the upgrade using the
- Terminate the 11.5 service we ran manually. Just type
CTRL-C
in the terminal Windows. - In the new terminal Window, make sure the user
postgres
owns the the database files:
sudo chown -R postgres:postgres /mnt/data/postgres/data11
- We are now ready to start the 11.5 database service in the system
sudo systemctl start postgresql.service
- Finally, we may have to do some additional steps as instructed by the output of
pg_upgrade
, such as reindexing the database, uninstalling the 9.6 database server binaries, and removing the old database files, e.g.,sudo su - postgres psql < reindex_hash.sql exit sudo /opt/PostgreSQL/9.6/bin/uninstall-postgresql
Saturday, September 28, 2019
Upgrading PostgreSQL Databases Revisited
Once upon a time I had to upgrade a PostgreSQL database after a Fedora Linux upgrade. Today after I upgraded a Fedora Linux 28 host to a Fedora Linux 31, I found out I had to do it again because PostgreSQL services refuses to start due to database files of older format. I took a slightly simpler approach to upgrade the 9.6 PostgreSQL database to a 11.5 one.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment