You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决PostgreSQL的postgres用户密码认证失败问题?

解决PostgreSQL密码认证失败(FATAL: password authentication failed for user "postgres")
  • 确认配置修改已生效
    修改pg_hba.conf后必须重启PostgreSQL服务,否则新配置不会加载:

    • macOS(EnterpriseDB安装):brew services restart postgresql 或通过EnterpriseDB自带的服务管理工具重启
    • Windows:打开「服务」面板找到PostgreSQL服务,右键选择「重启」
    • Linux:systemctl restart postgresql
  • 重置postgres用户密码(最直接的解决方式)
    如果确认密码输入错误或遗忘,按以下步骤重置:

    1. 停止PostgreSQL服务
    2. 打开pg_hba.conf,将localhost对应的IPv4和IPv6认证行改为trust:
      # IPv4 local connections:
      host    all             all             127.0.0.1/32            trust
      # IPv6 local connections:
      host    all             all             ::1/128                 trust
      
    3. 启动PostgreSQL服务
    4. 终端执行psql -U postgres,无需密码直接登录
    5. 在psql中执行密码修改命令:ALTER USER postgres PASSWORD '你的新密码';
    6. 将pg_hba.conf改回md5认证
    7. 再次重启服务,使用新密码登录
  • 检查IPv6连接的配置匹配
    报错显示连接到localhost (::1)(IPv6地址),需确保pg_hba.conf中IPv6的本地连接行设置为md5,否则会出现认证失败。

  • 验证postgres用户状态
    用trust方式登录后,执行\du查看用户列表,确认postgres用户存在且权限正常。

内容的提问来源于stack exchange,提问作者Mago223

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 05:33:12