简体   繁体   中英

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.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. The connection to the db is achieved using dj-datbase-url package and the setting looks like this:

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM