【问题标题】:Postgres cluster: password authentication failed for user “postgres”Postgres 集群:用户“postgres”的密码验证失败
【发布时间】:2015-11-23 11:36:12
【问题描述】:

在我的 Postgres 服务器中,使用 pg_createcluster 命令在端口 5433 上创建了一个集群。要为用户 postgres 设置密码,我按照以下步骤操作:

  1. 编辑文件 nano /etc/postgresql/9.3//pg_hba.conf

换行

托管所有 127.0.0.1/32 md5

按行

托管所有 127.0.0.1/32 信任

  1. 使用以下命令更改密码

sudo -u postgres psql -h localhost -p 5433

postgres = #\密码postgres

输入新密码:

再次输入:

postgres = #\q

  1. 编辑文件 nano /etc/postgresql/9.3//pg_hba.conf

换行

托管所有 127.0.0.1/32 信任

按行

托管所有 127.0.0.1/32 md5

显示没有错误,但连接控制台和从 pgadmin3 触发错误:用户“postgres”的密码验证失败。默认情况下(主)在实例中使用相同的进程,我可以成功连接。

感谢您的帮助,因为我没有找到太多可用于 Postgres 实例的文档。 提前致谢。

【问题讨论】:

    标签: postgresql postgresql-9.3 multiple-instances change-password


    【解决方案1】:

    首先,您需要重新加载配置,以便应用您的所有更改。连接端口可能未打开,此外您还没有明确共享local 连接的配置。这应该可以正常工作:

    # TYPE  DATABASE        USER            ADDRESS                 METHOD
    
    # "local" is for Unix domain socket connections only
    local   all             all                                     trust
    # IPv4 local connections:
    host    all             all             127.0.0.1/32            md5
    

    【讨论】:

      【解决方案2】:

      感谢您的回复。我已经在 pg_hba.conf 中配置了你的响应:

      # TYPE  DATABASE        USER            ADDRESS                 METHOD
      # "local" is for Unix domain socket connections only
      local   all             all                                     trust
      # IPv4 local connections:
      host    all             all             127.0.0.1/32            md5
      

      修改密码:

      # nano /etc/postgresql/9.3/<instance_name>/pg_hba.conf
      # /etc/init.d/postgresql restart
      # su - postgres
      $ psql -U postgres -p 5433 -h localhost
      Password for user postgres:
      

      认证服务器提示我输入psql。下面的配置是让我不用密码就可以进入psql:

      # TYPE  DATABASE        USER            ADDRESS                 METHOD
      # "local" is for Unix domain socket connections only
      local   all             all                                     trust
      # IPv4 local connections:
      host    all             all             127.0.0.1/32            trust
      

      修改密码:

      # nano /etc/postgresql/9.3/<instance_name>/pg_hba.conf
      # /etc/init.d/postgresql restart
      # su - postgres
      $ psql -U postgres -p 5433 -h localhost
      postgres=# \password postgres
      Enter new password:
      Enter it again:
      postgres=# \q
      $ exit
      # nano /etc/postgresql/9.3/<instance_name>/pg_hba.conf
      # /etc/init.d/postgresql restart
      

      更改设置并再次进入psql:

      # 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
      
      
      # su - postgres
      $ psql -U postgres -p 5433 -h localhost
      Password for user postgres:
      psql: FATAL:  password authentication failed for user "postgres"
      FATAL:  password authentication failed for user "postgres"
      

      【讨论】:

      • 遇到同样的问题,找到解决办法了吗?
      猜你喜欢
      • 2011-12-03
      • 1970-01-01
      • 2020-12-09
      • 2020-09-21
      • 2023-04-05
      • 1970-01-01
      • 2020-10-13
      相关资源
      最近更新 更多