0

我无法使用 elixir 连接到 postgres:

** (Mix) The database for PhoenixChat.Repo couldn't be created: FATAL 28P01 (invalid_password): password authentication failed for user "postgres"

00:08:59.053 [error] GenServer #PID<0.3214.0> terminating
** (Postgrex.Error) FATAL 28P01 (invalid_password): password authentication failed for user "postgres"
    (db_connection) lib/db_connection/connection.ex:148: DBConnection.Connection.connect/2
    (connection) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol

我无法理解数据库如何允许在没有超级用户的情况下创建用户。从我的普通用户那里,它不允许赋予超级用户角色:

$ psql -U thisone --password
Password for user thisone: 
psql: FATAL:  Peer authentication failed for user "thisone"

$ psql -U fakeuser
psql: FATAL:  Peer authentication failed for user "fakeuser"

cchilders=> alter user postgres superuser;
ERROR:  must be superuser to alter superusers
cchilders=> select rolname from pg_roles;
  rolname  
-----------
 postgres
 cchilders
 fakeuser
 thisone
(4 rows)

$ psql -U postgres --password
Password for user postgres: 
psql: FATAL:  Peer authentication failed for user "postgres"

如果没有超级用户,如何在 postgres 中给用户超级用户?

4

1 回答 1

2

psql: FATAL: Peer authentication failed for user "thisone"对于其他用户来说同样的错误意味着,您尝试使用不同的操作系统用户连接套接字(例如,操作系统用户是cchilders并且您尝试psql -U postgres),而peer意味着您必须以相同的操作系统用户登录。例如,要想成功就psql -U thisone应该在你之前sudo su - thisone。如果您没有此类操作系统用户,则无法连接peer身份验证。因此,要么将hba_file peer更改trust为无密码,要么md5将密码身份验证更改为 postgres 不是同一个操作系统用户...

因为你sudo -u postgres psql工作了,因为你有操作系统用户 postgres (例如,osx 不是这种情况)..

最后,您列出用户,而不是检查他们是否是超级用户。您应该使用\du带有psql, or addrolsuper` 列的元命令,所以它将是:

select rolname from pg_roles where rolsuper;
于 2017-04-29T08:31:47.660 回答