尽管用户名正确,但与 Azure postgres 服务器的连接失败

Connection to Azure postgres server fails in spite of correct username

当尝试从 psql 客户端连接到我在 Azure 中的 postgres 服务器时,我收到以下错误,即使我使用的是正确的用户名。我该如何解决这个问题?

psql:致命:指定的用户名无效。请检查用户名并重试连接。用户名应采用 <username@hostname> 格式。

如错误文本中所述,无论您是从 psql 客户端还是使用 pgadmin,尝试连接到 postgresql 服务器时都需要遵循 <username@hostname> 格式。使用 <username@hostname> 格式而不仅仅是 <username> 应该可以消除错误。

阅读 Azure portal and CLI 的快速入门文档,了解有关如何创建和配置 postgres 服务器的更多信息。

用户名中的 @ 符号适用于对象但不适用于连接字符串。根据 URI RFC-3986,用户名允许十六进制编码。所以用 %40 替换 @。 user@host:pw@fullhost 变成 user%40host:pw@fullhost