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
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 '#'
CodePudding user response:
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