PostGIS is a free and open-source database extender for the PostgreSQL Database Management System. It helps you to add some extra functions such as, area, union, intersection, distance, data types, and allow location queries to be run in SQL. With PostGIS, you can store the polygon and point types of the data in the PostgreSQL database.

In this tutorial, we will show you how to install PostGIS with PostgreSQL on CentOS 8.

Prerequisites

  • A server running CentOS 8.
  • A root password is configured on your server.

Getting Started

Before starting, you will need to install PostGIS and EPEL repo to your system. You can install both by running the following command:

dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

Next, enable the Powertool repo and disable the default PostgreSQL repo with the following command:

dnf config-manager --set-enabled PowerTools

dnf -qy module disable postgresql

Once you are finished, you can proceed to the next step.

Install PostGIS

Now, you can install the PostGIS by running the following command:

dnf install postgis25_12

Once the installation has been completed, you can verify the PostGIS package with the following command:

rpm -qi postgis25_12

You should get the following output:

Name        : postgis25_12
Version     : 2.5.5
Release     : 2.rhel8
Architecture: x86_64
Install Date: Monday 01 February 2021 11:59:37 PM EST
Group       : Unspecified
Size        : 29832534
License     : GPLv2 
Signature   : DSA/SHA1, Tuesday 10 November 2020 01:36:47 PM EST, Key ID 1f16d2e1442df0f8
Source RPM  : postgis25_12-2.5.5-2.rhel8.src.rpm
Build Date  : Tuesday 10 November 2020 01:30:09 PM EST
Build Host  : koji-rhel8-x86-64-pgbuild
Relocations : (not relocatable)
Vendor      : PostgreSQL Global Development Group
URL         : http://www.postgis.net/
Summary     : Geographic Information Systems Extensions to PostgreSQL
Description :
PostGIS adds support for geographic objects to the PostgreSQL object-relational
database. In effect, PostGIS "spatially enables" the PostgreSQL server,
allowing it to be used as a backend spatial database for geographic information
systems (GIS), much like ESRI's SDE or Oracle's Spatial extension. PostGIS
follows the OpenGIS "Simple Features Specification for SQL" and has been
certified as compliant with the "Types and Functions" profile.

Next, initialize the PostgreSQL database with the following command:

/usr/pgsql-12/bin/postgresql-12-setup initdb

Next, start the PostgreSQL service and enable it to start at system reboot with the following command:

systemctl start postgresql-12.service

systemctl enable postgresql-12.service

Create an Extension

At this point, PostgreSQL and PostGIS have been installed. Now, you will need to create an extension for PostGIS.

First, login to Postgres user with the following command:

su - postgres

Next, create a postgres user and database with the following command:

createuser test_usr

createdb test_postgis -O test_usr

Next, connect to the database with the following command:

psql -d test_postgis

You should see the following output:

psql (12.5)
Type "help" for help.

Next, create a PostGIS extension with the following command:

CREATE EXTENSION postgis;

Next, you can verify the PostGIS version using the following command:

select PostGIS_Full_Version();

You should see the PostGIS version in the following output:

                                                                                          postgis_full_version                                 
                                                          
-----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------
 POSTGIS="2.5.5" [EXTENSION] PGSQL="120" GEOS="3.8.1-CAPI-1.13.3" PROJ="Rel. 7.2.1, January 1st, 2021" GDAL="GDAL 3.2.1, released 2020/12/29" L
IBXML="2.9.7" LIBJSON="0.13.1" LIBPROTOBUF="1.3.0" RASTER
(1 row)

Next, exit from the Postgres shell with the following command;

exit

exit

Conclusion

In the above guide, you learned how to install PostGIS with PostgreSQL on CentOS 8. You can now use PostGIS to add geometry to your database.

How to Install PostGIS PostgreSQL database extender on CentOS 8 centos

About Hitesh Jethva

Over 8 years of experience as a Linux system administrator. My skills include a depth knowledge of Redhat/Centos, Ubuntu Nginx and Apache, Mysql, Subversion, Linux, Ubuntu, web hosting, web server, Squid proxy, NFS, FTP, DNS, Samba, LDAP, OpenVPN, Haproxy, Amazon web services, WHMCS, OpenStack Cloud, Postfix Mail Server, Security etc.