数据库连接限制是什么意思? [英] What does database connection limit mean?

查看:365
本文介绍了数据库连接限制是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Django与来自heroku的Postgres数据库一起使用。
heroku数据库具有

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

连接限制为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?

推荐答案

您执行的每个查询都与数据库建立连接。

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-您可以在django级。

1 - You execute your query in django level.

2-Django会将您的查询转换为SQL。

2 - Django will translate your query to SQL.

3-Django创建与您的数据库。

3 - Django creates a connection to your database.

4-您的查询将在数据库中执行。

4 - Your query will be executed in database.

5-Django将收到结果

5 - Django will receive the result.

6-Django将关闭连接。

6 - Django will close the connection.

该限制意味着您只能执行20个任务同时执行第3步到第6步。

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 through 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).

这篇关于数据库连接限制是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆