MacOS 上brew安装的PostgreSQL有时候就报

psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory 	Is the server running locally and accepting connections on that socket?

重启也没能解决,后来找了以后,找到原因了。

postmaster.pid already exists

上一次异常退出,pid 文件没清。 清理办法:

rm -f /opt/homebrew/var/postgresql@17/postmaster.pid

后面启动就行

brew services restart postgresql@17

就是一次问题的记录,希望对你有帮助!