I'm running out of db connections, how can I see who has "checked out" db connections?

This question requires different answers based on the scale. Assuming you’re at the small side and with a few app servers and a database server, yah, 100 connections definitely seems like a lot. If you’re mid-size, well, I have seen the necessity to have enough app servers that the database runs out of sockets. This doesn’t sound like that, otherwise we would also need to check fd’s and socket counts.

Debugging:

  1. If you have access to the database, enable slow query logging on your database. On mysql, you can also do ‘show processlist’ to see what queries are being executed. Postgres has ‘show * from pg_stat_activity’
  2. If you don’t have direct access to the database, you can install live_dashboard with the database options. /dashboard/ecto/stats may be helpful.
  3. Ecto.DevLogger - an alternative logger of SQL queries in development
    It really appears that you have some hanging query and hopefully this package can help you catch it.
3 Likes