Issue
File "/usr/local/lib/python3.7/dist-packages/psycopg2/__init__.py", line 126, in connect conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: FATAL: remaining connection slots are reserved for non-replication superuser connections
According to the Postgres documentation, this error occurs when Django makes more connections to the Postgres DB then it's default connection limit.
- I would like to know what could be the reasons for Django to be initiating/an opening lot of connections to the DB.
- I would like to know what are the best practices we can do to prevent it from the exception.
- How to increase the default connection limit for Postgres?
#settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'xxxxx',
'USER': 'xxxxx',
'PASSWORD':'xxxxx',
'HOST':'localhost',
'PORT':'5432',
}
Solution
I believe that this is ocuring given Django framework don't make database pooling. Looking into Django docs (https://docs.djangoproject.com/en/3.2/ref/databases/#transaction-pooling-and-server-side-cursors) i could find a sugestion to user pgBouncer (http://www.pgbouncer.org/) to deal with that.
Answered By - Thiago Schettini
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.