【问题标题】:OperationalError : FATAL: no pg_hba.conf entry for host "127.0.0.1", user "fibzadmin", database "fibz", SSL offOperationalError : FATAL: no pg_hba.conf entry for host "127.0.0.1", user "fibzadmin", database "fibz", SSL off
【发布时间】: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


【解决方案1】:

我认为错误信息非常准确。查看您的 pg_hba.conf,我没有看到将 fibzadmin 指定为有效用户的行,除了 ipv6。

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

host    all             fibzadmin     0.0.0.0/0               md5

【讨论】:

  • 我要试试这个。
  • 在添加后我收到错误 FATAL: password authentication failed for user "fibzadmin"。有没有一种简单的方法可以检查我指定的密码是否正确?
  • 认为您可以假设password authentication failed 表示您输入的密码不正确。如果你正在测试东西,你可以临时将信任级别设置为trust,这样你就可以登录了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-12-14
  • 1970-01-01
  • 1970-01-01
  • 2013-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多