简体   繁体   中英

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:

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

I checked my pg_hba.conf to make sure it allowed local connections:

# "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:

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.

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).

I added 0.0.0.0 to my pg_hba.conf connection list and it's working fine now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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