1

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.

4
  • Try setting a password for user django and using that. Commented Jan 16, 2016 at 11:14
  • 1
    When you use 'localhost' there is a good chance that an ipv6 connection is made to address ::1 so you need a line for that in your pg_hba.conf or put in 127.0.0.1 instead of localhost in your connection settings to make sure ipv4 is used. Commented Jan 16, 2016 at 11:28
  • @Eelke I added the ipv6 line. I'm already checking for 127.0.0.1; still not working Commented Jan 16, 2016 at 12:20
  • Did you restart the server or reload settings (via pg_ctl reload) after changing pg_hba.conf? Commented Jan 20, 2016 at 15:09

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.