概要
- 下記エラーを解消したい
psql: error: connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused Is the server running on that host and accepting TCP/IP connections?
環境
- Ubuntu 18.04.6 LTS
- Postgresqlのパスワードは設定済み
- create databaseも実行済み
ファイル修正
postgresql.confを探す
find / -name postgresql.conf 2> /dev/null
以下に変更
# - Connection Settings -
# listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
リスタートする
sudo service postgresql restart
こちらのファイルも変更する
/etc/postgresql/14/main/pg_hba.conf
開くとこのようになっているので、
# IPv4 local connections:
host all all 127.0.0.1/32 scram-sha-256
以下のように変更
# IPv4 local connections:
host all all 0.0.0.0/0 scram-sha-256
リスタートする
sudo service postgresql restart
再度接続
psql -h localhost -U postgres -W test
psql (14.8 (Ubuntu 14.8-1.pgdg18.04+1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.
test=#
できた!