0
0

More than 3 years have passed since last update.

ActiveRecord::ConnectionNotEstablishedの解決方法

Posted at

下記のようなエラー文が出たので、一つづつ紐解いて対処していく。

ActiveRecord::ConnectionNotEstablished (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"?

ActiveRecord::ConnectionNotEstablished

dbとの接続がうまくいっていないという意味らしい。

Is the server running locally

local環境でサーバーは動いているか

and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

もしくはUnixドメインソケットの.s.PGSQL.5432に繋がっているか?

環境

  • macOS Big Sur 11.5.2
  • MacBook Pro (Retina, 13-inch, Early 2015)
  • postgres (PostgreSQL) 13.3
  • rails 6.1.4

問題の場所と対処


データベースが正常に起動しているのかを確認するために、postgresqlの状態を確認してみる

$ postgres -D /usr/local/var/postgres
2021-08-21 10:57:07.740 JST [41676] FATAL:  lock file "postmaster.pid" already exists
2021-08-21 10:57:07.740 JST [41676] HINT:  Is another postmaster (PID 1188) running in data directory "/usr/local/var/postgres"?

FATALを紐解いてみる。どうやら起動時に作成されるロックファイルがすでに存在していて、エラーになっている模様。

前回の起動情報をkillしないと新しく起動できなくなるみたいだ。

postmaster.pidを削除&postgresの再起動をかけると治ると記事に書いてあるので、下記コマンドを入力する。

$ rm /usr/local/var/postgres/postmaster.pid
$ brew services restart postgresql
Stopping `postgresql`... (might take a while)
==> Successfully stopped `postgresql` (label: homebrew.mxcl.postgre
==> Successfully started `postgresql` (label: homebrew.mxcl.postgre

すると、無事再起動できました!!

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

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

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