SonarQube with Postgres on Docker

I tried to configure sonarqube (7.6) to use postgresql database and it seems to ignore the jdbc entries in the sonar.properties and picks up the H2 database. When I pass the properties as jvm parameters, it picks up fine. How do I configure sonar to use postgres from the sonar.properties

sonar.properties:

sonar.jdbc.username=myuser
sonar.jdbc.password=mypwd
sonar.jdbc.url=jdbc:postgresql://ipaddress:5444/mypostgres
sonar.log.level=DEBUG

Log snippet:

2019.03.25 05:42:03 INFO web[o.s.s.e.EsClientProvider] Connected to local Elasticsearch: [127.0.0.1:9001]
2019.03.25 05:42:03 INFO web[o.s.s.p.LogServerVersion] SonarQube Server / 7.6.0.21501 / d56689a5eb122c06cf87375828085609f5a68323
2019.03.25 05:42:03 INFO web[o.s.s.p.d.EmbeddedDatabase] Starting embedded database on port 9092 with url jdbc:h2:tcp://127.0.0.1:9092/sonar
2019.03.25 05:42:03 INFO web[o.s.s.p.d.EmbeddedDatabase] Embedded database started. Data stored in: /opt/sonarqube/data
2019.03.25 05:42:03 INFO web[o.sonar.db.Database] Create JDBC data source for jdbc:h2:tcp://127.0.0.1:9092/sonar
2019.03.25 05:42:03 WARN web[o.s.db.dialect.H2] H2 database should be used for evaluation purpose only.
2019.03.25 05:42:05 INFO web[o.s.s.p.ServerFileSystemImpl] SonarQube home: /opt/sonarqube

Hi,

Are you sure you don’t have another sonar.jdbc.url entry ?
Could you search for the text ‘h2’ in the file ?

Regards,
Julien Lancelot

The sonar.properties has only 4 lines as pasted above. I removed all the entries from the default sonar.properties and kept only the jdbc and log properties there.

Are you using a Docker image ? Are you sure the sonar.properties is in a folder that can be read by SonarQube ?

Yes. I’m using a docker image. The sonar.properties are located in conf/sonar.properties and the properties file seems to be used by sonarQube. The ‘sonar.log.level=DEBUG’ seems to come into effect and starts logging ‘debug’ level events.

Then I’m sorry but I’ve not idea what is not working…

no worries. I went with the JVM parameters approach and it works fine. Thank you for your help!

Hi, I’m also facing the same issue. SonaQube is not picking Postgresql, always connecting to the default database.

Don’t know what is the fault.
I’m using docker image of sonarqube and added sonar property file, docker image is taking the property file which I added
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.jdbc.url=jdbc:postgresql://localhost:5432/sonarqube?currentSchema=sonar

I tried with localhost, hostname, container name because I’m using docker for Postgres also.

This is the docker compose file written for postgresql
image: postgres
container_name: postgresDC
hostname: postgres
environment:
- POSTGRES_USER=sonar
- POSTGRES_PASSWORD=sonar
- POSTGRES_DB=sonar

Log is
LOG: database system is ready to accept connections

@Tweety_Darling please let me know how you are using the JVM parameters approach?

Hello,

Due to the SONAR-12501 bug, jdbc properties in sonar.properties are ignored on all docker images versions until 8.0. If you are using the 7.9.1 LTS, you have to set your properties with the -e sonar.jdbc.username and -e sonar.jdbc.password flags on the docker run command line.

The official documentation on docker hub have been updated last week to specify this behaviour. Sorry for the inconvenience.

1 Like

Hello @pierreguillot,

If I use the flags in run command, docker itself will not start , ES is failing

Error logs :
ERROR: [1] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
2019.11.25 08:14:20 WARN app[o.s.a.p.AbstractManagedProcess] Process exited with exit value [es]: 78
2019.11.25 08:14:20 INFO app[o.s.a.SchedulerImpl] Process[es] is stopped
2019.11.25 08:14:20 INFO app[o.s.a.SchedulerImpl] SonarQube is stopped
2019.11.25 08:14:19 INFO es[o.e.d.DiscoveryModule] using discovery type [zen] and host providers [settings]
2019.11.25 08:14:20 INFO es[o.e.n.Node] initialized
2019.11.25 08:14:20 INFO es[o.e.n.Node] starting …
2019.11.25 08:14:20 INFO es[o.e.t.TransportService] publish_address {127.0.0.1:9001}, bound_addresses {127.0.0.1:9001}
2019.11.25 08:14:20 INFO es[o.e.b.BootstrapChecks] explicitly enforcing bootstrap checks
2019.11.25 08:14:20 ERROR es[o.e.b.Bootstrap] node validation exception
[1] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
2019.11.25 08:14:20 INFO es[o.e.n.Node] stopping …
2019.11.25 08:14:20 INFO es[o.e.n.Node] stopped
2019.11.25 08:14:20 INFO es[o.e.n.Node] closing …
2019.11.25 08:14:20 INFO es[o.e.n.Node] closed

Even this has been updated

sysctl -w vm.max_map_count=262144
sysctl -w fs.file-max=65536
ulimit -n 65536
ulimit -u 4096
sonarqube   -   nofile   65536
sonarqube   -   nproc   65536

And again today I tried to install docker file of Sonarqube of version 8 beta which is given in github : https://github.com/SonarSource/docker-sonarqube/blob/8ae0fadc72fef64334998e811f1b9cf68a458a2c/8/community/Dockerfile

Still this also failing, none of this is not working.

Hello, your logs clearly state the issue : max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535].

Here is the instructions from elasticsearch : https://www.elastic.co/guide/en/elasticsearch/reference/current/file-descriptors.html

Did you put theses settings in the docker host, or in the container ?

is this got solved i am still also facing the same error

so you need to use the -e with the following ones

SONARQUBE_JDBC_USERNAME
SONARQUBE_JDBC_PASSWORD
SONARQUBE_JDBC_URL

at least for older docker images

i know someone posted sonar.jdbc.username and the like but those didnt work for me