使用最新版本的 Postgresql psql 客户端工具时无法连接到 Postgres 服务器

Cannot connect to Postgres server when using latest version of Postgresql psql client tool

当我通过 brew 安装了最新版本的 Postgresql(版本 12)并尝试使用 zsh shell 中的 psql 查询云托管数据库时,我收到以下错误:psql: error: could not connect to server: 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"?

当我使用postgresql version 11时,可以查询数据库

我团队中的其他开发人员可以使用最新版本的 Postgresql(版本 12)查询同一数据库。

有什么问题吗?

听起来您使用 v12 和 v11 进行连接的方式不同(不同 shell、不同的主机、不同的安装方法等等?)但不知道完整的连接命令 and/or 环境信息,这将很难排除故障。由于您的同事可以使用 v12 进行连接,因此这不是问题。由于您确实需要更多的支持论坛,我可能会建议将这个问题提交给 postgres slack 或 postgres 邮件列表。

我通过卸载所有 brew 软件包、卸载 brew、重新安装 brew 然后重新安装所有软件包(包括 postgresql 版本 12)解决了连接问题。之后,我可以连接到数据库。