LoginSignup
15
10

More than 3 years have passed since last update.

Postgresで発生したエラー「PG::ConnectionBad: 〜"/tmp/.s.PGSQL.5432"?」に対処した

Posted at

発生内容

昨日まで問題なく稼働していた、ローカルのrailsアプリを今日も起動して確認しようと思い、rails server起動後に、画面アクセスしたところ、以下のエラーが発生

PG::ConnectionBad (could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
):
...以下略

こんなエラー見たことない(汗)

環境

  • macOS Catalina 10.15.5
  • postgres (PostgreSQL) 12.2
  • rails 6.0.3.1

問題の特定と対処

とりあえず、postgreのログを確認してみる。


$ postgres -D /usr/local/var/postgres
2020-06-25 09:38:18.176 JST [3469] FATAL:  lock file "postmaster.pid" already exists
2020-06-25 09:38:18.176 JST [3469] HINT:  Is another postmaster (PID 405) running in data directory "/usr/local/var/postgres"?

起動時に作成されるロックファイルがすでに存在していて、エラーになっている模様。
つまり二重起動?おそらく前回起動したpostgresプロセスが正常に停止していないと想像。
(そいえば、昨日の夜macのバッテリーが少ない状態でスリープかけて朝起きたら勝手にシャットダウンしてたのと関係するかも)

こちらの記事を参考にして、postmaster.pidを削除&postgresの再起動をかける

$ rm /usr/local/var/postgres/postmaster.pid
$ brew services restart postgresql

結果、無事に起動できました。

参考記事

PG::ConnectionBad - could not connect to server: Connection refused

15
10
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
15
10