Upgrade Postgresql


Upgrade Postgresql 9.2 to 9.5

This tutorial how to upgrade postrgesql from postgresql 9.2 to postresql 9.5. but this command can use in other version also. We change the version from older and newest also :

1. First, update repository the new postresql version
[root@master ~]# yum update -y
[root@master ~]# yum install https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-3.noarch.rpm
2. Install postgresql that new version. In this case, I install postgresql 9.5
[root@master ~]# yum install postgresql95-server postgresql95 postgresql95-contrib rsync -y
3. Setting up data direcotry with this command below
[root@master ~]# /usr/pgsql-9.5/bin/postgresql95-setup initdb
4. Start and enable service postgresql 9.5
[root@master ~]# systemctl start postgresql-9.5.service
[root@master ~]# systemctl enable postgresql-9.5.service
5. Check status postgresql 9.5
[root@master ~]# systemctl status postgresql-9.5
6. Stop old postgresql (9.3) and new postgresql (9.5)
[root@master ~]# service postgresql-9.2 stop
[root@master ~]# service postgresql-9.5 stop
7. Move directory to /tmp
[root@master ~]# cd /tmp
8. Running this script bellow to upgrade postrgesql
[root@master ~]# sudo -u postgres /usr/pgsql-9.5/bin/pg_upgrade --old-bindir=/usr/pgsql-9.2/bin/ --new-bindir=/usr/pgsql-9.5/bin/ --old-datadir=/var/lib/pgsql/9.2/data/ --new-datadir=/var/lib/pgsql/9.5/data/
9. Copy direcotry postgresql configuration from postresql 9.2 to postrgesql 9.5
[root@master ~]# cp /var/lib/pgsql/9.2/data/postgresql.conf /var/lib/pgsql/9.5/data/postgresql.conf
10. Start service postrgesql 9.5
[root@master ~]# service postgresql-9.5 start
11. Enable postgresql 9.5 and disable postgresql 9.2
[root@master ~]# systemctl enable postgresql-9.5.service
[root@master ~]# systemctl disable postgresql-9.2.service

Post a Comment

Previous Post Next Post