postgresql Django - (OperationalError) 致命:用户“用户名”的身份验证失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11339917/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 00:03:51  来源:igfitidea点击:

Django - (OperationalError) FATAL: Ident authentication failed for user "username"

pythondjangopostgresqlsqlalchemy

提问by limlim

I've written a simple sqlalchemy-django model, according to this manual: http://lethain.com/replacing-django-s-orm-with-sqlalchemy/, which worked for me pretty well.
My Django is connected to a remote postgresql database, with this settings:

我根据本手册编写了一个简单的 sqlalchemy-django 模型:http: //lethain.com/replacing-django-s-orm-with-sqlalchemy/,它对我来说效果很好。
我的 Django 连接到远程 postgresql 数据库,使用以下设置:

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
    'NAME': 'wetlab_dev',                               # Or path to database file if using sqlite3.
    'USER': 'limlim',                                 # Not used with sqlite3.
    'PASSWORD': '',                                     # Not used with sqlite3.
    'HOST': 'cab-27',                                   # Set to empty string for localhost. Not used with sqlite3.
    'PORT': '',                                         # Set to empty string for default. Not used with sqlite3.
    }
}

It worked for me a few days ago, but now when I try to load the 'homepage' again, it shows me the following error message:

几天前它对我有用,但是现在当我再次尝试加载“主页”时,它显示以下错误消息:

(OperationalError) FATAL:  Ident authentication failed for user "limlim"    

The sqlalchemy engine-configuration is:

sqlalchemy 引擎配置是:

CONNECTION_STR = 'postgresql://limlim:@cab-27/wetlab_dev'

engine = sqlalchemy.create_engine(CONNECTION_STR)   

It seems like I haven't changed anything that is related to the database configurations, but still I get this error message.
Also, when I try to connect to the database on the remote server with my username, I succeed doing it, so I guess it's not a problem of permissions for my username to get to this database.

似乎我没有更改与数据库配置相关的任何内容,但仍然收到此错误消息。
另外,当我尝试使用我的用户名连接到远程服务器上的数据库时,我成功了,所以我想这不是我的用户名访问该数据库的权限问题。

What can be done to overcome this error?

可以做些什么来克服这个错误?

回答by Craig Ringer

Your pg_hba.confis configured to use 'ident' authentication for connections from localhost (127.0.0.1). You need it to be changed to md5for your database and user combination.

pg_hba.conf已配置为对来自 localhost (127.0.0.1) 的连接使用“ident”身份验证。您需要将其更改md5为您的数据库和用户组合。