【Postgresエラー対応】psql: error: could not connect to server: could not connect to server:

こんばんは。

 

久しぶりにpostgresを叩き起こそうかと思ったら、見事以下のエラー文句を吐き出されました。。。

f:id:TMLabo:20200128233125p:plain

エラー内容はこちら。

psql: error: could not connect to server: 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"?

 

macのアプリケーション > ユーティリティ > コンソール.app にて、

システムログを確認すると、、、

(homebrew.mxcl.postgresql[64520]): Service exited with abnormal code: 1

と延々と出力。

 

対応1→結果NG

postmaster.pidを削除してサービスを再起動する


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

 

対応2→結果OK

こちらを参考にしました。

https://qiita.com/akito19/items/409f06c61b5b8dc0ebaa

https://techracho.bpsinc.jp/hachi8833/2017_12_21/48661

 

再インストール→ディレクトリ初期化


//PostgreSQLを再インストール
$ brew uninstall postgresql
$ brew install postgresql

//元々のPostgreSQLディレクトリを削除し、初期化
$ rm -rf /usr/local/var/postgres && initdb /usr/local/var/postgres -E utf8

 

f:id:TMLabo:20200128234627p:plain

初期化後
//最後にDBに入る
$ psql postgres

 

やっとテーブル作れます。