I'm having trouble connecting to my postgres database from my django site. Before beginning, I have read and attempted the instructions provided at each of these sites:
- Django setting : psycopg2.OperationalError: FATAL: Peer authentication failed for user "indivo"
- OperationalError: (psycopg2.OperationalError) FATAL: password authentication failed for user
- FATAL: password authentication failed for user "root" postgresql
- postgresql: FATAL: password authentication failed for user "douglas"
Any assistance you are able to provide with the problem described below would be most-helpful in completing this site for a non-profit. Thank you in advance.
Traceback
Traceback is too large for this post. See: https://pastebin.com/fX7NY36M.
uname
kris@dask:~$ uname -a Linux dask 4.9.36-x86_64-linode85 #1 SMP Thu Jul 6 15:31:23 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
pg_hba.conf
kris@dask:~$ sudo cat /etc/postgresql/9.5/main/pg_hba.conf
...
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
wsgi.py
kris@dask:/home/dask/www/code/daskretreats_org$ cat wsgi.py
"""
WSGI config for daskretreats_org project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
from mezzanine.utils.conf import real_project_name
os.environ.setdefault("DJANGO_SETTINGS_MODULE",
"%s.settings" % real_project_name("daskretreats_org"))
application = get_wsgi_application()
settings.py
settings.py is too large for this post. See: https://pastebin.com/Dynq7EvT.
Testing psycopg2 python library
(venv) dask@dask:~/www/secrets$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
>>> f = open("postgres_key")
>>> passwd = f.read().strip()
>>> conn = psycopg2.connect("dbname=daskretreats_org user=dask password=%s" % passwd)
>>> conn.dsn
'password=xxx user=dask dbname=daskretreats_org'
Apache Site Configuration
kris@dask:~$ cat /etc/apache2/sites-enabled/daskretreats_org.conf
<VirtualHost *:80>
ServerName daskretreats.org
Alias /static /home/dask/www/html/static
<Directory /home/dask/www/html/static>
Require all granted
</Directory>
<Directory /home/dask/www/code/daskretreats_org>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess daskretreats_org python-home=/home/dask/www/venv python-path=/home/dask/www/code
WSGIProcessGroup daskretreats_org
WSGIScriptAlias / /home/dask/www/code/daskretreats_org/wsgi.py
</VirtualHost>
DATABASES
. You also need to create that user in PostgreSQL using SQL'sCREATE USER
or PostgreSQL'screateuser
command-line program. – Antonis ChristofidesHOST
to 'localhost' instead of the empty string and check if it works; 2) Have you restarted PostgreSQL after changingpg_hba.conf
? 3) Could you paste the entirepg_hba.conf
to pastebin? – Antonis Christofidespg_hba.conf
: pastebin.com/eFyQaGQp. ChangedHOST
tolocalhost
in settings.py. Executedsudo service postgresql reload
andsudo service apache2 reload
. Webpage test returned same error in browser. Traceback was also the same. – Kristopher Kerwin127.0.1.1 dask
to your/etc/hosts
. Next, please clarify: the message in the traceback is "peer authentication failed". When you change "HOST" to 'localhost' is it still the same? Or is it "password authentication failed"? – Antonis Christofides