【发布时间】:2019-04-25 19:33:41
【问题描述】:
这几天我一直在努力解决这个问题。我已经阅读了许多其他 SO 线程,似乎我的 django 应用程序难以连接到 postgres 数据库。我不确定为什么会这样。我希望那里的一些专家可以看看并告诉我为什么会发生这种情况。我在这里粘贴了一些我的配置。
这是我的 settings.py 包含的内容
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'fibz',
'USER':"fibzadmin",
"PASSWORD":"fibzadmin",
"HOST":"localhost",
"PORT":"5432",
}
}
这就是我的 pg_hba.conf 和 postgresql.conf 的样子
sudo vim /var/lib/pgsql9/data/pg_hba.conf
输出:
local all all trust
# IPv4 local connections:
host all power_user 0.0.0.0/0 md5
# IPv6 local connections:
host all other_user 0.0.0.0/0 md5
host all storageLoader 0.0.0.0/0 md5
host all all ::1/128 md5
以下是未注释的主要行
listen_addresses = '*'
port = 5432
max_connections = 100
这是来自 psql
(fibzVenv) [admin]$ sudo su - postgres
Last login: Fri Nov 23 07:13:53 UTC 2018 on pts/3
-bash-4.2$ psql -U postgres
psql (9.2.24)
Type "help" for help.
postgres=# \du
List of roles
Role name | Attributes | Member of
------------+------------------------------------------------+-----------
postgres | Superuser, Create role, Create DB, Replication | {}
fibzadmin | | {}
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+------------+----------+-------------+-------------+---------------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
fibz | fibzadmin | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/fibzadmin +
| | | | | fibzadmin=CTc/fibzadmin
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
对于我可能做错了什么或我应该看什么有什么建议吗?这发生在亚马逊 linux 上,它在同一个实例上。
【问题讨论】:
-
/etc/hosts中有什么内容? -
也不应该将
ENGINE设置为django.db.backends.postgresql而不是django.contrib.gis.db.backends.postgis。 -
不,我使用的是 postgis 插件而不是 postgresql
标签: python django postgresql devops