Bitbucket is unable to connect to PostgreSQL due to unconfigured pg_hba.conf file
プラットフォームについて: Server および Data Center のみ。この記事は、Server および Data Center プラットフォームのアトラシアン製品にのみ適用されます。
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.
*Fisheye および Crucible は除く
問題
Scenario #1:
When starting Bitbucket Service, the following is shown on the browser:
Scenario #2:
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)
原因
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
ソリューション
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