Install and Configure PostGIS on PostgreSQL

This tutorial is going to show you how to install and configure PostGIS on PostgreSQL. PostGIS is a GIS add-on for PostgreSQL. With this tool, you can turn PostgreSQL as a GIS database server where you can save your spatial data to PostgreSQL. By default, PostgreSQL does not support GIS spatial data which means you cannot load or save spatial data into it. At this point, PostGIS take place. Before we go further, make sure you have installed PostgreSQL Server on your system. You can install it on a local computer or on a remote one. 

Recommended Readings:

I assume you have PostgreSQL and PgAdmin installed on your system. If you are comfortable with the command line, you may not need the PgAdmin. 

Step 1. Install and Configure PostGIS on PostgreSQL 

I installed PostgreSQL on a Debian Linux and I am connecting it from an Ubuntu box. First, Install PostgreSQL and then make sure you can connect the PostgreSQL server from the network. Now let’s install PostGIS on Debian. If you are running PostgreSQL on another system, please visit the official website to check out how to install PostGIS on your system. In Debian, simply use this command to install PostGIS

sudo apt install postgis

Step 2. Create a New PostgreSQL Database

Open PgAdmin and login to your server. Right-click on Databases | Create Database

Configure PostGIS on PostgreSQL

If you prefer the command line, use this command

sudo -i -u postgres
psql
CREATE DATABASE gis_database;

Output:

postgres=# CREATE DATABASE gis_database;
CREATE DATABASE

Now, our new database is ready. 

Step 3. Create Extension PostGIS

Using the postgres privilege, execute this command:

Since we are going to add the extension to our new gis_database, we need to select or activate it first and then Create the extension.

psql -U postgres gis_database
CREATE EXTENSION postgis;

Done. 

At this point, our PostgreSQL can store spatial database. For example, you can export your spatial data from QGIS to this PostgreSQL Server. 

Be the first to comment

Leave a Reply