New SonarQube server not starting due to database connection error

On a new test install of SonarQube 7.7 on CentOS-7.5 with Postgresql 10.7, I am getting the following error. What could be the issue?

java.lang.IllegalStateException: Can not connect to database. Please check connectivity and settings (see the properties prefixed by 'sonar.jdbc.').

The following Postgres commands were given.

postgres=#create role sonarqube with login password 'XXXXXXXX';
CREATE ROLE
postgres=# grant all on schema public to sonarqube;
GRANT
postgres=# \dn+
                          List of schemas
  Name  |  Owner   |   Access privileges   |      Description       
--------+----------+-----------------------+------------------------
 public | postgres | postgres=UC/postgres +| standard public schema
        |          | sonarqube=UC/postgres | 
(1 row)

postgres=# grant all on all tables in schema public to sonarqube;
GRANT
postgres=# \dn+
                          List of schemas
  Name  |  Owner   |   Access privileges   |      Description       
--------+----------+-----------------------+------------------------
 public | postgres | postgres=UC/postgres +| standard public schema
        |          | sonarqube=UC/postgres | 
(1 row)

The following JDBC settings are used in sonar.properties.

sonar.jdbc.username=sonarqube
sonar.jdbc.password=XXXXXXXX
sonar.jdbc.url=jdbc:postgresql://localhost/sonarqube

Hi Denny,

It’s not clear in your post which commands are been executed. Nevertheless I suggest to give a try to the following snippet that creates a simple sonarqube user. If it works then network connectivity is good and your problem comes from permission granting.

CREATE USER sonarqube WITH PASSWORD xxx;

CREATE DATABASE sonarqube WITH OWNER=sonarqube LC_COLLATE='en_US.utf8' LC_CTYPE='en_US.utf8' ENCODING='UTF8';

Properties are the same:

sonar.jdbc.url=jdbc:postgresql://localhost:5432/sonarqube
sonar.jdbc.username=sonarqube
sonar.jdbc.password=xxx

My 2 cents.

Unfortunately it’s still not working:

postgres=# drop user sonarqube;
DROP ROLE
postgres=# create user sonarqube with password ‘testing’;
CREATE ROLE
postgres=# CREATE DATABASE sonarqube WITH OWNER=sonarqube LC_COLLATE=‘en_US.UTF-8’ LC_CTYPE=‘en_US.UTF-8’ ENCODING=‘UTF8’;
CREATE DATABASE
postgres=#

From web.log
2019.05.08 23:14:58 ERROR web[o.s.s.p.Platform] Web server startup failed
java.lang.IllegalStateException: Can not connect to database. Please check connectivity and settings (see the properties prefixed by ‘sonar.jdbc.’).

From sonar.properties
sonar.jdbc.username=sonarqube
sonar.jdbc.password=testing
sonar.jdbc.url=jdbc:postgresql://localhost:5432/sonarqube

Hi.
Was a solution given to this case? the same error is happening to me. Recreating the sonar database no longer allows me to connect. I appreciate your help.