Postgrex - 主机" xxx.xxx.xxx.xxx"没有pg_hba.conf条目

时间:2015-07-27 21:30:51

标签: postgresql phoenix-framework ecto

我有一个单独托管的Postgres数据库,我试图用我的Phoenix应用程序。我的{"ItemDescription": "Yyyyy\nYyyyyy\nYyyyyyyyy\nYyyyyyyyyyyy\nYyyyyyyyyyyyyy"} 配置是:

prod

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

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

我也可以从Postgres GUI工具连接到数据库,因此没有任何问题。我注意到的一件事是它将我的VPS IP声明为主机而不是网址中指定的主机。

由于数据库完全在一个单独的主机上,因此无关紧要,但我仍然在这里尝试了解决方案:

真的很挣扎,请帮忙!

更新:这是我的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"}}

pg_hba.conf

1 个答案:

答案 0 :(得分:8)

这太愚蠢了,但我弄明白了这个问题。我试图连接的主机,期望一个安全的数据库连接。默认情况下,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