diff --git a/lib/postgrex/replication_connection.ex b/lib/postgrex/replication_connection.ex index 01f22301..3354f17c 100644 --- a/lib/postgrex/replication_connection.ex +++ b/lib/postgrex/replication_connection.ex @@ -502,6 +502,10 @@ defmodule Postgrex.ReplicationConnection do maybe_handle(mod, :handle_connect, [mod_state], %{s | protocol: protocol}) {:error, reason} -> + Logger.error( + "#{inspect(pid_or_name())} (#{inspect(mod)}) failed to connect to Postgres: #{Exception.format(:error, reason)}" + ) + if s.auto_reconnect do {:keep_state, s, {{:timeout, :backoff}, s.reconnect_backoff, nil}} else diff --git a/lib/postgrex/simple_connection.ex b/lib/postgrex/simple_connection.ex index 0f411341..eaef1f8e 100644 --- a/lib/postgrex/simple_connection.ex +++ b/lib/postgrex/simple_connection.ex @@ -362,6 +362,10 @@ defmodule Postgrex.SimpleConnection do end {:error, reason} -> + Logger.error( + "#{inspect(pid_or_name())} (#{inspect(mod)}) failed to connect to Postgres: #{Exception.format(:error, reason)}" + ) + if state.auto_reconnect do {:keep_state, state, {{:timeout, :backoff}, state.reconnect_backoff, nil}} else @@ -466,6 +470,13 @@ defmodule Postgrex.SimpleConnection do end end + defp pid_or_name do + case Process.info(self(), :registered_name) do + {:registered_name, atom} when is_atom(atom) -> atom + _ -> self() + end + end + defp opts(mod), do: Process.get(mod) defp put_opts(mod, opts), do: Process.put(mod, opts)