Reputation: 172
Recently I've been receiving this error regarding what appears to be an insufficiency in connection slots along with many of these Heroku errors:
H18 - Request Interrupted H19 - Backend connection timeout H13 - Connection closed without response H12 - Request timeout
django.db.utils.OperationalError in /
FATAL: remaining connection slots are reserved for non-replication superuser connections
Are there general good practices for where one should or should not perform querysets in a Django application, or when to close a database connection?
I've never experienced this error before. I have increased my dynos on heroku and allocated significantly more RAM and I am still experiencing the same issue.
I've found similar questions on Stack Overflow but I haven't been able to figure out what might be causing the issue exactly.
I have querysets in Model methods, views, decorator views, context processors.
My first inclination would be that there is an inefficient queryset being performed somewhere causing connections to remain open that eventually crashes the application with enough people accessing the website.
Any help is appreciated. Thanks.
Upvotes: 2
Views: 4258
Reputation: 172
I realized that I was using the django server in my procfile. I accidentally commented out and commited it to heroku instead of using gunicorn. Once I switched to gunicorn on the same heroku plan the issue was resolved.
Using a production level application server really makes a big difference. Also don't code at crazy hours of the day when you're prone to errors.
Upvotes: 4