Connect/Disconnect from remote Repo

Hi,
my Phoenix app works with several remote PostgreSQL repos and connects to them one-by-one: connect - get data - disconnect. The code for connecting to a remote repo looks something like this:

default_dynamic_repo = Repo.get_dynamic_repo()
{:ok, repo} = Repo.start_link(start_opts)

try do
Repo.put_dynamic_repo(repo)
some_records = Repo.all(SomeRecords)
Repo.put_dynamic_repo(default_dynamic_repo)
after
Repo.put_dynamic_repo(default_dynamic_repo)
Supervisor.stop(repo)
end

After disconnect from remote db i have this errors in Postgres log (remote db):
“AUDIT: FAILURE, DISCONNECT, … lost frontend connection” x 10 times
I think the error message is repeated 10 times because repo pool_size=10 by default.

I have several questions:

  • how to disconnect from remote db correctly without errors?
  • if i have a few requests to db, can i set pool_size=1? What does it effect?
  • is it possible not to call the Supervisor.stop(repo) method and keep the connection alive until the next session? How is it better to handle connection errors in this case?