Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgresql: FATAL: password authentication failed for user "douglas"

Tags:

I am trying to migrate a DB from sqlite to postgresql...so I typed:

sudo -u postgres psql postgres=# ALTER USER postgres WITH PASSWORD 'newpassword'; 

and the output returns ALTER ROLE

but when I type python manage.py migrate I receive always the same error:

django.db.utils.OperationalError: FATAL: password authentication failed for user "douglas"

This is the database sections of my settings.py.

# Old, using mysqlite """ DATABASES = {     #'default': {     #    'ENGINE': 'django.db.backends.sqlite3',     #    'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),     #}     'default': dj_database_url.config(default='postgres://localhost:5432/postgres_db_name'), } """  # New, using postgres DATABASES = {     'default': {         'ENGINE': 'django.db.backends.postgresql',         'NAME': 'douglas_db',         'USER': 'douglas',         'PASSWORD': 'vamointer',         'HOST': '127.0.0.1',         'PORT': '5432',     } } 

Note: When I run the 'ALTER USER postgres WITH PASSWORD' I put in the same password defined in the settings.py.

like image 411
Douglas da Dias Silva Avatar asked Mar 28 '17 04:03

Douglas da Dias Silva


People also ask

How do I fix Postgres password authentication failed?

Restart the PostgreSQL service from the Services control panel ( start->run->services. msc ) Connect using psql or pgAdmin4 or whatever you prefer. Run ALTER USER postgres PASSWORD 'fooBarEatsBarFoodBareFoot'

How do I list databases in PostgreSQL?

Step 1: Log in to the server using the SQL Shell (psql) app. Step 2: Run the following query: SELECT datname FROM pg_database; psql runs the query against the server and displays a list of existing databases in the output.


2 Answers

The SQL you are running does not match the user you are attempting to use.

You will need to create the user if it does not exist:

CREATE USER douglas WITH PASSWORD 'vamointer'; 

or if it does exist, change that user's password instead.

ALTER USER douglas WITH PASSWORD 'vamointer'; 

Once you have done that you should have more luck. You may need to assign permissions to that user as well.

like image 50
Shadow Avatar answered Sep 27 '22 21:09

Shadow


If you are bone-headed like me and have used 'USERNAME' instead of 'USER' in your Django database configs in settings.py, make sure you change it to 'USER' else you will see this same error. Hope this helps someone like me down the road.

like image 37
Harlin Avatar answered Sep 27 '22 21:09

Harlin