【问题标题】:Postgrex - No pg_hba.conf entry for host "xxx.xxx.xxx.xxx"Postgrex - 主机“xxx.xxx.xxx.xxx”没有 pg_hba.conf 条目
【发布时间】:2015-10-18 06:19:05
【问题描述】:

我有一个单独托管的 Postgres 数据库,我正在尝试将其与我的 Phoenix 应用程序一起使用。我的prod 配置是:

config :my_app, MyApp.Repo,
  adapter: Ecto.Adapters.Postgres,
  url: "postgres://username:password@myhost:5432/my_database",
  size: 20 

当我的应用程序托管在 Heroku 上时,这工作正常,但由于我已将其移至 VPS,我不断收到此错误:

17:07:13.665 [info] GET /subjects
17:07:13.707 [info] Processing by MyApp.SubjectController.index/2
  Parameters: %{"format" => "html"}
  Pipelines: [:browser, :authorize]
17:07:13.951 [error] GenServer #PID<0.515.0> terminating
** (exit) %Postgrex.Error{message: nil, postgres: %{code: :invalid_authorization_specification, file: "auth.c", line: "474", message: "no pg_hba.conf entry for host \"xxx.xxx.xxx.xxx\", user \"username\", database \"my_database\", SSL off", pg_code: "28000", routine: "ClientAuthentication", severity: "FATAL"}}
17:07:13.970 [info] Sent 500 in 305ms
17:07:13.972 [error] #PID<0.513.0> running MyApp.Endpoint terminated
Server: xxx.xxx.xxx.xxx:80 (http)
Request: GET /subjects
** (exit) exited in: GenServer.call(#PID<0.515.0>, {:query, "SELECT s0.\"id\", s0.\"name\", s0.\"inserted_at\", s0.\"updated_at\" FROM \"subjects\" AS s0", []}, 5000)
    ** (EXIT) %Postgrex.Error{message: nil, postgres: %{code: :invalid_authorization_specification, file: "auth.c", line: "474", message: "no pg_hba.conf entry for host \"xxx.xxx.xxx.xxx\", user \"username\", database \"my_database\", SSL off", pg_code: "28000", routine: "ClientAuthentication", severity: "FATAL"}}

我还可以从 Postgres GUI 工具连接到数据库,所以这没有什么问题。我注意到的一件事是它将我的 VPS IP 声明为主机,而不是 url 中指定的主机。

这应该没关系,因为数据库完全位于单独的主机上,但我仍然在这里尝试了解决方案:

真的很苦恼,请帮忙!

更新:这是我的pg_hba.conf

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# 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
host    all             all             0.0.0.0/0               md5

【问题讨论】:

  • pg_hba.conf 是一个文件,其中列出了您可以从 连接到数据库的位置,因此它没有提及您尝试连接的主机名也就不足为奇了
  • 另外,您具体尝试了什么?也许edit 包含您当前的pg_hba.conf 的问题。
  • 已更新。我添加了最后一行以允许从所有人访问所有地址。
  • 请删除此问题,因为这是一个简单的配置问题。
  • 为什么?这仍然可以帮助其他开发人员。 :)

标签: postgresql phoenix-framework ecto


【解决方案1】:

这太愚蠢了,但我发现了问题所在。我尝试连接的主机期望安全的数据库连接。默认情况下,SSL 是关闭的,所以我启用了它:

config :my_app, MyApp.Repo,
  adapter: Ecto.Adapters.Postgres,
  url: "postgres://username:password@myhost:5432/my_database",
  ssl: true,
  size: 20 

感谢这个答案:Node.js, PostgreSQL error: no pg_hba.conf entry for host

【讨论】:

    猜你喜欢
    • 2010-11-27
    • 2013-10-19
    • 2014-10-27
    • 2020-07-29
    • 2014-09-19
    • 2019-04-28
    • 2021-06-11
    • 2020-05-19
    相关资源
    最近更新 更多