DEV Community

Discussion on: Quickops 3: too many connections to my database and what can i do

Collapse
 
darwinpasco25 profile image
darwinpasco25 • Edited

If you have too many connections to your database, you should consider if your application is doing too many roundtrips to the database. You should design your database in such a way that it minimizes if not eliminate the need to do roundtrips.

  1. Make sure your tables are properly normalized. In most cases, this is where the actual problem will be.
  2. Always use set operation. You can use stored procedures that accept json or xml as parameters. Yo can read json and xml as table so you can do bulk insert, update or even delete(if advisable).
  3. Output nested records as json or xml so the application wont have to call multiple queries to fetch related records
  4. Check if your queries are optimized. Check the execution plan. Check the indexes. If the tables are not properly normalized, chances are the queries also aren't optimized and needs a lot of logic and data manipulation to come up with a result. The faster your queries execute, the sooner it can release the connection. Most cases of too many connections are due to poor query performance.
Collapse
 
aernesto24 profile image
Ernesto Lopez

Yes, thanks a lot for your answer, totally agree with you, in fact this post is if didn´t work with the best practices and you are in a trouble because your db cannot receive connection. It is a great comment thanks!