Install the PostGIS Extension for PostgreSQL on Ubuntu Linux
source link: https://www.vultr.com/docs/install-the-postgis-extension-for-postgresql-on-ubuntu-linux
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Introduction
PostgreSQL is a free open source object-relational database system with extensions available to extend its capabilities. PostGIS is a spatial database extension that provides location and geographic capabilities for PostgreSQL. PostGIS adds the POINT
datatype to define locations and can return location radiuses and distances using relevant queries.
This installation guide covers PostgreSQL versions 11 and 12.
Prerequisites
- A fully-updated Ubuntu Linux server, version 16.04 LTS or higher.
- A non-root sudo user.
1. Set up Repository
Add the PostgreSQL repository to your system. This repository provides automatic updates for all supported versions of PostgreSQL throughout the supported lifetime of PostgreSQL.
Install the required Gnu Privacy Guard dependency.
$ sudo apt -y install gnupg2
Import the repository PGP signing key.
$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
Add the PostgreSQL apt repository.
$ echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
2. Install PostgreSQL and PostGIS
PostgreSQL Version 12
Follow these steps if using PostgreSQL version 12.
Install PostgreSQL.
$ sudo apt -y install postgresql-12 postgresql-client-12
Install PostGIS.
$ sudo apt install postgis postgresql-12-postgis-3
Install the required control packages.
$ sudo apt-get install postgresql-12-postgis-3-scripts
PostgreSQL Version 11
Follow these steps if using PostgreSQL version 11.
Install PostgreSQL.
$ sudo apt -y install postgresql-11
Install PostGIS.
$ sudo apt install postgis postgresql-11-postgis-3
Install the required control packages.
$ sudo apt-get install postgresql-11-postgis-3-scripts
3. Log into PostgreSQL and Enable PostGIS
Log in as the superuser.
$ sudo su - postgres
Create a new PostgreSQL user.
$ createuser exampleuser
Set the password for the new user.
$ psql -c "alter user exampleuser with password 'yourPassword'"
Create a new database.
$ createdb my_db -O exampleuser
Connect to the database.
$ psql -d my_db
Enable the PostGIS extension for the database.
my_db=# CREATE EXTENSION postgis;
Test the PostGIS extension.
my_db=# SELECT PostGIS_version();
Conclusion
After installing the PostGIS extension, you can create fields that store geometry types. The geometrical data can be accessed using SQL queries. See the PostGIS documentation for more details and examples.
Want to contribute?
You could earn up to $600 by adding new articles
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK