[英]Phoenix Framework: why mix ecto.create and mix phx.server not working?
[英]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
mix ecto.create
仍然在錯誤跟蹤中顯示數據庫名稱的postgres
。psql
從與應用程序相同的服務器連接到數據庫。mix ecto.create
, mix ecto.migrate
, mix test
和mix 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.