Why Use It?

The pg_service.conf file allows you to connect your QGIS project using only a Service Name, so your password is not stored (even in in encrypted format) in your QGIS document.

This is particulary important with QGIS as a misconfigured qgis_mapserver or Apache/NGINX can cause the .qgis file to be downloaded rather than rendered in the browser.

Create File on Server

1. Create the pg_service.conf file under the /etc/postgresql-common directory

../_images/40-pg_service-1.png ../_images/spacer11.png

2. The contents of the file should be as below. Make sure to substitute your geouser password for the password show below

../_images/40-pg_service-2.png ../_images/spacer11.png

Test File on Server

It’s a good idea to test your file.

To do, su to user postgres:

root@suite:~# su - postgres

Issue psql service=geosuiteb:

postgres@suite:~$ psql service=geosuitedb
psql (15.3 (Ubuntu 15.3-1.pgdg22.04+1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off)
Type "help" for help.

You have now verified the pg_service.conf file is working correctly.

Create File on Desktop

1. Copy the pg_service.conf file you created above to your desktop and note the location

2. Change the host to the hostname (or IP) of your GeoSuite server

So, for example, if your GeoSuite is running on IP, your file would look as below:


Register File

To registet the file, on Windows:

1. Go to Control Panel and click on User Acccounts

../_images/control-panel.png ../_images/spacer11.png

2. Click the User Acccounts link

../_images/control-panel-2.png ../_images/spacer11.png

3. On the left menu, click “Change my environmental variables”

../_images/control-panel-3.png ../_images/spacer11.png

4. In the Environmental Variables box click new. In the New User Variable box enter PGSERVICEFILE for Variable name and the location you saved the pg_service.conf file above as Variable value. Click OK

../_images/control-panel-4.png ../_images/spacer11.png

You have now registered your pg_service.conf file.

Test File on Desktop

To test our pg_service.conf file on our desktop, start QGIS.

1. On the left menu, click PostGIS and then right click “Add New Connection”

../_images/30-qgis-2.png ../_images/spacer11.png

2. In the Create New PostGIS Connection box, give your connection and name enter your service name

../_images/30-qgis-0-2.png ../_images/spacer11.png

3. Click the Test Connection button. You should see a success message at top as show below

../_images/30-qgis-0-3.png ../_images/spacer11.png

Congradualtions, you have successfully create a pg_service.conf file on your server and desktop