Bitbucket is unable to connect to PostgreSQL due to unconfigured pg_hba.conf file

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Problem

Scenario #1:

When starting Bitbucket Service, the following is shown on the browser:




Scenario #2:

The following appears in the atlassian-bitbucket.log

The configuration entered is not valid. A database connection could not be established. Please check your configuration and try again.
Hide details
The configuration entered is not valid. A database connection could not be established. Please check your configuration and try again.
com.atlassian.stash.internal.db.DefaultDatabaseManager.validateConfiguration(DefaultDatabaseManager.java:217)
com.atlassian.stash.internal.migration.DefaultMigrationService.validateConfiguration(DefaultMigrationService.java:85)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...
Could not get JDBC Connection; nested exception is org.postgresql.util.PSQLException: FATAL: no pg_hba.conf entry for host "192.168.10.5", user "stashdbuser", database "stashdb", SSL off
org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
com.atlassian.stash.internal.db.DefaultDatabaseValidator.validate(DefaultDatabaseValidator.java:44)
com.atlassian.stash.internal.db.DefaultDatabaseManager.validateConfiguration(DefaultDatabaseManager.java:214)
...
FATAL: no pg_hba.conf entry for host "192.168.10.5", user "stashdbuser", database "stashdb", SSL off
org.postgresql.Driver$ConnectThread.getResult(Driver.java:358)
org.postgresql.Driver.connect(Driver.java:282)
java.sql.DriverManager.getConnection(DriverManager.java:664)


Cause

PostgreSQL has a list of allowed IP (configured in pg_hba.conf) that allow access to the database server. There is a missing entry for the host. For more information on Postgres configuration file details:

http://www.postgresql.org/docs/9.2/static/auth-pg-hba-conf.html

Resolution

Add the IP address of the Bitbucket server to the pg_hba.conf and make sure that the method is not set to reject. You need to modify the xxx.xxx.xxx.xxx and put the IP address to allow connections. Edit the [pg_hba.conf|https://www.postgresql.org/docs/devel/auth-pg-hba-conf.html] file and add an entry to the Bitbucket server IP:


# TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD
 
# IPv4 local connections:
host    all         all         127.0.0.1/32          md5
host    all  	    all  		xxx.xxx.xxx.xxx       md5
# IPv6 local connections:
host    all         all         ::1/128               md5
Description
Product
Last modified on Apr 30, 2019

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.