postgres不允许alter role superuser和我的默认用户不是超级用户

问题描述 投票:0回答:1

我无法使用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中为用户提供超级用户?

postgresql elixir phoenix-framework psql pg-hba.conf
1个回答
2
投票

psql: FATAL: Peer authentication failed for user "thisone"和其他用户的相同错误意味着,你尝试使用不同的os用户连接套接字(例如,os用户是cchilders,你尝试psql -U postgres),而peer means you have to be logged in same OS user。例如,要在psql -U thisone成功,你应该在sudo su - thisone之前。如果你没有这样的OS用户,你就无法连接peer身份验证。因此要么将hba_file peer更改为trust进行无密码,要么将md5更改为密码身份验证,以使postgres不是同一个os用户...

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

最后,您列出了用户,而不是检查他们是否是超级用户。你应该使用\du metacommand和psql, or addrolsuper`列,所以它将是:

select rolname from pg_roles where rolsuper;
© www.soinside.com 2019 - 2024. All rights reserved.