Elixir-Phoenix:混合 ecto.create 和混合 phx.server 引发相同的错误但包含不同的 postgres 数据库参数

Elixir-Phoenix: mix ecto.create and mix phx.server provoke same error but contain different postgres db parameters

当 运行ning mix ecto.create 我得到以下错误:

17:47:14.118 [error] GenServer #PID<0.299.0> terminating
** (Postgrex.Error) FATAL 28000 (invalid_authorization_specification) no pg_hba.conf entry for host "10.110.0.3", user "staging", database "postgres", SSL off
    (db_connection 2.4.0) lib/db_connection/connection.ex:100: DBConnection.Connection.connect/2
    (connection 1.1.0) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib 3.15.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol

然后,如果我尝试 运行 mix phx.server 我会收到以下错误:

[error] Postgrex.Protocol (#PID<0.358.0>) failed to connect: ** (Postgrex.Error) FATAL 28000 (invalid_authorization_specification) no pg_hba.conf entry for host "10.110.0.3", user "staging", database "contact", SSL off

我在 dev.exs 中的数据库配置是:

config :contact_api, ContactApi.Repo,
   username: System.get_env("DB_USER") || "postgres",
   password: System.get_env("DB_PWD")  || "postgres",
   database: System.get_env("DB_NAME") || "contact",
   hostname: System.get_env("DB_HOST") || "localhost",
   port: System.get_env("DB_PORT")     || "5432",
   show_sensitive_data_on_connection_error: true,
   pool_size: 10

任何帮助将不胜感激!

我的问题已经解决了。我正在使用由 Digital Ocean 托管的云托管 postgres 数据库。唯一允许的连接是使用 ssl certificates 加密的连接。错误跟踪仅通知 pg_hba.conf 中没有用户输入,但未提及 ssl 问题。因此我不得不修改 config/dev.exs:

config :contact_api, ContactApi.Repo,
   username: System.get_env("DB_USER") || "postgres",
   password: System.get_env("DB_PWD")  || "postgres",
   database: System.get_env("DB_NAME") || "contact",
   hostname: System.get_env("DB_HOST") || "localhost",
   port: System.get_env("DB_PORT")     || "5432",
   show_sensitive_data_on_connection_error: true,
   pool_size: 10
   ssl: true,
   ssl_opts: [
     cacertfile: "cert/ca-certificate.crt"
   ]