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

macOS Monterey安装PostgreSQL 14后postgres用户密码验证失败求助

macOS Monterey下PostgreSQL 14密码认证失败的解决办法

核心问题排查

你修改pg_hba.conf后问题没解决,大概率是没修改正确的配置文件,或者修改后没重启服务,按以下步骤逐一处理:

1. 定位正确的pg_hba.conf文件

macOS上PostgreSQL 14的配置文件路径分两种情况:

  • 官方安装包:/Library/PostgreSQL/14/data/pg_hba.conf
  • Homebrew安装:/usr/local/var/postgres/pg_hba.conf

如果不确定路径,用命令查询:

find / -name pg_hba.conf 2>/dev/null

2. 修改配置并强制重启服务

找到正确的pg_hba.conf后,将本地连接的认证方式改为trust(比如local all postgres trust和host all postgres 127.0.0.1/32 trust),保存后必须重启服务:

  • 官方安装包:
    sudo /Library/PostgreSQL/14/bin/pg_ctl restart -D /Library/PostgreSQL/14/data
    
  • Homebrew安装:
    brew services restart postgresql@14
    

3. 重置postgres用户密码

重启后无密码登录PostgreSQL:

psql -U postgres

执行密码重置命令:

ALTER USER postgres WITH PASSWORD '你的新密码';

4. 恢复安全认证方式(可选但推荐)

密码重置完成后,把pg_hba.conf里的trust改回scram-sha-256,再次重启服务,之后用新密码登录即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 20:18:33