简体   繁体   English

由没有密码的用户连接到 Postgres DB

[英]Connect to Postgres DB by a user which has no password

I created a user by:我通过以下方式创建了一个用户:

sudo -u postgres psql -c "CREATE USER sample;"

Then created a database:然后创建了一个数据库:

sudo -u postgres psql -c "CREATE DATABASE practice OWNER sample;"

Now I'm trying to connect to this DB by following snippet:现在我正在尝试通过以下代码段连接到该数据库:

dsn := url.URL{
        User:     url.UserPassword("sample", ""),
        Scheme:   "postgres",
        Host:     fmt.Sprintf("%s", "localhost"),
        Path:     "practice",
        RawQuery: (&url.Values{"sslmode": []string{"disable"}}).Encode(),
}
db, err := gorm.Open(
        "postgres",
        dsn.String(),
)
if err != nil {
        log.Fatal(err)
}

But the output is:但是 output 是:

2020/07/07 16:43:44 pq: password authentication failed for user "sample"

How do I connect to DB with a user which has no password?如何使用没有密码的用户连接到数据库?

Either assign the user a password and then use it, or change your pg_hba.conf file so that some other method of authentication is used for that user/dbname/connection-method/host (and then restart your server so the change takes effect).给用户分配一个密码然后使用它,或者更改您的 pg_hba.conf 文件,以便对该用户/dbname/connection-method/host 使用其他一些身份验证方法(然后重新启动您的服务器以使更改生效) .

sudo -u postgres psql -c "ALTER USER sample password 'yahkeixuom5R';"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Docker postgress用户“ postgres”未分配密码 - Docker postgress User “postgres” has no password assigned 用户“postgres”的密码验证失败,用户“postrgres”没有密码 - password authentication failed for user "postgres" and user 'postrgres' has no password Google Cloud SQL[postgres] - db=postgres,user=postgres 致命:用户“postgres”的密码身份验证失败 - Google Cloud SQL[postgres] - db=postgres,user=postgres FATAL: password authentication failed for user "postgres" Postgres docker “用户“postgres”没有分配密码。” - Postgres docker "User "postgres" has no password assigned." GCP 日志导出器报告错误:db=postgres,user=postgres 致命:用户“postgres”的密码验证失败 - GCP Logs Exporter is reporting error: db=postgres,user=postgres FATAL: password authentication failed for user "postgres" Postgresql用户“ postgres”需要密码才能创建数据库 - Postgresql user “postgres” requires password in order to create db psql无法连接到服务器,用户postgres的密码认证失败 - Psql can not connect to server, password authentication failed for user postgres postgres 密码错误:请输入用户 'postgres' 的密码以连接服务器 - “PostgreSQL 13” - postgres password error : Please enter the password for the user 'postgres' to connect the server - "PostgreSQL 13" 无法连接到postgres(用户密码验证失败-docker) - Cant connect to postgres (password authentication failed for user - docker) 忘记了我的postgres用户密码以连接服务器 - Can't remember my postgres user password to connect server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM