[英]django.db.utils.OperationalError: connection to server at "database" failed: FATAL: sorry, too many clients already
I had a spike of this error in my Django application:我的 Django 应用程序中出现了这个错误:
django.db.utils.OperationalError: connection to server at "name-of-the-db" (172.17.0.11), port 5432 failed: FATAL: sorry, too many clients already My Django app is deployed on dokku and connected to a postgres database. django.db.utils.OperationalError: 在“name-of-the-db” (172.17.0.11) 连接到服务器,端口 5432 失败:致命:抱歉,已经有太多客户端 我的 Django 应用程序部署在 dokku 上并连接到postgres 数据库。 The connection to the db is achieved using dj-datbase-url package and the setting looks like this:
使用 dj-datbase-url package 实现与数据库的连接,设置如下所示:
DATABASES = {
"default": {
**dj_database_url.parse(
os.environ.get("DATABASE_URL", False), conn_max_age=600
),
"ATOMIC_REQUESTS": True,
}
}
I use daphne in front of Django, and I'm running 3 processes with daphne.我在 Django 前面使用了 daphne,并且我正在使用 daphne 运行 3 个进程。
What could have been causing this issue?是什么导致了这个问题?
I have read that a possible solution is to drop the conn_max_age parameter or set it to a lower value, but I'm not sold on it and don't completely understand how it works, so any guidance is welcome.我已经读过一个可能的解决方案是删除 conn_max_age 参数或将其设置为较低的值,但我没有出售它并且不完全理解它是如何工作的,所以欢迎任何指导。
Also, I haven't registered any abnormal traffic on my website, but I'm wondering: is this something that can happen “spontaneously”, maybe due to an incorrect setup, or could it be due to malicious activity?另外,我没有在我的网站上注册任何异常流量,但我想知道:这是否会“自发”发生,可能是由于设置不正确,还是由于恶意活动?
The most likely explanation I can think of is there is some database connection leaks around my app, but I can't figure out how to find them.我能想到的最可能的解释是我的应用程序周围存在一些数据库连接泄漏,但我不知道如何找到它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.