Skip to content

Instantly share code, notes, and snippets.

@cedricbonhomme
Created December 15, 2021 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cedricbonhomme/f94b0ea046ab31391c462e8b1c694605 to your computer and use it in GitHub Desktop.
Save cedricbonhomme/f94b0ea046ab31391c462e8b1c694605 to your computer and use it in GitHub Desktop.
PostgreSQL server migration
$ locate bin/postgres
/usr/lib/postgresql/10/bin/postgres
/usr/lib/postgresql/12/bin/postgres
/usr/lib/postgresql/9.5/bin/postgres
$ sudo pg_lsclusters
$ mkdir backup-pg
$ sudo cp -R /var/lib/postgresql/9.5 backup-pg
$ sudo systemctl stop postgresql.service
$ sudo systemctl stop postgresql@12.service
$ sudo systemctl stop postgresql@9.5.service
$ cd /tmp
$ sudo -H -u postgres /usr/lib/postgresql/12/bin/pg_upgrade \
-b /usr/lib/postgresql/9.5/bin \
-B /usr/lib/postgresql/12/bin \
-d /var/lib/postgresql/9.5/main \
-D /var/lib/postgresql/12/main \
-o ' -c config_file=/etc/postgresql/9.5/main/postgresql.conf' \
-O ' -c config_file=/etc/postgresql/12/main/postgresql.conf'
$ sudo systemctl start postgresql.service
$ sudo ./analyze_new_cluster.sh
$ sudo ./delete_old_cluster.sh
$ # delete and clean old data....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment