OperationalError:严重:主机“ 127.0.0.1”,用户“ fibzadmin”,数据库“ fibz”,关闭SSL时没有pg_hba.conf条目

时间:2018-11-23 07:36:44

标签: python django postgresql devops

几天来我一直在努力解决这个问题。我已经阅读了许多其他的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上的同一实例上发生的。

1 个答案:

答案 0 :(得分:0)

我认为错误消息非常准确。在查看您的pg_hba.conf时,除通过ipv6之外,没有看到指定fibzadmin为有效用户的行。

我认为您需要添加以下行:

host    all             fibzadmin     0.0.0.0/0               md5