1

I followed these steps to set up QWC services https://github.com/qwc-services/qwc-services-core#quick-start and I can run the demo. But if load my own QGIS project, I receive the following error message:

qwc-qgis-server_1              | 07:50:07 WARNING Server[99]: <ServerException>Layer(s) not valid</ServerException>
qwc-qgis-server_1              | 
qwc-qgis-server_1              | 07:50:07 WARNING ClearCapabilities[99]: Cached cleared : /data/MeasurementDemo.qgs
qwc-qgis-server_1              | 07:50:07 WARNING PostGIS[99]: Connection to database failed
qwc-qgis-server_1              | could not connect to server: No such file or directory
qwc-qgis-server_1              |    Is the server running locally and accepting
qwc-qgis-server_1              |    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
qwc-qgis-server_1              | 
qwc-qgis-server_1              | 07:50:07 CRITICAL Server[99]: Error, Layer(s) measurement_b46e976f_2d0f_4bf0_942a_9d9462b40c3e not valid in project /data/MeasurementDemo.qgs
qwc-qgis-server_1              | 07:50:07 WARNING Server[99]: <ServerException>Layer(s) not valid</ServerException>
qwc-qgis-server_1              | 
qwc-config-service_1           | [2022-01-04 07:50:09,360] WARNING in config_generator: Skipping theme item '': Could not get capabilities for /ows/MeasurementDemo
qwc-config-service_1           | [2022-01-04 07:50:19,468] CRITICAL in config_generator: The generation of the configuration files resulted in a failure
qwc-config-service_1           | [2022-01-04 07:50:19,468] CRITICAL in config_generator: The configuration files were not updated!
qwc-config-service_1           | [2022-01-04 07:50:20,856] CRITICAL in config_generator: The generation of the permission files resulted in a failure.
qwc-config-service_1           | [2022-01-04 07:50:20,857] CRITICAL in config_generator: The permission files were not updated!
qwc-config-service_1           | [pid: 15|app: 0|req: 18/18] 172.18.0.11 () {30 vars in 408 bytes} [Tue Jan  4 07:50:05 2022] POST /generate_configs?tenant=default => generated 2881 bytes in 15083 msecs (HTTP/1.1 200) 2 headers in 81 bytes (1 switches on core 0)

As the error is quite similar to this question: PostgreSQL: Why psql can't connect to server?, I followed the answers but with no result.

ps -ef | grep postgres gives me the following result:

postgres  203911       1  0 07:35 ?        00:00:00 /usr/lib/postgresql/13/bin/postgres -D /var/lib/postgresql/13/main -c config_file=/etc/postgresql/13/main/postgresql.conf

Also I found the socket in

/var/run/postgresql/.s.PGSQL.5432

And I run the command

psql -h /var/run/postgresql/ GeoDB

But without result. After that I checked the ph_hba.conf File:

# "local" is for Unix domain socket connections only
local   all             all                                     peer

Running the command pg_lsclusters gives me:

Ver Cluster Port Status Owner    Data directory              Log file
13  main    5432 online postgres /var/lib/postgresql/13/main /var/log/postgresql/postgresql-13-main.log

Also after restarting the pg_ctlcluster and PostgreSQL the error remained the same.

Edit 1 After the answer from cnaimi I checked the postgresql.confFile:

# - Connection Settings -

#listen_addresses = '*'         # what IP address(es) to listen on;
                                # comma-separated list of addresses;
                                # defaults to 'localhost'; use '*' for all
                                # (change requires restart)
port = 5432                     # (change requires restart)
max_connections = 100           # (change requires restart)
#superuser_reserved_connections = 3 # (change requires restart)
unix_socket_directories = '/var/run/postgresql' # comma-separated list of directories
                                # (change requires restart)
#unix_socket_group = '*'        # (change requires restart)
#unix_socket_permissions = 0777     # begin with 0 to use octal notation
                                # (change requires restart)
#bonjour = off                  # advertise server via Bonjour
                                # (change requires restart)
#bonjour_name = ''              # defaults to the computer name
                                # (change requires restart)

But I can't find an error there as the port is 5432 and it listen to all adresses.

Edit 2 During my search I found several pg_service.conf Files:

./qwc-services/qwc-docker/wsgi-service/pg_service.conf
./qwc-services/qwc-docker/qgis-server/pg_service.conf
./qwc-services/qwc-docker/postgis/pg_service.conf
./qwc-services/qwc-docker/pg_service.conf

Each if them contain one or more credentials for databases like the one below:

[qwc_geodb]
host=qwc-postgis
port=5432
dbname=qwc_demo
user=qwc_service
password=qwc_service
sslmode=disable

The port is in all files correct, as far as I saw. But of course the db name and user/password are wrong. Does this could cause the error? Or does QWS get the credentials through the .qgs file?

Edit 3 Thanks to the hints from Devdatta Tengshe I set the host for PostgreSQL to 127.0.0.1. By using sudo docker-compose ps one can see the used container and their ports:

                  Name                                Command                  State                      Ports                
-------------------------------------------------------------------------------------------------------------------------------
qwc-docker_qwc-admin-gui_1                 /bin/sh -c uwsgi --http-so ...   Up             127.0.0.1:5031->9090/tcp            
qwc-docker_qwc-api-gateway_1               /docker-entrypoint.sh ngin ...   Up             0.0.0.0:8088->80/tcp,:::8088->80/tcp
qwc-docker_qwc-auth-service_1              /bin/sh -c uwsgi --http-so ...   Up             127.0.0.1:5017->9090/tcp            
qwc-docker_qwc-config-service_1            /bin/sh -c uwsgi --http-so ...   Up             127.0.0.1:5010->9090/tcp            
qwc-docker_qwc-data-service_1              /bin/sh -c uwsgi --http-so ...   Up             127.0.0.1:5012->9090/tcp            
qwc-docker_qwc-elevation-service_1         /bin/sh -c uwsgi --http-so ...   Up             127.0.0.1:5002->9090/tcp            
qwc-docker_qwc-fulltext-search-service_1   /bin/sh -c uwsgi --http-so ...   Up             127.0.0.1:5011->9090/tcp            
qwc-docker_qwc-map-viewer_1                /bin/sh -c uwsgi --http-so ...   Up             127.0.0.1:5030->9090/tcp            
qwc-docker_qwc-mapinfo-service_1           /bin/sh -c uwsgi --http-so ...   Up             127.0.0.1:5016->9090/tcp            
qwc-docker_qwc-ogc-service_1               /bin/sh -c uwsgi --http-so ...   Up             127.0.0.1:5013->9090/tcp            
qwc-docker_qwc-permalink-service_1         /bin/sh -c uwsgi --http-so ...   Up             127.0.0.1:5001->9090/tcp            
qwc-docker_qwc-postgis_1                   docker-entrypoint.sh postgres    Up (healthy)   127.0.0.1:5439->5432/tcp            
qwc-docker_qwc-qgis-server_1               /sbin/my_init                    Up             127.0.0.1:8001->80/tcp              
qwc-docker_qwc-solr_1                      docker-entrypoint.sh solr- ...   Up             127.0.0.1:8983->8983/tcp
Dennis
  • 171
  • 3
  • 16
  • Where is the Postgres Server running? Is it on the host? or is it running within a docker container? Additionally it looks like the qgs file is looking for a Postgres running on localhost, but it won't be able to connect, because there is no postgres running inside that docker container. – Devdatta Tengshe Jan 05 '22 at 07:12
  • Thanks @DevdattaTengshe for this hint, that's true I didn't installed Postgres inside the docker. Do I have to install it inside the docker with `$ docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres`? Is it then available for all docker container? – Dennis Jan 05 '22 at 08:28
  • You can create the gqs file and use 127.0.0.1 as the Postgres host; and then run this docker container like this: https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach – Devdatta Tengshe Jan 05 '22 at 09:53
  • Thanks for this information, I edited my question as I set the host to 127.0.0.1 but if I try to follow the answer in your link, I'm not sure which container (or all?) I should change as to my understanding all are already using the port 127.0.0.1. Sorry, I'm new to docker and have not much experience with this. – Dennis Jan 05 '22 at 11:00

2 Answers2

0

Can you check the postgres.conf file located in /etc/postgresql/13/main/postgresql.conf specially the parameter listen_address

Maybe you have to specify from which host you are listening. But if the demo example is working the database configuration should be ok.

You can also check the port for postgres on postgres.conf and validate it's 5432.

cnaimi
  • 484
  • 6
  • 10
  • Thank you for your idea, I added some lines from the postgresql.config file but I can't find an error in it. – Dennis Jan 04 '22 at 09:24
  • did you try to uncomment the line #listen_addresses = '*' and restart postgres ? I am not sure of the setting in use with the line commented. – cnaimi Jan 04 '22 at 09:35
  • I completely missed that it is commented, I just uncommented the line and used sudo service postgresql restart to restart postgresql, but the error remains – Dennis Jan 04 '22 at 09:39
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 04 '22 at 10:53
0

There are a couple of things that need to be fixed to get this working.

I'm assuming that you have the Postgres Server running on the host machine, and not within any Docker container.

When you configured your QGIS Map file, you probably connected to localhost, and this information got saved in the .qgs file.

This is why your first error message says that it trying to connect to localhost, and no server was found. This error was thrown within the qwc docker container.

This error is occuring, because QGIS server (within the docker container) is not able to connect to the postgres server which is running on the host, using 'localhost' as the hostname

To solve this, you need to do the following:

  1. In QGIS, connect to the Postgres Server using 127.0.0.1 and not localhost.

  2. Save your qgs file using this new connection.

  3. When you run the docker container for qwc, use --network="host" as the commandline parameter.

See: From inside of a Docker container, how do I connect to the localhost of the machine?

After this, the qgis server (within docker container) should be able to connect to the Postgres Server running on your host, using 127.0.0.1 as IP address.

Devdatta Tengshe
  • 4,015
  • 10
  • 46
  • 59
  • Really great, just point three creates problem as I use ```docker-compose``` and not docker run as there are several container. As I found out ```--network="host"``` is not supported there. As far as I found out until now I should change the docker-compose.yml file as in https://stackoverflow.com/questions/56582446/how-to-use-host-network-for-docker-compose but until now the solution in this link doesn't work (```network_mode``` as well as ```net``` are not supported). – Dennis Jan 05 '22 at 15:02