How to Install the PostGIS Extension for PostgreSQL

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

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
Install PostgreSQL
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
Install the PostGIS Extension for PostgreSQL
Install the PostGIS Extension for PostgreSQL

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:

Check the possible extension to load
Check the possible extension to load

And this other one:

SELECT postgis_version();

Sample output:

PostGIS running with PostgreSQL
PostGIS running with PostgreSQL

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.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Angelo
Angelo
I am Angelo. A systems engineer passionate about Linux and all open-source software. Although here I'm just another member of the family.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook