How to access your Linux based PostGIS database

Hey guys!
Here is the next part about PostGIS running on Ubuntu and how to use it for your everyday work with GIS on your client computer. This can be the same computer your database is running on (here Ubuntu 16.04) or any remote PC with Linux or Windows…
You don’t have a running PostGIS yet? Go to our installation tutorial for setting up a stable and up-to-date PostGIS DBMS on Ubuntu Linux!

First we need to install the Postgres Adminpack on our server system. It provides a number of support functions which pgAdmin3 and other administration tools can use to give additional functionality.

sudo -u postgres psql
CREATE EXTENSION adminpack;

Now we edit the config files of PostgreSQL to open access to external clients.

cd /etc/postgresql/9.6/main

sudo vim pg_hba.conf

Instead of vim you could use whatever editor you prefer. Let’s go to the end of the document and add the following line under # IPv4 local connections:

host    all             all             0.0.0.0/0               md5

This will allow all users with a md5 encrypted password to connect from remote. You could set whatever IP range you want to have here (e.g. for safety reasons your local network).

Now we edit postgresql.conf and change listen_addresses line to a specific IP of the server or ‘*’ to listen on all IPs:

sudo vim posgresql.conf

listen_addresses = '*'

Save and exit your editor. Do a service restart:

sudo service postgresql restart

Now we are ready to add the database in QGIS: In the Browser panel right-click on PostGIS and open “New Connection…”. Fill in your connection information:

If you are running QGIS on an external client then use the IP of your server in Host. Database and Username have to match your given designations throughout the installation process.

Successfully connected to the PostGIS database you can now add layers to it or use some of the PostGIS functions for data processing.
Let’s try a short example and convert the information of an ESRI shape file into a PostGIS vector layer.

Open QGIS and start the DB Manager (Database->DB Manager).
Click the Import layer/file button on the toolbar in the DB Manager dialog.
Select the shape file of your choice as Input. Click the Update Options button to pre-fill some of the form values. SRID fields (coordinate system) should be prefilled – if not choose the right coordinate system (e.g. WGS84 SRID 4326).
Your form could look like below:

After clicking OK you should refresh your database connection to see the new dataset. Now check if spatial reference etc. is listed correctly in Info of your DB Manager.

Drag and drop your layer from your database connection in the browser panel to your layers panel and have fun working with it!

The post How to access your Linux based PostGIS database first appeared on GIS-Blog.com.

Ubuntu Server Admin

Recent Posts

Predict, compare, and reduce costs with our S3 cost calculator

Previously I have written about how useful public cloud storage can be when starting a…

22 hours ago

One Thread to Poll Them All: How a Single Pipe Made WaterDrop 50% Faster

This is Part 2 of the "Karafka to Async Journey" series. Part 1 covered WaterDrop's…

1 day ago

A year of documentation-driven development

For many software teams, documentation is written after features are built and design decisions have…

2 days ago

Announcing FIPS 140-3 for Ubuntu Core22

With the release of the FIPS 140-3 certified cryptographic modules for Ubuntu 22.04 LTS, Canonical…

3 days ago

The foundations of software: open source libraries and their maintainers

Open source libraries are repositories of code that developers can use and, depending on the…

6 days ago

From inspiration to impact: design students from Regent’s University London explore open design for their dissertation projects

Last year, we had the opportunity to speak at Regent’s UX Conference (Regent’s University London’s…

7 days ago