# - bof - # # - - # # - Documentation - # https://www.kostolansky.sk/posts/upgrading-to-postgresql-12/ # - - # # - Upgrade PostgreSQL from 11 to 12 - # Update: This tutorial works also perfectly well with the new PostgreSQL 13. :A # - - # # - Update & install PostgreSQL 12 - # sudo apt-get update; sudo apt-get install postgresql-12 postgresql-server-dev-12 -y; :B # - - # # - Check differences - # diff /etc/postgresql/11/main/postgresql.conf /etc/postgresql/12/main/postgresql.conf diff /etc/postgresql/11/main/pg_hba.conf /etc/postgresql/12/main/pg_hba.conf :C # - - # # - Stop PostgreSQL - # sudo systemctl stop postgresql.service; :D # - - # # - Login postgres user - # sudo su postgres; :E # - - # # - Check clusters (notice the --check argument will not change any data - # /usr/lib/postgresql/12/bin/pg_upgrade \ --old-datadir=/var/lib/postgresql/11/main \ --new-datadir=/var/lib/postgresql/12/main \ --old-bindir=/usr/lib/postgresql/11/bin \ --new-bindir=/usr/lib/postgresql/12/bin \ --old-options '-c config_file=/etc/postgresql/11/main/postgresql.conf' \ --new-options '-c config_file=/etc/postgresql/12/main/postgresql.conf' \ --check :F # - - # # - Migrate data (without the --check argument) - # /usr/lib/postgresql/12/bin/pg_upgrade \ --old-datadir=/var/lib/postgresql/11/main \ --new-datadir=/var/lib/postgresql/12/main \ --old-bindir=/usr/lib/postgresql/11/bin \ --new-bindir=/usr/lib/postgresql/12/bin \ --old-options '-c config_file=/etc/postgresql/11/main/postgresql.conf' \ --new-options '-c config_file=/etc/postgresql/12/main/postgresql.conf' :G # - - # # - Exit postgres user - # exit :H # - - # # - Swap ports for old and new PostgreSQL - # sudo vim /etc/postgresql/12/main/postgresql.conf # ...and change "port = 5433" to "port = 5432" sudo vim /etc/postgresql/11/main/postgresql.conf # ...and change "port = 5432" to "port = 5433" :I # - - # # - Start PostgreSQL service - # sudo systemctl start postgresql.service; :J # - - # # - Login as postgres user again - # sudo su postgres; :K # - - # # - Check the new PostgreSQL version - # psql -c "SELECT version();" :L # - - # # - Run generated analyze_new_cluster script - # ./analyze_new_cluster.sh :M # - - # # - Back to normal user - # exit :N # - - # # - Check which old PostgreSQL packages are installed - # apt list --installed | grep postgresql :O # - - # # - Remove old PostgreSQL packages - # sudo apt remove postgresql-11 -y; sudo apt remove postgresql-11 postgresql-server-dev-11 -y; :P # - - # # - Remove the old configuration - # sudo rm -rf /etc/postgresql/11/ :Q # - - # # - Login as postgres user once more - # sudo su postgres; :R # - - # # - Finally, drop the old cluster data - # ./delete_old_cluster.sh Done! # - eof - #