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
put_dynamic_repo(repo)
callback.()
after
put_dynamic_repo(default_dynamic_repo)
Supervisor.stop(repo)
end
end
end
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 (wrong.host:5432): 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?