==============
Install postgresql 9.6
==============
wget https://yum.postgresql.org/9.6/redhat/rhel-7.4-x86_64/pgdg-centos96-9.6-3.noarch.rpm
rpm -i pgdg-centos96-9.6-3.noarch.rpm
yum install postgresql96-server postgresql96-contrib
/usr/pgsql-9.6/bin/postgresql96-setup initdb
mv /usr/bin/pg_ctl{,-orig}
echo '#!/bin/bash' > /usr/bin/pg_ctl
echo '"$0"-orig "${@/unix_socket_directory/unix_socket_directories}"' >> /usr/bin/pg_ctl
chmod +x /usr/bin/pg_ctl
==============
Start importing/upgrading data to new server
==============
systemctl stop postgresql
# At this point both servers are stoped
# As Postgres user
su postgres
cd ~
/usr/pgsql-9.6/bin/pg_upgrade -v -b /usr/bin/ -B /usr/pgsql-9.6/bin/ -d /var/lib/pgsql/data/ -D /var/lib/pgsql/9.6/data/
exit
# Back to root user
# Rollback pg_ctl
mv -f /usr/bin/pg_ctl{-orig,}
#### APPLY OLD postgresql config params to postgresql-9.6 (pg_hba.conf, postgresql.conf) (manually), maybe use pgtune for postgresql.conf...
==============
START NEW SERVER AND DISABLE THE OLD
==============
systemctl start postgresql-9.6
systemctl enable postgresql-9.6
systemctl disable postgresql
# temporary
ln -s /usr/pgsql-9.6/bin/psql /usr/bin/psql --force
ln -s /usr/pgsql-9.6/bin/pg_dump /usr/bin/pg_dump --force
# Postgres user
su postgres
cd ~
./analyze_new_cluster.sh
exit
# back as root
# remove old postgresql
yum remove postgresql
# Export new path
echo 'export PATH=$PATH:/usr/pgsql-9.6/bin' >> /etc/bashrc
exit, SSH back to host and check if new path is ok for postgres commands
Finally decide if you want to remove the old postgres cluster (data folder)
FLOSS Hacktivist, Board Member at @FLOSSKosova & @MOSSCon13, board Member at @STIKK_KS, Co-founder of @PRNHackerspace, @Mozilla Representative, Linux Sysadmin, DevOps
View all posts by Altin Ukshini
Published
12 thoughts on “Upgrade postgresql 9.2 to 9.6 in CentOS 7 (bold steps)”
Thanks for this – this was just what I needed after discovering that I’d not in fact upgraded to 9.5 and was now running a version incompatible with Django 2.1….
The default encoding for 9.2 is SQL_ASCII, the default for 9.6 is UTF8.
Solution is to ditch the initialised 9.6 db, and set PGSETUP_INITDB_OPTIONS=’-E SQL_ASCII’ as an environment variable before running `/usr/pgsql-9.6/bin/postgresql96-setup initdb`
In my case I had to add a locale argument: export PGSETUP_INITDB_OPTIONS=’-E SQL_ASCII –locale=C’
I’m getting this error message,
could not get pg_ctl version data using “/usr/bin/pg_ctl” –version: No such file or directory
after the following:
bash-4.2$ /usr/pgsql-9.6/bin/pg_upgrade -v -b /usr/bin/ -B /usr/pgsql-9.6/bin/ -d /var/lib/pgsql/data/ -D /var/lib/pgsql/9.6/data/
Running in verbose mode
Performing Consistency Checks
—————————–
Checking cluster versions
could not get pg_ctl version data using “/usr/bin/pg_ctl” –version: No such file or directory
Failure, exiting
master of masters
Thanks for this – this was just what I needed after discovering that I’d not in fact upgraded to 9.5 and was now running a version incompatible with Django 2.1….
THANKS !!! It saved a lot of my hours
I keep hitting this error:
encodings for database “postgres” do not match: old “SQL_ASCII”, new “UTF8”
Failure, exiting
Any idea?
The default encoding for 9.2 is SQL_ASCII, the default for 9.6 is UTF8.
Solution is to ditch the initialised 9.6 db, and set PGSETUP_INITDB_OPTIONS=’-E SQL_ASCII’ as an environment variable before running `/usr/pgsql-9.6/bin/postgresql96-setup initdb`
In my case I had to add a locale argument: export PGSETUP_INITDB_OPTIONS=’-E SQL_ASCII –locale=C’
Thank you. It worked perfectly.
Thanks! Still wondering why the CentOS repo has an EOL postgres version (9.2) in it.
Thanks a lot !
Awesome scripts, everything works like a charm !
Thanks a lot – i’m not sure if i’ve managed to upgrade pg without this howto!
I’m getting this error message,
could not get pg_ctl version data using “/usr/bin/pg_ctl” –version: No such file or directory
after the following:
bash-4.2$ /usr/pgsql-9.6/bin/pg_upgrade -v -b /usr/bin/ -B /usr/pgsql-9.6/bin/ -d /var/lib/pgsql/data/ -D /var/lib/pgsql/9.6/data/
Running in verbose mode
Performing Consistency Checks
—————————–
Checking cluster versions
could not get pg_ctl version data using “/usr/bin/pg_ctl” –version: No such file or directory
Failure, exiting
Thanks a lot – worked on a 9.2 to 11 pg_upgrade (CentOS 7).
Thanks so much! Worked perfectly – twice. I got bit by Centos installing 9.2 twice now.