エラーの発生内容
ActiveRecord :: ConnectionNotEstablished
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"?
やったこと
- PC自体を再起動 → NGだった
-
psql -V
を実行 - バージョンが
psql (PostgreSQL) 14.1
-
brew services list
を実行 - postgresql が error
-
tail -n 20 /usr/local/var/log/postgres.log
を実行
2022-02-04 05:55:21.403 JST [4050] FATAL: database files are incompatible with server
2022-02-04 05:55:21.403 JST [4050] DETAIL: The data directory was initialized by PostgreSQL version 13, which is not compatible with this version 14.1.
2022-02-04 05:55:31.536 JST [4118] FATAL: database files are incompatible with server
以下省略
:
:
:
解決方法
PostgreSQLのメジャーアップデートが原因で,データベースが読めないケースと推察。
以下を順に実行
brew services stop postgresql
==> Successfully stopped `postgresql`
brew upgrade postgresql
Warning: postgresql 14.1_1 already installed
rm -rf /usr/local/var/postgres.old
brew postgresql-upgrade-database
==> Upgrading postgresql data from 13 to 14...
省略
:
:
==> Upgraded postgresql data from 13 to 14!
==> Your postgresql 13 data remains at /usr/local/var/postgres.old
brew services start postgresql
==> Successfully started `postgresql`
brew services list
postgresql started
やっぱり互換性が問題だったみたいですね;;
とにかく解決できてよかったーー。