无法连接到 Azure PostresSQL 数据库 – 用户名应该采用 格式。

huangapple go评论81阅读模式
英文:

Cannot connect to azure PostresSQL database - The Username should be in <username@hostname> format

问题

我无法连接到 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:password!@some-url-with-dashes.postgres.database.azure.com:5432/file

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

英文:

I cannot connect to an Azure PostgreSQL database in a Golang application

Error message :

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

I do not have an @ in my username.

I am using gorm as a ORM and connecting like this

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

My variables look like this

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

My code does see them and correctly creates dbUrl like :

postgres://postgresuser:password!@some-url-with-dashes.postgres.database.azure.com:5432/file

I have tried changing the username and password

答案1

得分: 1

你必须将参数db_user_namespace配置为on。不要这样做。

英文:

You must have configured the parameter db_user_namespace to on. Don't do that.

huangapple
  • 本文由 发表于 2022年11月17日 23:01:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/74477613.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定