postgresql - 无法连接到 azure PostgreSQL 数据库 - 用户名应采用 <username@hostname> 格式

标签 postgresql azure go

我无法连接到 Golang 应用程序中的 Azure PostgreSQL 数据库

错误消息:

FATAL: Invalid Username specified. Please check the Username and retry connection. The Username should be in <username@hostname> format. (SQLSTATE 28000))

我的用户名中没有@。

我使用 gorm 作为 ORM 并像这样连接

dbUrl := fmt.Sprintf("postgres://%s:%s@%s:5432/%s", dbUser, dbPass, dbHost, dbName)
db, err := gorm.Open(postgres.Open(dbUrl), &gorm.Config{})

我的变量看起来像这样

POSTGRES_PASSWORD="password!"
DB_HOST="some-url-with-dashes.postgres.database.azure.com"
APP_PORT="8080"
POSTGRES_USER="postgresuser"
DB_NAME="file"

我的代码确实看到了它们并正确创建了dbUrl,如下所示:

postgres://postgresuser:passw<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ef809d8bceaf9c80828ac29a9d83c298869b87c28b8e9c878a9cc19f809c9b889d8a9cc18b8e9b8e8d8e9c8ac18e959a9d8ac18c8082" rel="noreferrer noopener nofollow">[email protected]</a>:5432/file

我已尝试更改用户名和密码

最佳答案

您必须配置参数db_user_namespace。不要这样做。

关于postgresql - 无法连接到 azure PostgreSQL 数据库 - 用户名应采用 <username@hostname> 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74477613/

相关文章:

go - 解析 Freebase RDF 时 golang 内存不足

php - 如何确保使用 PHP 的 Postgres 中的 DELETE SQL 语句成功?

postgresql - 如何从外部/应用访问容器化的Postgresql数据库

涉及三张表的Postgresql查询

go - gqlgen - DirectiveResolver 未由生成的包导出

json - 在 golang、JSON 与 gob 中深度复制对象的更快方法

node.js - Node js - Bcrypt - 比较方法为正确的输入密码返回false

c# - 使用 Azure Active Directory 的 Blazor Server 聊天应用程序在 Program.cs 中产生异常

azure - 超过允许的接收器最大数量。连接到 IoT Hub 的 Azure 流分析作业

javascript - 将数据从 html 表单发布到 SQL 不会发布