连接到“localhost”(127.0.0.1)的服务器,端口 5432 失败:致命:用户“postgres”的身份验证失败

问题描述 投票:0回答:1

我正在尝试在 Django 应用程序中设置 Django PostgreSQL。我为该用户创建了数据库、用户和密码,当我运行

\l
时,我可以看到该数据库。当我使用
python manage.py runserver
运行 django 应用程序时,我收到以下错误消息。

ON PURE START UP
USER TABLE NOT EXIST
connection to server at "localhost" (127.0.0.1), port 5432 failed: could not initiate GSSAPI security context: Unspecified GSS failure.  Minor code may provide more information: Server not found in Kerberos database
connection to server at "localhost" (127.0.0.1), port 5432 failed: FATAL:  Ident authentication failed for user "postgres"

我错过了什么

django postgresql
1个回答
0
投票

类似的错误,但 php 应用程序从 docker 容器连接到本地主机上的 PostgreSQL

FastCGI sent in stderr: "PHP message: PHP Warning:  pg_connect(): Unable to connect to PostgreSQL server: connection to server at "127.0.0.1", port 5432 failed: FATAL:  Ident authentication failed for user

正如@jjanes 在评论中所写

sudo vim /var/lib/pgsql/data/pg_hba.conf

ident
更改为
md5
以进行密码验证

# host          DATABASE  USER  ADDRESS  METHOD  [OPTIONS]

host    all       all        127.0.0.1/32            md5

需要重启

sudo systemctl restart postgresql

© www.soinside.com 2019 - 2024. All rights reserved.