【问题标题】:PgAdmin on Ubuntu 20.04 FATAL: password authentication failed for userUbuntu 20.04 FATAL 上的 PgAdmin:用户的密码验证失败
【发布时间】:2021-01-24 23:18:15
【问题描述】:

我在 Ubuntu 20.04 上安装了 Postgres 和 PGAdmin4,但我无法创建服务器并连接到数据库

正如我在几个解决方案中看到的,我在我的 pg_hba.conf 文件中将方法更改为 md5

# Database administrative login by Unix domain socket
local   all             postgres                                md5

# 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
# IPv6 local connections:
host    all             all             ::1/128                 md5

我还连接到 psql,创建新用户,更改密码并通过运行 sudo systemctl restart postgresql 重新启动服务器

                                   List of roles
 Role name |                         Attributes                         | Member of 
-----------+------------------------------------------------------------+-----------
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

有什么想法吗?

【问题讨论】:

  • 在服务器日志文件中查看完整的错误消息。

标签: postgresql pgadmin


【解决方案1】:

运行以下命令:

sudo -i -u postgres

输入你的 sudo 用户密码

psql
ALTER USER postgres PASSWORD 'new_password';
\q
exit

现在更改配置文件以使用此新密码:

sudo subl /etc/postgresql/13/main/pg_hba.conf

subl 表示崇高文本,您可以使用任何其他文本编辑器)。

编辑这部分文件:将 peer 更改为 md5

# Database administrative login by Unix domain socket
local   all             postgres                                peer

# "local" is for Unix domain socket connections only
local   all             all                                     peer

重启 postgres 服务

运行此命令以使用新创建的密码登录 postgres:

psql -U postgres

【讨论】:

  • 嗨,你知道我为什么尝试上述程序吗? (重试大约 5 次并重新启动服务器)。如上所示,在创建密码时将密码放在“ALTER USER ...”的单引号中,但在执行“psql -U postgres”时仍会收到“psql: error: FATAL: password authentication failed for user “postgres”?更新:没关系!我可以通过使用 \password 而不是使用 ALTER USER 设置密码来修复!
【解决方案2】:

sudo -u postgres psql 并设置新密码 postgres=# \密码

解决方案来源: https://www.youtube.com/watch?v=ej08u5xPa64

【讨论】:

  • 请不要发布视频链接。你也可以在这里解释一下!
猜你喜欢
  • 2016-01-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-06
  • 2021-08-04
  • 2021-08-06
相关资源
最近更新 更多