Be sure to make a copy of all databases of the server before all the work performed
    Example of version change from PostgreSQL 9.2 to PostgreSQL 9.3 on Centos 7 and on Debian 8 example of version change from 9.4 to 9.5

    Centos 7 PostgreSQL 9.3

    Install the repository. The repository with the required version can be found at

    rpm -ivh ./pgdg-centos93-9.3-3.noarch.rpm  

    See which postgresql packages are installed:

    rpm -qa | grep postgresql  

    Install the same packages of version 9.3 and the contrib package

    yum install postgresql93-server.x86_64 postgresql93-libs.x86_64 postgresql93.x86_64 postgresql93-contrib.x86_64  

    In /usr/lib/systemd/system/postgresql-9.3.service specify a port different from the standard port, for example PGPORT=5432 Check that PGDATA is different from /var/lib/pgsql/data/, for example PGDATA=/var/lib/pgsql/9.3/data/ Initialize 9.3 Postgresql

    /usr/pgsql-9.3/bin/postgresql93-setup initdb

    Make sure that directory /var/lib/pgsql/9.3/data/ and files there are created. Stop the postgresql server

    service postgresql stop  

    You need to run the pg_upgrade utility. Utility options:

    • -b binary directory of the old version of postgresql
    • -B the binary directory of the new postgresql version
    • -d data directory of the old version of postgresql
    • -D data directory of the new version of postgresql

    Run pg_upgrade

    su postgres  
    cd /var/lib/pgsql/9.3/  
    /usr/pgsql-9.3/bin/pg_upgrade -v -b /usr/bin/ -B /usr/pgsql-9.3/bin/ -d /var/lib/pgsql/data/ -D /var/lib/pgsql/9.3/data/

    Possible problems:

    There were problems executing ""/usr/bin/pg_ctl" -w -l "pg_upgrade_server.log" -D "/var/lib/pgsql/data/" -o "-p 50432 -b  
    -c listen_addresses= - - c unix_socket_permissions=0700 -c unix_socket_directory='/var/lib/pgsql/9.3/data'" start >> "pg_upg_server.log" 2>&1"
    Consult the last few lines of "pg_upgrade_server.log" for  
    the probable cause of the failure.  

    The pg_upgrade_server.log has the following errors:

    command: "/usr/bin/pg_ctl" -w -l "pg_upg_server.log" -D "/var/lib/pgsql/data/" -o "-p 50432 -b -c listen_addresses= -c  
    unix_socket_permissions=0700 -c unix_socket_directory='/var/lib/pgsql/9.3/data'" start >> "pg_upgrade_server.log" 2>&1  
    waiting for server to start....FATAL: unrecognized configuration parameter "unix_socket_directory"  
    stopped waiting  
    pg_ctl: could not start server  
    Examine the log output.  

    Execute the following commands as root:

    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  
    connection to database failed: FATAL: no pg_hba.conf entry for host "[local]", user "postgres", database "template1", SSL off  

    To solve this problem you need to add in /var/lib/pgsql/data/pg_hba.conf a line:

    local all all trust  

    Compare the configuration file of the old server with the new one.

    diff /var/lib/pgsql/data/pg_hba.conf  

    If necessary, copy the configuration file pg_hba.conf

    cp /var/lib/pgsql/data/pg_hba.conf  

    Change the port to the default port in /usr/lib/systemd/system/postgresql-9.3.service PGPORT=5432 Start the new server

    service postgresql-9.3 start  


    su postgres  

    Run, to delete the directory of the old server. All databases will be deleted


    Copy the contents of the new directory to the working directory of the server.

    cp -R /var/lib/pgsql/9.3/data /var/lib/pgsql/  
    chown -R postgres:postgres /var/lib/pgsql/data  

    In /usr/lib/systemd/system/postgresql-9.3.service change PGDATA to /var/lib/pgsql/data/ Restart

    service postgresql-9.3 restart  

    Delete the old server

    yum remove postgresql-server-9.2.15-1.el7_2.x86_64 postgresql-9.2.15-1.el7_2.x86_64 postgresql-libs-9.2.15-1.el7_2.x86_64  

    Run the script with the following contents:

    ls /usr/pgsql-9.3/bin/ |while read line  
    ln -s /usr/pgsql-9.3/bin/$line /usr/bin/$line  

    In the file /var/lib/pgsql/.bash_profile change the version to 9.3 After having done all these operations you should download the existing database backup and check that the server is working.

    Debian 8 PostgreSQL 9.5

    Connecting the repository with other versions of postgresql In the file /etc/apt/sources.list add the following lines

    # postgreSQL repository
    deb jessie-pgdg main  

    Import the repository key

    wget --quiet -O - | apt-key add -  

    Let's update the packages:

    apt-get update -y  

    Check for PostgreSQL versions

    apt-cache search postgresql- | less  

    Install version 9.5 of PostgreSQL

    apt-get install postgresql-9.5 -y  

    Uninstall the new version of the cluster:

    pg_dropcluster --stop 9.5 main  

    Use the pg_upgradecluster script to upgrade to the new major version, the configuration files and data will be copied to the new cluster.

    pg_upgradecluster -v 9.5 9.4 major  

    There may be problems during the upgrade:

    psql: FATAL: no pg_hba.conf entry for host "[local]", user "postgres", database "template1", SSL off  
    psql: FATAL: no pg_hba.conf entry for host "[local]", user "postgres", database "template1", SSL off  
    Use of uninitialized value $out in pattern match (m//) at /usr/share/perl5/ line 915.  
    psql: FATAL: no pg_hba.conf entry for host "[local]", user "postgres", database "template1", SSL off  
    Use of uninitialized value $out in pattern match (m//) at /usr/share/perl5/ line 921.  
    Use of uninitialized value $ctype in scalar chomp at /usr/share/perl5/ line 924.  
    Use of uninitialized value $collate in scalar chomp at /usr/share/perl5/ line 925.  
    Error: could not get cluster locales  

    You should add to /etc/postgresql/9.4/main/pg_hba.conf the line

    local all all trust  

    After the upgrade delete this line from /etc/postgresql/9.5/main/pg_hba.conf Remove the old server, all databases will be removed:

    pg_dropcluster --stop 9.4 main  

    After the work you should check the server availability, if there is no DB, download the backup copy.

    С подробной информацией можно ознакомится на официальном сайте разработчика.