Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Django takes ubuntu username to connect database instead of db user from settings.py

I trying to run django website on aws ec2 machine (ubuntu). my postgresql database running on aws RDS

when I run $python manage.py runserver, it throws this error:

django.db.utils.OperationalError: connection to server at "xxxxx.xxxxx.us-east-2.rds.amazonaws.com" (xxx.xx.xx.xxx), port 5432 failed: FATAL:  password authentication failed for user "ubuntu"

basically django trying to connect database using ubuntu user instead of postgres user in settings.py

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

my settings.py:

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql',
    'NAME': config('NAME'),
    'USER': config('USER'),
    'PASSWORD':config('PASSWORD'),
    'HOST':config('HOST')
    #'HOST':'localhost'
}

}

.env file:

SECRET_KEY=xxxx
DEBUG=True
HOST=xxx.xxx.us-east-2.rds.amazonaws.com
NAME=xxxx
USER=postgres
PASSWORD=xxxxxx

my password has special special char ‘#’

>Solution :

A Linux distribution typically uses the $USER variable to specify the name of the user, not of the database.

I would advise to use $DB_USER or something similar, so:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': config('DB_NAME'),
        'USER': config('DB_USER'),
        'PASSWORD':config('DB_PASSWORD'),
        'HOST':config('DB_HOST')
    }
}

and then configure with:

SECRET_KEY=xxxx
DEBUG=True
DB_HOST=xxx.xxx.us-east-2.rds.amazonaws.com
DB_NAME=xxxx
DB_USER=postgres
DB_PASSWORD=xxxxxx
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading