Mac端pgAdmin4用PEM文件注册服务器时遇fe_sendauth无密码错误
解决Mac上pgAdmin4用PEM文件连接PostgreSQL报"fe_sendauth: no password supplied"的问题
核心原因
PostgreSQL的pg_hba.conf配置未允许证书认证,或pgAdmin4的连接设置未正确关联证书文件,导致数据库仍强制要求密码验证。
具体修复步骤
1. 调整PostgreSQL的pg_hba.conf配置
- 找到
pg_hba.conf文件,Mac默认路径一般为/Library/PostgreSQL/<版本号>/data/pg_hba.conf(例如/Library/PostgreSQL/15/data/pg_hba.conf) - 找到对应客户端连接的规则行,将认证方式改为
cert,示例:
本地连接可根据实际情况替换为hostssl all all 0.0.0.0/0 certhost或local - 重启PostgreSQL服务,Mac上可执行命令:
也可通过系统偏好设置里的PostgreSQL图标完成重启sudo brew services restart postgresql
2. 修正pgAdmin4的连接配置
- 在pgAdmin4的服务器注册界面,切换到SSL选项卡
- 将SSL mode勾选为
require或verify-full(按需选择安全等级) - 在Client certificate处选择你的PEM证书文件(支持.pem/.crt格式)
- 在Client certificate key处选择对应私钥文件(若PEM已合并证书与私钥,此处选同一文件即可)
- 确保Password和Password confirmation留空,不要填写任何内容
3. 修复证书文件权限
- 确保PostgreSQL进程能读取你的PEM文件,执行命令调整权限:
替换路径为你实际的证书存储路径chmod 600 /path/to/your/certificate.pem sudo chown postgres:postgres /path/to/your/certificate.pem
4. 检查postgresql.conf的SSL配置
- 打开
postgresql.conf,确保以下配置已开启:ssl = on ssl_cert_file = '/path/to/server.crt' ssl_key_file = '/path/to/server.key' ssl_ca_file = '/path/to/root.crt' # 自签名证书需指定CA文件 - 重启PostgreSQL服务使配置生效
额外提示
若连接的是云服务商的PostgreSQL(如AWS RDS),还需确认:
- 云实例安全组已允许你的Mac IP访问
- 云数据库参数组已开启SSL并允许证书认证
内容的提问来源于stack exchange,提问作者smohan
相关产品推荐
相关产品推荐

