Django+tenant FATAL: sorry, too many clients already

I am currently updating the following error in my application:

This error does not occur all the time, only at certain times of the day. I have the following database configuration where I use tenants:

DATABASE_URL = os.environ.get('DATABASE_URL')
DATABASES = {'default': dj_database_url.parse(DATABASE_URL)}
DATABASES['default']['ATOMIC_REQUESTS'] = True
DATABASES['default']['ENGINE'] = 'django_tenants.postgresql_backend'
DATABASES['default']['CONN_MAX_AGE'] = 300
DATABASES['default']['OPTIONS'] = {'MAX_CONNS': 25}
DATABASE_ROUTERS = ( 'django_tenants.routers.TenantSyncRouter', )

What I don't understand is that when I query the maximum number of connections directly in the database, the number that appears is 1708: max_connections

And the error starts to pop up when my bank starts to have the number of connections above 400: dashboard

Initially my backend connection to the database did not have the following settings:

DATABASES\['default'\]\['CONN_MAX_AGE'\] = 300
DATABASES\['default'\]\['OPTIONS'\] = {'MAX_CONNS': 25}

However, I believe that these settings would not affect the tenant.

Upvotes: 0

Views: 47

Answers (0)

Related Questions