Disabling connection pooling Ecto

Is it possible to disable connection pooling in Ecto; can you open a connection on the fly?
There are instances an application will occasionally connect to the database, hogging connection that is used occasionally I believe is not ideal especially when other applications depend on the same database.

Your question doesn’t make lot of sense. I really don’t know how Ecto does connection pooling, but whole idea of connection pooling is to keep those connections open and connected to database. Usually way it works when connection is returned back to pool it is just resetted not closed.

No, the only thing you can do is to set the pool_size to an amount that is large enough to not slow down your application to badly, while having it low enough to not be a blocker for your other applications.

1 Like

Connecting to a database is quite an expensive operation, a connection pool establishes a connection to the database and holds onto the connection without closing it, whether it’s being used by the application or not. For example your Postgres DB has max connection of 50, an idle application might be holding unto 5 without actually utilising the connection denying other applications chance to use those 5 connections.

1 Like

You could probably achieve a similar result by starting and stopping the Repo but I wouldn’t want to have to deal with the additional effort required to dynamically start it and stop it at the right time. If the repo can’t start because there aren’t any connections available, for example, then now I have a another failure mode I have to deal with in the application.

Won’t there be a problem that ECTO can’t open those connections to your database and returns errors when you have multiple apps connecting to same database and have limit like that? Shouldn’t you put all connection limits in all connected to apps to combined limit that wouldn’t go over database connection limit? Or add something like PgBouncer in front of PostgreSQL?

That’s exactly why connections to databases are kept alive and pooled. Because connecting for each individual requests adds a bunch of additional latency on all your queries.

1 Like

@kodepett - I believe there is a way - coincidentally a member of our team introduced me to Ecto DynamicRepositories two days ago - you can use them for ad-hoc, infrequently used connections to arbitrary databases

Dynamic repos are needed for giving a name to dynamically started repos and being able to use them. Starting/stopping can be done with any repo – dynamic repo or not.

1 Like

I’ve gone through all the comments, grateful for your support. Thanks everyone.

2 Likes