簡體   English   中英

Elixir-Phoenix:混合 ecto.create 和混合 phx.server 會引發相同的錯誤,但包含不同的 postgres db 參數

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

運行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
  • 我已經檢查過 env 變量是否正確設置。
  • 我還嘗試測試不同的 env 值,但mix ecto.create仍然在錯誤跟蹤中顯示數據庫名稱的postgres
  • 我可以使用psql從與應用程序相同的服務器連接到數據庫。
  • 使用 docker 運行本地數據庫時; mix ecto.create , mix ecto.migrate , mix testmix phx.server按預期運行。

任何幫助都感激不盡!

我已經解決了我的問題。 我正在使用由 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"
   ]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM