LoginSignup
0
0

More than 3 years have passed since last update.

【EC2・Rails】unicorn.logのエラーIs the server running on host "3.114.69.77" and accepting TCP/IP connections on port 5432? (PG::ConnectionBad)の解決法

Last updated at Posted at 2020-05-29

デプロイをしている最中のエラー。
Postgresqlを使っています。

unicorn.logの結果は下記の通り。

Is the server running on host "3.114.69.77" and accepting
    TCP/IP connections on port 5432?
 (PG::ConnectionBad)

原因はいくつかある。

Ec2内のデータベースにアクセスできる権限がない。

アプリディレクトリでpsql -lと打って下記のように表示されれば、権限がない可能性があります。

スクリーンショット 2020-05-26 12.10.1610.png

\lで確認しても権限がない。
portfolioの部分にアクセス権が書いていない。

スクリーンショット 2020-05-26 12.34.5234.png

したがって下記のコマンドで権限を追加します。

$  su - postgres  #管理者権限でDBに入る。

$  psql postgres

$  psql -U postgres -d postgres #postgresユーザで入る。

$  su postgres

$  psql -l

$  GRANT ALL PRIVILEGES ON DATABASE portfolio to postgres;  #これで権限を追加できる。

スクリーンショット 2020-05-26 18.51.4451.png

しかしunicorn.logのエラー文は変わらず。

database.ymlの本番環境のhost名はlocalhostかIPを指定する。

database.ymlの本番環境のhost名でlocalhostかIPを指定することによって解決。

以下のようなルールがあるとのこと。

production環境の host名をdbにするのは、dockerを使って内部ネットワークを利用するときに使用する。

そうでない場合は、host名は、dbのホスト名かIPを指定する。

同じサーバー内で動かすのであれば、localhostでも良い。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0