Shashwat Chetan
Shashwat Chetan

Reputation: 41

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.

Upvotes: 1

Views: 1880

Answers (1)

Shashwat Chetan
Shashwat Chetan

Reputation: 41

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.

Upvotes: 1

Related Questions