简体   繁体   English

Elixir / Phoenix无法连接到云托管的Postgres DB

[英]Elixir/Phoenix can't connect to cloud hosted Postgres DB

trying to get my first Phoenix app connected to Compose's Cloud Hosted Postgres DB and am unable to connect. 试图使我的第一个Phoenix应用程序连接到Compose的Cloud Hosted Postgres DB,但无法连接。 I have verified that it is up and running. 我已验证它已启动并正在运行。 I get the following error: 我收到以下错误:

[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

These are my dependencies: 这些是我的依赖项:

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

And my DB Config: 而我的数据库配置:

# 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

And using this version of PostgresSQL : PostgreSQL 9.4.10 并使用此版本的PostgresSQL: PostgreSQL 9.4.10

Any help would be greatly appreciated. 任何帮助将不胜感激。 :-) Y'all take care! :-)大家保重! -Chris -克里斯

The hostname of your database is aws-us-east-1-portal.5.dblayer.com , not the whole postgres://... . 数据库的hostnameaws-us-east-1-portal.5.dblayer.com ,而不是整个postgres://... Also, you need to specify the port since it's not the default PostgreSQL port. 另外,您还需要指定端口,因为它不是默认的PostgreSQL端口。 This should work: 这应该工作:

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

Since it seems you have a full database URL, probably the easiest solution for you will be to use that URL and let ecto decode it into the constituent parts that it needs for connecting. 由于您似乎拥有完整的数据库URL,因此最可能的解决方案是使用该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

Here's the documentation for that feature: https://hexdocs.pm/ecto/Ecto.Repo.html#module-urls 这是该功能的文档: https : //hexdocs.pm/ecto/Ecto.Repo.html#module-urls

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM