Home > Blockchain >  authentication failed when I use postgresql with django [closed]
authentication failed when I use postgresql with django [closed]

Time:09-28

OS: AWS linux django3.2.7 python 3.7 psql (PostgreSQL) 13.3

I am trying to use postgresql with django. I changed setting.py like below:

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

I created a password for postgre and I successfully logged in as this user.

$ sudo su - postgres 
Last failed login: Sun Sep 26 18:21:57 JST 2021 on pts/4
There were 6 failed login attempts since the last successful login.
-bash-4.2$ psql
Password for user postgres: 
psql (13.3)
Type "help" for help.

postgres=# 

However, when I tried to execute this:

$ python3 manage.py runserver

I got this error:

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

I am not sure what is the problem and would like to know how I can fix this.

Thank you in advance!

CodePudding user response:

Your database name is "postgres", you can see on psql bash (postgres=#), but you setup it to "dbname" on settings

CodePudding user response:

You are configured to use ident authentication, not password. Setting a password for the user does not change that--the password assigned will just sit there unused. If you want to use password authentication, you need to change pg_hba.conf to specify it, either md5 or "scram-sha-256".

Alternatively, you could learn how to use ident correctly, if that is what your framework wants you to do.

  • Related