Local-running Ecto not connecting to remote Postgres GCloud

I am trying to connect an Ecto project running on my local machine to a remote Postgres GCloud instance. I have added the following entry to my config.exs:



config :my_ecto_test, MyEctoTest.Repo,
  username: "<username>",
  password: "<password>",
  database: "<database_name>",
  hostname: "<ip_address>",
  show_sensitive_data_on_connection_error: true,
  pool_size: 10

I triple-checked that all my actual values were correct, but I keep getting this error over and over again:
** (Mix) The database for MyEctoTest.Repo couldn’t be created: connection not available and request was dropped from queue after 2000ms. This means requests are coming in and your connection pool cannot serve them fast enough. You can address this by:

  1. Ensuring your database is available and that you can connect to it
  2. Tracking down slow queries and making sure they are running fast enough
  3. Increasing the pool_size (although this increases resource consumption)
  4. Allowing requests to wait longer by increasing :queue_target and :queue_interval

See DBConnection.start_link/2 for more information

Hi @gavid, when dealing with cloud hosted databases it’s also important to make sure that the firewall and network / VPC settings allow access from where you are trying to connect. Are you able to connect via psql from your local machine?

@benwilson512 I couldn’t see the add network interface in the GCloud console because of a responsiveness issue, but thanks to you I knew to look for it and I zoomed out :rofl:

I can now get a basic connection working.

Another thing, I have read that it is possible to specify Ecto Repos in this format? Is this correct? If I try to copy the config in the previous format, I get errors again:

config :my_ecto, MyEcto.Repo,
  url: "ecto://<username>:<password>@<host_ip_address>/<database>",
  show_sensitive_data_on_connection_error: true,
  pool_size: 10

This is the stacktrace:

14:21:52.073 [error] GenServer #PID<0.305.0> terminating
** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
    (db_connection 2.4.3) lib/db_connection/connection.ex:100: DBConnection.Connection.connect/2
    (connection 1.1.0) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib 4.2) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol

14:21:52.086 [error] GenServer #PID<0.311.0> terminating
** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
    (db_connection 2.4.3) lib/db_connection/connection.ex:100: DBConnection.Connection.connect/2
    (connection 1.1.0) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib 4.2) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
** (Mix) The database for MyEcto.Repo couldn't be created: killed

Config is merged, if you have configured the repo with the separate keys before supplying the url won’t necessarily overwrite previous config.

I created an entirely new project for the most recent config code. Sorry, should have clarified.