我无法从我的django网站连接到我的postgres数据库。在开始之前,我已经阅读并尝试了每个站点提供的说明:
您能够提供下述问题的任何帮助对于为非营利组织完成本网站最有帮助。提前谢谢。
回溯
回溯对于这篇文章来说太大了。请参阅: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太大了。请参阅:https://pastebin.com/Dynq7EvT。
测试psycopg2 python库
(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站点配置
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>
答案 0 :(得分:1)
您是否为用户设置了角色并授予用户数据库权限?
postgres=#
ALTER ROLE mydbuser SET client_encoding TO 'utf8';
ALTER ROLE mydbuser SET default_transaction_isolation TO 'read committed';
ALTER ROLE mydbuser SET timezone TO 'UTC';
GRANT ALL PRIVILEGES ON DATABASE mydb TO mydbuser;
答案 1 :(得分:0)
您甚至可以联系 postgres =#吗?如果没有,请执行以下操作:
如果您在Ubuntu上,请执行以下操作:
sudo su - postgres
,然后按Enter键psql
并按Enter
然后您会看到此 postgres =#
现在,您可以根据需要进行操作