【错误】Postgres PG::ConnectionBad: 无法连接到服务器: 没有该文件或目录。服务器在本地运行并且是否接受在Unix域套接字”/tmp/.s.PGSQL.5432″上的连接?【Rails】

スクリーンショット 2020-11-22 午前8.59.59.png

我做过的事情 (Wǒ de

暫時參考https://qiita.com/great084/items/98c83364f246473249c4。
可是問題並未解決。

postgres -D /usr/local/var/postgres 
2020-11-21 23:37:47.476 AEDT [84006] FATAL:  database files are incompatible with server
2020-11-21 23:37:47.476 AEDT [84006] DETAIL:  The data directory was initialized by PostgreSQL version 12, which is not compatible with this version 13.1.

提升 PostgreSQL 的版本可能可以解决该问题,所以我会尝试进行升级。

brew postgresql-upgrade-database
Error: Upgrading postgresql data from 12 to 13 failed!
==> Removing empty postgresql initdb database...
==> Moving postgresql data back from /usr/local/var/postgres.old to /usr/local/v
Error: Failure while executing; `/usr/local/opt/postgresql/bin/pg_upgrade -r -b /usr/local/Cellar/postgresql@12/12.5/bin -B /usr/local/opt/postgresql/bin -d /usr/local/var/postgres.old -D /usr/local/var/postgres -j 4` exited with 1.

为什么无法升级版本的错误。
因此,回想起之前出现postgresql相关错误时所采取的措施,运行brew doctor。

Warning: Git could not be found in your PATH.
Homebrew uses Git for several internal functions, and some formulae use Git
checkouts instead of stable tarballs. You may want to install Git:
  brew install git

Warning: No developer tools installed.
Install the Command Line Tools:
  xcode-select --install


Warning: Your Xcode does not support macOS 10.15.
It is either outdated or was modified.
Please update your Xcode or delete it if no updates are available.

Warning: Xcode alone is not sufficient on Catalina.
Install the Command Line Tools:
  xcode-select --install

解决掉被检测到的问题,然后再尝试升级postgresql版本。

brew postgresql-upgrade-database
~~(省略)~~
==> Upgraded postgresql data from 12 to 13!
==> Your postgresql 12 data remains at /usr/local/var/postgres.old

升级版本非常顺利,服务器也顺利启动而没有出现错误!