2

Yesterday I was attempting to setup a django website on an Ubuntu 16.04 server on Digital Ocean. I was having some problems with Potsgresql particularly when I thought I had it all installed and tried to migrate the files, eventually I found this thread and followed the chosen answer which worked perfectly for me

django.db.utils.OperationalError: could not connect to server: No such file or directory

after doing that I was able to get my site running (but with no css) on my site on :8000, I called it a day at that point.

After returning to it today about 24hrs later and trying to do

python manage.py runserver

so that I can finish the setup I am now getting this error

File "/home/david/.local/lib/python2.7/site-  packages/psycopg2/__init__.py", line 164, in connect
    conn = _connect(dsn, connection_factory=connection_factory,     async=async)
django.db.utils.OperationalError: FATAL:  password authentication     failed for user "django_user"
FATAL:  password authentication failed for user "django_user"

I tried recreating the steps from the other thread but that hasn't worked, Ive open the psql shell and reset the password and double checked that the password in my keys file is correct, I also checked that the user 'django_user' is still there and the correct db has the permissions etc.

This is my Django settings.py file

from .base import *
DEBUG = False
ADMINS = (
       ('My name', 'name@gmail.com'),
)
ALLOWED_HOSTS = ['domain name', 'www.domain name.co', 'ip address']

with open('/etc/django_keys/postgres_key.txt') as f:
        PSQL_KEY = f.read().strip()

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

Im pretty confused by all this, it was fine 24hrs ago, what has changed?

thanks

EDIT: I should add that I have read the other similar questions here where people suggest solutions about editing the pg_hba.conf file, this is something I have never done before though and Im very knew to psql and also I would like to know why this worked fine yesterday before I look at making other changes.

This is what I see when I login to psql as the postgres user and then lookup all users and databases, should it look like this?

psql screengrab

Community
  • 1
  • 1
goblin_rocket
  • 357
  • 2
  • 8
  • 17
  • This error message usually means the password is incorrect. Is it possible that you have changed the password, or that file `/etc/django_keys/postgres_key.txt` has been changed? And no, don't touch `pg_hba.conf`, the default is fine. – Antonis Christofides Jan 12 '17 at 14:21
  • Try to connect to the database with `sudo -u postgres psql -U django_user django_db`. Does it connect? – Antonis Christofides Jan 12 '17 at 14:23
  • @AntonisChristofides, not it doesn't and it returns this error - psql: FATAL: Peer authentication failed for user "django_user" please see the screen grab image of what I get when I check all the psql users and databases at the end of the post also please, thanks – goblin_rocket Jan 13 '17 at 01:18
  • @AntonisChristofides I double checked the pw too, it was all working fine when I last used it and nothing has been changed since – goblin_rocket Jan 13 '17 at 01:20
  • @AntonisChristofides so I just found this thread for the above problem in my last comment http://stackoverflow.com/questions/17443379/psql-fatal-peer-authentication-failed-for-user-dev and I ran the command that the top answer recommended and then it asked me for the pw for django_user and I entered the one I have set in my postgres_key.txt file and it worked fine. It now shows me logged in as django_db though... – goblin_rocket Jan 13 '17 at 01:33
  • OK think Ive (sort of) figured it out, Ive changed the pw to be hardcoded in the settings/pro.py file and Im not getting that error now and I think when I did it the first time and it worked I had it hardcoded too so it must be an other issue. I am however getting this error now which needs investigating further (when I try to run migrations) "App '%s' does not have migrations." % app_label UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 0: ordinal not in range(128) – goblin_rocket Jan 13 '17 at 12:44
  • ...and now managed to do a normal migrate and back where I was 36hrs again, so the problem is pulling the pw from another file which I will look into, thanks for your input! – goblin_rocket Jan 13 '17 at 12:47

0 Answers0