凤凰无法连接到Heroku的PostgreSQL服务器

3

这是我在一个全新的Phoenix应用程序中看到的错误,我设置它来进行一些试验:

[error] Postgrex.Protocol (#PID<0.362.0>) 连接失败: ** (Postgrex.Error) FATAL 28000 (invalid_authorization_specification): no pg_hba.conf entry for host "24.25.201.68", user "koilqmnaakvfjg", database "dc245o0vlbprf7", SSL off

这是我的 config/dev.exs 文件:

# Configure your database
config :hello, Hello.Repo,
  adapter: Ecto.Adapters.Postgres,
  username: "koilqmnaakvfjg",
  password: "somepass",
  database: "dc245o0vlbprf7",
  hostname: "ec2-54-243-54-6.compute-1.amazonaws.com",
  pool_size: 10

有些简单的东西我错过了吗?

编辑:

我的pg_hba.conf文件看起来像这样:

# TYPE  DATABASE        USER            ADDRESS                 METHOD
host  all  all 0.0.0.0/0 md5
# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     trust
host    replication     all             127.0.0.1/32            trust
host    replication     all             ::1/128                 trust

你应该在你的Postgres配置中允许来自任何地方的连接(或将其限制为24.25.201.68),位于54.243.54.6 - Aleksei Matiushkin
@mudasobwa,请查看已更新的问题,其中包括pg_hba.conf。 - dsp_099
一个简单粗暴的解决方法是将以下行放在此文件中并重新启动Postgres:host dc245o0vlbprf7 koilqmnaakvfjg 0.0.0.0/0 password - Aleksei Matiushkin
@mudasobwa 那个方法不起作用。如果Elixir应该连接到远程服务器,那么更新本地pg_hba的目的是什么? - dsp_099
1个回答

5

您需要将ssl参数设置为true,如果问题仍然存在,请修改pg_hba.conf文件。

解决方法:

# Configure your database
config :hello, Hello.Repo,
  adapter: Ecto.Adapters.Postgres,
  username: "koilqmnaakvfjg",
  password: "somepass",
  database: "dc245o0vlbprf7",
  hostname: "ec2-54-243-54-6.compute-1.amazonaws.com",
  pool_size: 10,
  ssl: true

希望有所帮助 :D
告诉我它的进展;
祝你好运;

不管我怎么尝试,似乎都不起作用。解决方法是不使用Heroku的postgres服务,而是换成另一个替代品。 - dsp_099
我在我的应用程序中使用Heroku服务,配置pg_hba.conf后没有任何问题。很高兴你解决了你的问题:D - sBanda
不,我没有,配置看起来像这样,并且完美地工作着: config :test_rest, Test.Repo, adapter: Ecto.Adapters.Postgres, username: "someusername", password: "somepassword", database: "somedb", hostname: "ec2-46-137-109-220.eu-west-1.compute.amazonaws.com", pool_size: 10, ssl: true - sBanda
这解决了我的问题。Heroku现在连接到PostgreSQL时需要SSL。https://devcenter.heroku.com/changelog-items/2035 - Neil

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接