我无法连接到 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/