RailsコマンドでPostgreSQLのエラー出た時の対処法

Rails newしてDB作成しようとしたらエラー発生。

$ bin/rails db:create
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+homebrew+postgres で接続エラー「PG::ConnectionBad: 〜"/tmp/.s.PGSQL.5432"?」を解決 - Qiita

brew services restart postgresql
PostgreSQLを再起動すればOKという記事もあるが、エラー解消せず、、

postgres -D /usr/local/var/postgresでエラーの詳細を調べる。 オプション補足:-D DATADIR database directory

2019-07-22 20:00:50.239 JST [21618] FATAL:  database files are incompatible with server
2019-07-22 20:00:50.239 JST [21618] DETAIL:  The data directory was initialized by PostgreSQL version 10, which is not compatible with this version 11.4.

data directoryのバージョンがまずいとのことなので、バージョンアップしたら解消しました! brew postgresql-upgrade-database