How to install PostGIS PostgreSQL database extender on CentOS 8
How to install PostGIS PostgreSQL database extender on CentOS 8
PostGIS is a free and open source database extension program for PostgreSQL database management system. It can help you add some extra features, such as area, union, intersection, distance, data type, and allows you to run location queries in SQL. Using PostGIS, the polygon and point types of the data can be stored in the PostgreSQL database.
In this tutorial, we will show you how to install PostGIS with PostgreSQL on CentOS 8.
prerequisites
- Server running CentOS 8.
- A root password is configured on your server.
getting Started
Before starting, you need to install PostGIS and EPEL libraries into the 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.rpmdnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
Next, use the following command to enable the Powertool repository and disable the default PostgreSQL repository:
dnf config-manager --set-enabled PowerToolsdnf -qy module disable postgresql
Once completed, you can proceed to the next step.
Install PostGIS
Now, you can install PostGIS by running the following command:
dnf install postgis25_12
After the installation is complete, 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, use the following command to initialize the PostgreSQL database:
/usr/pgsql-12/bin/postgresql-12-setup initdb
Next, start the PostgreSQL service and use the following command to enable it to start when the system restarts:
systemctl start postgresql-12.servicesystemctl enable postgresql-12.service
Create an extension
So far, PostgreSQL and PostGIS have been installed. Now you will need to create an extension for PostGIS.
First, log in to the Postgres user using the following command:
su - postgres
Next, create a postgres user and database using the following commands:
createuser test_usrcreatedb test_postgis -O test_usr
Next, use the following command to connect to the database:
psql -d test_postgis
You should see the following output:
psql (12.5) Type "help" for help.
Next, use the following command to create the PostGIS extension:
CREATE EXTENSION postgis;
Next, you can verify the PostGIS version with 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, use the following command to exit from the Postgres shell;
exitexit
in conclusion
In the above guide, you learned how to install PostgreSQL together with PostgreSQL on CentOS 8. You can now use PostGIS to add geometry to the database.