Wednesday, June 3, 2015

PostgreSQL error: no pg_hba.conf entry for host

I’m currently integrating SonarQube in our Build pipeline. During the process I stumbled over some issues. One issue I got was related to PostgreSQL that we were using as our database for SonarQube.

Everything worked nicely from the SonarQube web portal, but when I tried to execute the SonarQube Runner on our build server, it failed with the following PostgreSQL error:

connect to PostgreSQL server: FATAL: no pg_hba.conf entry for host

I’m not an expert in PostgreSQL, so with the help of a google search I discovered that the pg_hba.conf file is used to configure the security of your PostgreSQL database. By default only local connections are allowed. So it is not possible to connect to the PostgreSQL database from outside the server it is running on. As I had SonarQube running on the same server as my database, it worked for the SonarQube web portal. However my build server was a different machine(even in a different datacenter) and couldn’t reach the PostgreSQL database.

To fix it, you have to update the pg_hba.conf file in your PostgreSQL installation directory. I added the following line to the file just below the # TYPE DATABASE USER CIDR-ADDRESS METHOD header:

host all all md5

Warning: Note that this line will give everyone(with a correct username and password) access to your PostgreSQL instance. It is recommended to limit the attack surface by specifying a more restrictive set of allowed IP addresses.

No comments: