Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does database connection limit mean?

I'm using Django with a Postgres database from heroku. The heroku database has a

"connection limit of 20".

I don't understand what this means.

How is a connection defined? Every time a user visits my site I will get some stuff of the database. Is this already a connection because my website needs to connect to the database to get this data?

And what happens if the total number of connections is reached? Does the website still work?

like image 777
Nepo Znat Avatar asked Mar 05 '23 01:03

Nepo Znat


1 Answers

Every query you execute, makes a connection to database.

For example if you want to get some data out of your database, this is what happens in general:

1 - You execute your query in django level.

2 - Django will translate your query to SQL.

3 - Django creates a connection to your database.

4 - Your query will be executed in database.

5 - Django will receive the result.

6 - Django will close the connection.

That limitation means that you can have only 20 tasks working on step 3 to 6 at the same time.

And if you exceed this limitation, your application will throw an error or your application tries till it can make the connection (there will be limit for number of tries and you will get an error if you exceed the tries too) which leads your application to get slower or break on some requests.

You either have to upgrade your server/get more servers or you have to optimize your code to makes fewer queries (Combining queries for example).

like image 170
Navid Zarepak Avatar answered Mar 12 '23 20:03

Navid Zarepak