psql:致命:用户“GuardDog_02”的密码验证失败

Dan*_*one 1 postgresql authentication

在 postgresql 9.5.1 中,我创建了一个名为 GuardDog_02 的用户。我给了它密码。我给了它创建数据库和用户的权限:

CREATE USER GuardDog_02 WITH PASSWORD 'apple100' CREATEDB CREATEUSER;
Run Code Online (Sandbox Code Playgroud)

然后在 GuardDog_02 系统用户(Mac OSX)下:

$ psql -d template1
Password: 
psql: FATAL:  password authentication failed for user "GuardDog_02"
Run Code Online (Sandbox Code Playgroud)

我更新密码只是为了确保我输入正确:

template1=# ALTER USER GuardDog_02 WITH PASSWORD 'apple100';
Run Code Online (Sandbox Code Playgroud)

仍然说密码验证失败。我也检查了 pg_hba.conf 文件:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                md5
#host    replication     postgres        127.0.0.1/32            md5
#host    replication     postgres        ::1/128                 md5
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

Dan*_*ité 5

发出CREATE USER GuardDog_02...创建的确切用户名是 guardgog_02因为 SQL 大小写折叠。您可以\du在 psql 中检查。

但根据该错误消息:

psql:致命:用户“GuardDog_02”的密码验证失败

您尝试登录的用户名是GuardDog_02(大写的 G、D),该用户名不存在此大写

要创建该确切名称,标识符必须用双引号括起来,如下所示:

CREATE USER "GuardDog_02" WITH PASSWORD 'apple100' CREATEDB CREATEUSER;
Run Code Online (Sandbox Code Playgroud)

或者,如果您不想重新创建用户,请使用psql -U guarddog_02.