My OpenProject management software is installed with default postgresql 10. Currently the postgresql DB is 12, It is having lot of new features.
I want to upgrade my Pos
A) First create a backup of all the databases for that (You can continue from B if you dont need a backup)
sudo su postgres
pg_dumpall > backup.sql
B) Upgrade to PostgreSQL12
sudo apt-get update
sudo apt-get install postgresql-12 postgresql-server-dev-12
sudo systemctl stop postgresql.service
/usr/lib/postgresql/12/bin/pg_upgrade \
--old-datadir=/var/lib/postgresql/10/main \
--new-datadir=/var/lib/postgresql/12/main \
--old-bindir=/usr/lib/postgresql/10/bin \
--new-bindir=/usr/lib/postgresql/12/bin \
--old-options '-c config_file=/etc/postgresql/10/main/postgresql.conf' \
--new-options '-c config_file=/etc/postgresql/12/main/postgresql.conf'
exit
sudo vim /etc/postgresql/12/main/postgresql.conf
#change port to 5432
sudo vim /etc/postgresql/10/main/postgresql.conf
#change port to 5433
sudo systemctl start postgresql.service
sudo su postgres
psql -c "SELECT version();"
./analyze_new_cluster.sh
sudo apt-get remove postgresql-10 postgresql-server-dev-10
#uninstalls postgres packages
sudo rm -rf /etc/postgresql/10/
#removes the old postgresql directory
sudo su postgres
#login as postgres user
./delete_old_cluster.sh
#delete the old cluster data
NOTE: Change the postgresql.conf and pg_hba.conf as per your requirement
PS: Feel free to comment your issues, suggestions or anyother modifications you would like to suggest
psql --version sudo -u postgres psql pg_dumpall > alldbs.sql
(this command will backup all databases from the postgresql db)Then exit from postgres user, and:
Inside a terminal run these commands:
sudo systemctl stop postgres
sudo apt-get install -y postgresql-12 postgresql-server-dev-12 postgresql-contrib-12 libpq-dev postgresql-12-hypopg
sudo pg_dropcluster 12 main --stop
sudo pg_upgradecluster 10 main
sudo pg_dropcluster 10 main --stop
restart the postgresql service:
sudo systemctl restart postgresql
login to the postgres:
su - postgres
to check the version:
psql --version
I have done using the above steps and I could update the DBand restore all data.
SHOW LC_COLLATE;
$ sudo systemctl list-units | grep postgres
$ sudo service postgresql-<source-version>.service stop
$ /usr/pgsql-<target-version>/bin/initdb -D /var/lib/pgsql/<target-version>/data --locale=<add-your-encoding>
$sudo su postgres
$ /usr/pgsql-<target-version>/bin/pg_upgrade --old-bindir /usr/pgsql-<source-version>/bin --new-bindir /usr/pgsql-<target-version>/bin --old-datadir /var/lib/pgsql/<source-version>/data --new-datadir /var/lib/pgsql/12/data --link --jobs=2 --check
If it's ok we can move to the next step, If not fix the issues before proceeding to the next step Expected output: Clusters are compatible
$sudo su postgres
$ /usr/pgsql-<target-version>/bin/pg_upgrade --old-bindir /usr/pgsql-<source-version>/bin --new-bindir /usr/pgsql-<target-version>/bin --old-datadir /var/lib/pgsql/<source-version>/data --new-datadir /var/lib/pgsql/<target-version>/data --link
Expected output: Upgrade Complete
Thanks. ENJOY !!!