【问题标题】:Psql can not connect to server, password authentication failed for user postgrespsql 无法连接到服务器,用户 postgres 的密码验证失败
【发布时间】:2020-03-15 11:11:16
【问题描述】:

我知道这个问题以前被问过很多次,但其他答案都没有帮助。我尝试更改 pg_hba.conf。我尝试使用sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';" 更改postgres 的密码。但要做到这一点,我需要用户 postgres 的密码。我尝试使用sudo passwd postgres 更改postgres 的密码。它仍然无法进行身份验证。当被要求输入密码时,我尝试使用自己的密码,但身份验证失败。

我使用的是 PostgreSQL 12.2

pg_hba.conf

sudo -u postgres psql

【问题讨论】:

  • 更改pg_hba.conf后是否重启了数据库?您是否查看了服务器的日志文件以了解它的内容?

标签: postgresql


【解决方案1】:

我通过在 postgres 使用的端口(端口:5432)上查找活动进程来修复此错误。一旦这些进程被杀死,postgres 就会工作。

所以..

  1. lsof -i :5432 打印任何可能正在运行的当前进程及其 PID
  2. kill -9 <PID> 杀死进程。
  3. initdb testdb 测试

注意:为 postgres 运行 GUI 将占用这些进程并重新启动它们,即使您在某个 PID 上终止进程也是如此。关闭所有 giu。

如果这不起作用,我建议检查启动守护进程

  1. sudo launchctl list | fgrep postgres 打印出守护进程
  2. sudo launchctl stop <printed process name>
  3. initdb testdb 测试

【讨论】:

    猜你喜欢
    • 2021-07-03
    • 1970-01-01
    • 2020-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-15
    • 2011-12-03
    相关资源
    最近更新 更多