2017-01-29 75 views
1

試圖讓我的第一個鳳凰應用程序連接到Compose的雲託管Postgres數據庫並且無法連接。我已經驗證它已啓動並正在運行。我得到以下錯誤:Elixir/Phoenix無法連接到託管的雲Postgres DB

[error] GenServer #PID<0.178.0> terminating 
** (DBConnection.ConnectionError) tcp connect (postgres://*****@aws-us-east-1-portal.5.dblayer.com:16786/compose:5432): non-existing domain - :nx 
domain 
    (db_connection) lib/db_connection/connection.ex:148: DBConnection.Connection.connect/2 
    (connection) lib/connection.ex:622: Connection.enter_connect/5 
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3 
Last message: nil 
State: Postgrex.Protocol 
** (Mix) The database for HelloPhoenix.Repo couldn't be created: an exception was raised: 
    ** (DBConnection.ConnectionError) tcp connect (postgres://****@aws-us-east-1-portal.5.dblayer.com:16786/compose:5432): non-existing domain - 
:nxdomain 
     (db_connection) lib/db_connection/connection.ex:148: DBConnection.Connection.connect/2 
     (connection) lib/connection.ex:622: Connection.enter_connect/5 
     (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3 

這是我的依賴關係:

defp deps do 
    [{:phoenix, "~> 1.2.1"}, 
    {:phoenix_pubsub, "~> 1.0"}, 
    {:phoenix_ecto, "~> 3.0"}, 
    {:postgrex, ">= 0.0.0"}, 
    {:phoenix_html, "~> 2.6"}, 
    {:phoenix_live_reload, "~> 1.0", only: :dev}, 
    {:gettext, "~> 0.11"}, 
    {:cowboy, "~> 1.0"}] 
end 

而且我的數據庫配置:

# Configure your database 
config :hello_phoenix, HelloPhoenix.Repo, 
    adapter: Ecto.Adapters.Postgres, 
    username: "admin", 
    password: "******", 
    database: "compose", 
    hostname: "postgres://admin:******@aws-us-east-1-portal.5.dblayer.com:16786/compose", 
    pool_size: 10 

並使用此版本的PostgreSQL中的:PostgreSQL的9.4.10

任何幫助將不勝感激。 :-)你們都保重! -Chris

回答

4

您的數據庫的hostnameaws-us-east-1-portal.5.dblayer.com,而不是整個postgres://...。另外,您需要指定端口,因爲它不是默認的PostgreSQL端口。這應該工作:

config :hello_phoenix, HelloPhoenix.Repo, 
    adapter: Ecto.Adapters.Postgres, 
    username: "admin", 
    password: "******", 
    database: "compose", 
    hostname: "aws-us-east-1-portal.5.dblayer.com", 
    port: 16786, 
    pool_size: 10 
+0

感謝的人,是非常完美! – cpeele00

4

因爲它似乎你有一個完整的數據庫URL,也許對你最簡單的解決方法是將使用該網址,讓外生其解碼爲它需要連接的組成部分。

config :hello_phoenix, HelloPhoenix.Repo, 
    adapter: Ecto.Adapters.Postgres, 
    url: "postgres://admin:******@aws-us-east-1-portal.5.dblayer.com:16786/compose", 
    pool_size: 10 

下面是該功能的文檔:https://hexdocs.pm/ecto/Ecto.Repo.html#module-urls

+0

感謝您的輸入!我已經在你的面前讀過Dogbert的解決方案並且嘗試過了,所以我把他標記爲「正確的」。但只是想表示感謝迴應,並指出我在文檔中的這一功能。 :-) – cpeele00