Sys Admin

Installing PostgreSQL 9.4 and PostGis on CentOS 7

Fabrice

Jan. 22, 2016

PostGis PostgreSQL CentOS

Centos 7 provides PostgreSQL 9.2 but we can upgrade to 9.4.

Hopefully postgresql.org provides RPMs for Centos 7.

First install these extra packages:

yum install http://yum.postgresql.org/9.4/redhat/rhel-7-x86_64/pgdg-redhat94-9.4-1.noarch.rpm
yum groupinstall "PostgreSQL Database Server 9.4 PGDG"

Note this package use an install prefix:

/usr/pgsql-9.4/bin/psql

/var/lib/pgsql/9.4/data/

Thus we can run both in parallel.

If you have to stop PostgreSQL 9.2:

systemctl stop postgresql.service
systemctl disable postgresql.service

Then setup and enable PostgreSQL 9.4:

/usr/pgsql-9.4/bin/postgresql94-setup initdb
systemctl enable postgresql-9.4.service
systemctl start postgresql-9.4.service

To use PostGis, we have to compile it againt PostgreSQL 9.4. The package provided by EPEL is compiled againt 9.2 and is not aware of the prefix.

First install some dependencies:

yum install postgresql94-devel
yum install geos-devel.x86_64
yum install proj-devel.x86_64
yum install gdal-devel.x86_64
yum install libxml2-devel.x86_64
yum install json-c-devel.x86_64

Then compile PostGIS:

wget http://download.osgeo.org/postgis/source/postgis-2.2.1.tar.gz
tar xvzf postgis-2.2.1.tar.gz
cd postgis-2.2.1
./configure --with-pgconfig=/usr/pgsql-9.4/bin/pg_config
make
make install

Enjoy!