简体   繁体   English

无法使用Django连接到本地Postgresql服务器

[英]Unable to connect to local Postgresql server using django

I'm getting the following error when I try to connect to my postgresql server locally from the same ec2 instance as the postgresql server: 当我尝试从与Postgresql服务器相同的ec2实例本地连接到我的postgresql服务器时,出现以下错误:

django.db.utils.OperationalError: FATAL:  Ident authentication failed for user "django"

I checked my pg_hba.conf to make sure it allowed local connections: 我检查了pg_hba.conf以确保它允许本地连接:

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust

My settings.py has the following settings: 我的settings.py具有以下设置:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'famtest',
        'USER': 'django',
        'PASSWORD': '',
        'HOST': 'localhost',
        'PORT': '5432',
    }
}

These settings work when I run the project on my machine(I change 'localhost' to the ip address) but not when I try to run the project from the same ec2 instance. 这些设置在我在计算机上运行项目时起作用(我将“ localhost”更改为ip地址),但是当我尝试从同一ec2实例运行项目时却无效。

Realised I was running the django server on 0.0.0.0 instead of the default (for some reason my server doesn't work with 127.0.0.1). 我意识到我在0.0.0.0而不是默认值上运行django服务器(由于某种原因,我的服务器无法在127.0.0.1上运行)。

I added 0.0.0.0 to my pg_hba.conf connection list and it's working fine now. 我在pg_hba.conf连接列表中添加了0.0.0.0,现在可以正常工作了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM