Can't connect to PostgreSQL 12 database with SQ 8.4

I have installed PostgreSQL 12 - also trying on 13 version.
Config file pg_hba.conf:

# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5

Man page: https://www.postgresql.org/docs/current/auth-pg-hba-conf.html

Connecting via CLI works as expected.

$ psql -d sonarqube -U postgres -W -p 5432 -h localhost

Also working external app connections: DataGrid, PhpStorm, pgAdmin4.

I have fresh install of SonarQube 8.4.
Config file sonar.properties:

sonar.jdbc.username=postgres
sonar.jdbc.password=secret
sonar.embeddedDatabase.port=5432
sonar.jdbc.url=jdbc:postgresql://localhost/sonarqube

I also try

sonar.jdbc.url=jdbc:postgresql://localhost:5432/sonarqube

I have that error:

2020.11.01 11:53:52 ERROR web[][o.s.s.p.PlatformImpl] Web server startup failed
java.lang.IllegalStateException: Unable to start database
        at org.sonar.server.platform.db.EmbeddedDatabase.startServer(EmbeddedDatabase.java:87)
        at org.sonar.server.platform.db.EmbeddedDatabase.start(EmbeddedDatabase.java:62)
        at org.sonar.server.platform.db.EmbeddedDatabaseFactory.start(EmbeddedDatabaseFactory.java:49)
        at org.sonar.core.platform.StartableCloseableSafeLifecyleStrategy.start(StartableCloseableSafeLifecyleStrategy.java:40)
        at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.start(AbstractInjectionFactory.java:84)
        at org.picocontainer.behaviors.AbstractBehavior.start(AbstractBehavior.java:169)
        at org.picocontainer.behaviors.Stored$RealComponentLifecycle.start(Stored.java:132)
        at org.picocontainer.behaviors.Stored.start(Stored.java:110)
        at org.picocontainer.DefaultPicoContainer.potentiallyStartAdapter(DefaultPicoContainer.java:1016)
        at org.picocontainer.DefaultPicoContainer.startAdapters(DefaultPicoContainer.java:1009)
        at org.picocontainer.DefaultPicoContainer.start(DefaultPicoContainer.java:767)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
        at org.sonar.server.platform.platformlevel.PlatformLevel.start(PlatformLevel.java:90)
        at org.sonar.server.platform.platformlevel.PlatformLevel1.start(PlatformLevel1.java:166)
        at org.sonar.server.platform.PlatformImpl.start(PlatformImpl.java:213)
        at org.sonar.server.platform.PlatformImpl.startLevel1Container(PlatformImpl.java:172)
        at org.sonar.server.platform.PlatformImpl.init(PlatformImpl.java:86)
        at org.sonar.server.platform.web.PlatformServletContextListener.contextInitialized(PlatformServletContextListener.java:43)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4689)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5155)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1412)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1402)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.h2.jdbc.JdbcSQLInvalidAuthorizationSpecException: Wrong user name or password [28000-199]
        at org.h2.message.DbException.getJdbcSQLException(DbException.java:459)
        at org.h2.message.DbException.getJdbcSQLException(DbException.java:427)
        at org.h2.message.DbException.get(DbException.java:205)
        at org.h2.message.DbException.get(DbException.java:181)
        at org.h2.message.DbException.get(DbException.java:170)
        at org.h2.engine.Engine.validateUserAndPassword(Engine.java:366)
        at org.h2.engine.Engine.createSessionAndValidate(Engine.java:186)
        at org.h2.engine.Engine.createSession(Engine.java:161)
        at org.h2.engine.Engine.createSession(Engine.java:31)
        at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:336)
        at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:169)
        at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:148)
        at org.h2.Driver.connect(Driver.java:69)
        at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)
        at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:251)
        at org.sonar.server.platform.db.EmbeddedDatabase.createDatabase(EmbeddedDatabase.java:114)
        at org.sonar.server.platform.db.EmbeddedDatabase.startServer(EmbeddedDatabase.java:78)
        ... 26 common frames omitted

EDIT:
When I comment that line

#sonar.embeddedDatabase.port=5432

SonarQube start as expected.
LOL

Hi @LocalHeroPro and welcome to the community :wave:

you already found the solution. the property sonar.embeddedDatabase.port defines the port for the embedded h2 database and not the postgresql that you want to attach sonarqube to. if you change the port, the h2 database will be created but sonarqube will fail to do something with it, resulting in the failure you observerd.

can you point us to the documentation that made you assume that you had to change this value, so we can improve our docs on this?

Thanks

My bad with config line with H2 port.
Please update docs with information about config file pg_hba.conf.
Thanks!

we don’t provide a detailed configuration for every DBMS and framework there is, that would be too much to maintain and this is already covered by the DBMS specific documentation you already mentioned

never the less i am glad that everything is working for you now and happy analyzing :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.