0down votefavorite 
<https://stackoverflow.com/questions/48644208/django-postgresql-heroku-operational-error-fatal-too-many-connections-for-r#>

I am running a web application using Django and Django Rest Framework on 
Heroku with a postgresql and redis datastore. I am on the free postgresql 
tier which is limited to 20 connections.

This hasn't been an issue in the past, but recently I started using django 
channels 2. <https://github.com/django/channels>0 and the daphne server 
<https://github.com/django/daphne/> (switched my Procfile from gunicorn to 
daphne like this tutorial 
<https://blog.heroku.com/in_deep_with_django_channels_the_future_of_real_time_apps_in_django>)
 
and now I have been running into all sort of weird problems.

The most critical is that connections to the database are being left open 
so as the app runs, the number of connections keep increasing until it 
reaches 20 and gives me the following error message: Operational Error - 
'FATAL too many connections for role "usename"'

[image: Sentry Error Description] <https://i.stack.imgur.com/VdZFC.png>

[image: postgresql connection utilization] 
<https://i.stack.imgur.com/va8Sp.png> 


Then I have to manually go to shell and type heroku pg:killall each time, 
this is obviously not a feasible solution and this is production so my 
users cant get access to site and get 500 errors. Would really appreciate 
any help.

I have tried:

Adding this to my different views in different places

from django.db import connections conections.close_all()

for con in connections: con.close()

I also tried doing SELECT * from pg_activity and saw a bunch of stuff but 
have no idea what to make of it:

<https://i.stack.imgur.com/BTbNu.png>


-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/50195a32-6dcb-4ad5-a778-c83b5f366718%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to