【问题标题】:postgres will not allow alter role superuser and my default user isnt superuserpostgres 将不允许更改角色超级用户,而我的默认用户不是超级用户
【发布时间】:2017-04-29 05:25:00
【问题描述】:

我无法使用 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】:

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 之前。如果您没有此类操作系统用户,则无法使用peer 身份验证连接。因此,要么将 hba_file peer 更改为 trust 以获取无密码,要么将 md5 更改为 postgres 的密码验证不是同一操作系统用户...

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

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

select rolname from pg_roles where rolsuper;

【讨论】:

    猜你喜欢
    • 2012-06-01
    • 2022-11-25
    • 1970-01-01
    • 2021-05-15
    • 2016-01-21
    • 2010-11-27
    • 1970-01-01
    • 2012-08-23
    • 2013-06-23
    相关资源
    最近更新 更多