Is there a way to get lower DBConnection.ConnectionError from Ecto?

We are making a small B2B SaaS that loads data from customer’s DB.
To do that, we use dynamic repo.

defmodule MyApp.Dynamic.PostgresRepo do
  use Ecto.Repo,
    otp_app: :my_app,
    adapter: Ecto.Adapters.Postgres

  def with_dynamic_repo(credentials, callback) when is_function(callback, 0) do
    default_dynamic_repo = get_dynamic_repo()

    {:ok, repo} = __MODULE__.start_link(credentials)

    try do

When a customer try to connect their DB to our services with wrong host information, Postgrex logs like below.

[error] Postgrex.Protocol (#PID<0.2407.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect ( non-existing domain - :nxdomain

But error finally occurred doesn’t contain that information.
It has a message like below.

[error] ** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 4000ms. 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

    (ecto_sql 3.10.1) lib/ecto/adapters/sql.ex:913: Ecto.Adapters.SQL.raise_sql_call_error/1

I want to get more information when connection information is wrong.

Is there a way to get lower DBConnection.ConnectionError from Ecto?

Could the :show_sensitive_data_on_connection_error option in the config help you here?

Some reference here: Ecto.Adapters.Postgres — Ecto SQL v3.10.1

1 Like

Thanks for your reply!

:show_sensitive_data_on_connection_error is true already.
So it shows detailed errors, but I can’t get or capture that error in code.

I solved this problem by calling raw level APIs, like

Postgrex.Protocol.connect(opts), MyXQL.Connection.connect(opts).