In my previous article, we learned about how to install PostgreSQL on Debian 12. Now, as a GIS, I want to expand my database server capabilities. PostGIS allows us to store the GIS file formats directly in the PostgreSQL database. If you are a QGIS or ArcGIS Pro user, you can work with PostGIS seamlessly. Both software have good support for PostGIS. In this article, I am using the latest Debian 12.2.0. You can download a copy of Debian 12.2 from this link.
Steps to Install PostGIS on Debian 12
I can summarize the general steps to get the PostGIS up and running on our system below:
- Install PostgreSQL Server. You can use Linux, Windows, as well as Mac to install PostgreSQL
- Create a New Database
- Install PostGIS extension
- Enable PostGIS extension on the database. PostGIS must be enabled on the database.
- Connect GIS Software to PostGIS
Step 1. Install PostgreSQL Server
We can install PostgreSQL Server on almost any operating system. We can install it on Windows, Mac, and Linux. If you are running Debian 12, you can follow this tutorial to install PostgreSQL Server. Make sure you install it correctly and check the status with this command in Debian.
sudo systemctl status postgresql
At this point, we have the PostgreSQL server up and running. Let us continue to the next step.
Step 2. Install PostGIS
From the Terminal, execute this command to install PostGIS package in Debian 12.
apt install postgis
Now we need to enable the postgis extension to our database. In this example, I will enable the extension on my database called gis_database. Follow the steps below to enable postgis extension on a database.
So now our database has the postgis extension. Let’s try to put some spatial data into it. I will use QGIS program to export my spatial data to the database.
Open QGIS and go to Layer | Data Source Manager. Add our PostgreSQL database information.
To import a vector layer to the PostgreSQL server, go to Database | DB Manager. Choose the newly added PostgreSQL server and then click Import Layer/File. Specify the vector layer and click OK.
Now we have successfully imported a vector layer to our PostgreSQL database.