Bitbucket fails to connect to PostgreSQL Server with a "Connection refused" error

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

プラットフォームについて: 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 は除く

要約

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.

Caused by: org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
at org.postgresql.Driver$ConnectThread.getResult(Driver.java:385)
at org.postgresql.Driver.connect(Driver.java:298)
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138)
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364)
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206)
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476)
at com.zaxxer.hikari.pool.HikariPool.access$100(HikariPool.java:71)
at com.zaxxer.hikari.pool.HikariPool$PoolEntryCreator.call(HikariPool.java:726)
at com.zaxxer.hikari.pool.HikariPool$PoolEntryCreator.call(HikariPool.java:712)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
... 2 common frames omitted
Caused by: java.net.ConnectException: Network is unreachable (connect failed)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:607)

環境

  • 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.

ソリューション

  1. Open the file /var/lib/psql/pg_hba.conf in a text editor with appropriate read/write permissions
  2. You may have to use sudo  to obtain the correct permissions to edit and save the file as needed
  3. Edit the file, switching the values written as IDENT to 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
    
  4. Save the changes made into  /var/lib/psql/pg_hba.conf
  5. Restart PostgreSQL service
  6. Restart Bitbucket

最終更新日 2024 年 4 月 3 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.