【Postgres】安装错误处理|ConnectionBad:无法连接到服务器:没有这个文件或目录
為了將PostgreSQL引入到rails中,執行$ brew install postgresql安裝並通過$ postgres –version確認安裝正確。然而,當輸入postgres命令時,會出現以下錯誤。
$psal
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"?
据说无法连接到服务器。可以确认Postgres的路径和版本,但是依然无法连接。。。
#パスの確認
$ which postgres
/usr/local/bin/postgres
#バージョンの確認
$ postgres --version
postgres (PostgreSQL) 13.2
解决方法
需要在Mac上直接安装PostgreSQL。
前往PostgreSQL官方网站的下载页面。
https://www.postgresql.org/download/macosx/

点击下载安装程序。
https://www.enterprisedb.com/downloads/postgres-postgresql-downloads

点击适用的操作系统和想要安装的版本。在这里选择最新的Mac版本(13.2)。
当下载完成后,请双击安装程序。



选择保存位置。一般来说,默认选项即可。


输入超级用户(postgres,root用户)的密码。

请输入端口号。默认为5432。

请选择语言。

请确认之前的设定内容,如果没有问题,就进行下一步。


开始安装。


以上是PostgreSQL安装完成。
是否要启动一个名为Stack Builder的附加工具的PostgreSQL安装向导?
只要取消勾选并完成,就可以随时追加。
PostgreSQL自身的安装已经完成。
启动Postgres
使用psql -U postgres命令以root用户身份启动交互模式。
$ psql -U postgres
Password for user postgres:
psql (13.2)
Type "help" for help.
postgres=#
没有错误发生。终于进入了对话模式。