Maximum database connections exceeded

367 views
Skip to first unread message

Hans Kristian Flaatten

unread,
Mar 20, 2015, 11:58:23 AM3/20/15
to django...@googlegroups.com
My Django application is exceeding the maximum number of simultaneous database
connections (100) to the Postgres database when running through Gunicorn with
async eventlet workers. When the limit it exceeded it starts returning
500-errors until new connections can be established.

Setting `CONN_MAX_AGE` to 0, 60, 600, or None does not appear to solve this issue.

This is my database configuration:

DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': 'django',
        'USER': 'django',
        'HOST': 'postgres',
        'PORT': 5432,
        'CONN_MAX_AGE': 60,
    }  
}

This is my Gunicorn configuration:

gunicorn --bind 0.0.0.0:8080 --worker-class eventlet --workers 5 myapp.wsgi:application

These are the installed packages:
  •  djano v1.7
  •  gunicorn v19.3
  •  eventlet v0.17
  •  psycopg2 v2.6
Any hints or tips on where to go from here? Is Django's ORM supposed to offer
connection pooling/reuse, or is this something I have to get else where?

Andreas Kuhne

unread,
Mar 20, 2015, 1:55:31 PM3/20/15
to django...@googlegroups.com
Hi Hans,

I know this isn't really solving your issue, but it can remove a symptom. I have successfully used pgBouncer to pool the connections, so that connections aren't handled by django directly, but you connect to a connection pool, so that it can create and reuse connections more efficiently. See https://wiki.postgresql.org/wiki/PgBouncer.

That would probably solve the symptoms of your problem, but not the problem itself.

Regards,

Andréas

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a5bd0b59-638c-466d-9f85-aadd5edda500%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages