Bitbucket fails to connect to PostgreSQL Server with a "Connection refused" error
プラットフォームについて: サーバーと Data Center のみ。この記事は、サーバーおよび Data Center プラットフォームのアトラシアン製品にのみ適用されます。
Restarting Bitbucket results in PostgreSQL database connectivity issue. The error seen in the web interface is:
The database, as currently configured, is not accessible. Connection to <hostname>:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
The following appears in the
atlassian-bitbucket.log file, indicating a connection refused when using Bitbucket with JDBC direct connection string:
org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
- Bitbucket Server/DC
- PostgreSQL database
Here are some quick and handy diagnostic scripts:
This command should list the PostgreSQL processes in your environment:
ps -f -u postgres
This command will show the TCP/IP addresses and ports that your instance of PostgreSQL is listening upon.
sudo lsof -n -u postgres |grep LISTEN or sudo netstat -ltnp | grep postgres
This is a misconfiguration issue with PostgreSQL, not Bitbucket, the root cause being that the PostgreSQL
/var/lib/pgsql/data/pg_hba.conf file is set to
IDENT instead of
TRUST connections, even from localhost, as shown below:
# TYPE DATABASE USER CIDR-ADDRESS METHOD # "local" is for Unix domain socket connections only local all all ident # IPv4 local connections: host all all 127.0.0.1/32 ident host all all 100.200.300.50/32 ident # IPv6 local connections: host all all ::1/128 ident
IP address range 100.200.300.50/32 is only used herein for purposes of example, please do not use that address.
- Open the file
/var/lib/psql/pg_hba.confin a text editor with appropriate read/write permissions
- You may have to use
sudoto obtain the correct permissions to edit and save the file as needed
Edit the file, switching the values written as
TRUST, as shown below:
# TYPE DATABASE USER CIDR-ADDRESS METHOD # "local" is for Unix domain socket connections only local all all trust # IPv4 local connections: host all all 127.0.0.1/32 trust host all all 100.200.300.50/32 trust # IPv6 local connections: host all all ::1/128 ident
- Save the changes made into
- Restart PostgreSQL service
- Restart Bitbucket