0

This has been giving me problems for a few days now.

I have a django application that I am trying to connect to an elephantsql database.

My settings look like this:

DATABASES = {'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'name_provided_by_elephantsql',
        'USER': 'name_provided_by_elephantsql',
        'PASSWORD': 'xxxxxxxxxxxxxxxx',
        'Host': 'ziggy.db.elephantsql.com',
        'PORT': '5432',
    }
}

Every time I try to makemigrations, I get the following error:

`django.db.utils.OperationalError: FATAL:  Peer authentication failed for user "name_provided_by_elephantsql"

My pg_hba.conf file looks like this, but I have tried adding the credentials under IPv6, as well as changing several of the 'peer' to 'md5':

# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5

Then I tried to create a psql user with the same name, and created a database with it:

createdb -U name_provided_by_elephantsql -h ziggy.db.elephantsql.com -p 5432

And it returned:

createdb: error: could not connect to database template1: FATAL:  no pg_hba.conf entry for host "174.45.58.218", user "name_provided_by_elephantsql", database "template1", SSL on
FATAL:  no pg_hba.conf entry for host "174.45.58.218", user "name_provided_by_elephantsql", database "template1", SSL off

Restarted postgresql in between each attempt. I even tried purging postgresql. Lastly I tried this before reinstalling postgresql:

sudo rm -Rf /etc/postgresql /var/lib/postgresql

Can anyone tell me what I might be missing?

  • Maybe this [answer will helps you](https://stackoverflow.com/questions/2942485/psql-fatal-ident-authentication-failed-for-user-postgres?rq=1) – Mubashar Javed Jan 25 '21 at 04:49
  • @Mubasharjaved unfortunately not. I've already worked my way through those solutions and none of them helped. – Matthew George Jan 25 '21 at 16:13
  • Peer authentication is only used for linux socket connections. So you aren't connecting to the server you think you are. Maybe because 'Host' is mis-capitalized? – jjanes Jan 25 '21 at 19:25
  • @jjanes That was it! I am not sure whether to smile that its fixed or cry that I wasted three days on such a simple error. Thanks a bunch! – Matthew George Jan 25 '21 at 20:26
  • @jjanes I changed all the 'peer' and 'md5' in 'pg_hba.conf' file into 'trust', restarted postgresql service, and 'migrate' worked. I know that I should not have done that. But what should I do? Please kindly advise. Thanks in advance! (It is 'host' in the pg_hba.conf file, and 'HOST' in site settings.py file.) – Sherman Chen Nov 21 '21 at 17:18

0 Answers0