连接Azure Postgres时服务器意外关闭连接。

7

我正在尝试使用本地机器上的psql连接到Azure Postgresql,但是出现以下错误:

$ psql "host=username.postgres.database.azure.com port=5432 dbname=postgres user=username@domain password=mypassword sslmode=require"
psql: error: could not connect to server: server closed the connection unexpectedly
    This probably means the server terminated abnormally
    before or while processing the request.

本地Postgres版本:12.1,Azure Postgres数据库版本:10,macOS Mojave。

在重新使用Homebrew安装Postgres之后,这个问题最近才开始出现。我运行$ psql --host=localhost没有问题。

我尝试使用Homebrew安装postgresql@10,以便当我运行psql时,我会收到消息psql (12.1, server 10.11)。但是,当我尝试登录Azure Postgres时,我收到与上面相同的错误。

我对Postgres和Azure相当新,希望能得到任何建议。

更新:

感谢评论和反馈。

我使用Homebrew正确安装了Postgres 10并进行了链接,以解决问题。

$ brew services stop postgresql
$ brew install postgresql@10
$ brew services start postgresql@10
$ brew link --overwrite --force postgresql@10

我现在可以如预期地访问 Azure 数据库。


你尝试过重试逻辑吗? - Thiago Custodio
尝试使用Homebrew安装macOS的PostgreSQL客户端,可以参考这里 - Nancy Xiong
1
我遇到了你现在遇到的相同问题。我可以使用GUI客户端连接到数据库,但无法使用psql连接。 - tony.0919
1个回答

5
在这种情况下,您可以使用Homebrew在macOS上正确安装PostgreSQL客户端,然后将其链接,因为它将所有工具都符号链接到/usr/local/bin目录中。
要解决此问题,请运行以下命令:
$ brew services stop postgresql
$ brew install postgresql@10
$ brew services start postgresql@10
$ brew link --overwrite --force postgresql@10

引用:https://www.compose.com/articles/postgresql-tips-installing-the-postgresql-client/

本文将教您如何在Windows、Linux和Mac上安装PostgreSQL客户端。在这里,我们提供了针对不同操作系统的具体步骤以及相关提示和技巧。无论您是正在使用哪种操作系统,本文都将为您提供所需的说明,帮助您轻松地安装并使用PostgreSQL客户端。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接