Django REST framework Postgresql Heroku : Operational Error - 'FATAL too many connections for role “usename”'

55 views
Skip to first unread message

Tomiwa Ademidun

unread,
Feb 6, 2018, 8:34:19 AM2/6/18
to Django REST framework

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.0 and the daphne server (switched my Procfile from gunicorn to daphne like this tutorial) 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"'

Sentry Error Description

postgresql connection utilization 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:

Heroku Dataclip pg_activity

Tom Christie

unread,
Feb 15, 2018, 9:19:32 AM2/15/18
to Django REST framework
You might want to try taking the question to django-dev, since it's not specifically about REST framework. Perhaps someone there will be able to help you dig into how to configure things differently.
Reply all
Reply to author
Forward
0 new messages