Hello, friends. In this post, you will learn how to install PostGIS Extension for PostgreSQL using Ubuntu 22.04, but it is perfectly applicable to other systems.
According to the project website
PostGIS is a spatial database extender for PostgreSQL object-relational database. It adds support for geographic objects allowing location queries to be run in SQL.
In addition to basic location awareness, PostGIS offers many features rarely found in other competing spatial databases such as Oracle Locator/Spatial and SQL Server.
It has become one of the leading extensions in its segment and one of the most important globally.
Of course, it is Open source and is available for almost any system where PostgreSQL is installed.
Let’s go for it.
Install PostGIS Extension for PostgreSQL
As you can notice, the first thing we have to do is to install PostgreSQL. As the goal of this post is not the installation of PostgreSQL, I will move a little fast.
So, connect via SSH to the server and update it
sudo apt update
sudo apt upgrade
Then, install PostgreSQL with the command
sudo apt install postgresql
Remember that with the installation, a user named postgres
will be created, and we have to change the password to it
sudo passwd postgres
Then, install PostGIS from the official repositories. Furthermore, you can use other methods, but this is the best one.
sudo apt install postgis
Now, access the PostgreSQL console.
su - postgres
psql
Now check if PostGIS is available for loading
SELECT * FROM pg_available_extensions;
In the wide screen output, you should notice that it is available.
The next step is to load it. It is simple, to achieve this, run.
CREATE EXTENSION postgis ;
And to verify if everything went well, you have two commands to test. The first one.
SELECT * FROM pg_extension;
Sample output:
And this other one:
SELECT postgis_version();
Sample output:
So, that’s it. Everything went well.
Conclusion
In this post, you learned how to install PostGIS on Ubuntu. I hope you liked it, and you can get more out of PostgreSQL.