I made a Django app, and I was able to connect from my local machine. I then pushed the code to pythonanywhere.com, and initially it ran, and everything went smoothly. But suddently my app in pythonanywhere.com started giving me this message:
Connection refused
Is the server running on that host and accepting TCP/IP connections?
So, I checked if I could still connect from local and I can, meaning the DB is up and running.
I don’t think I modified anything in the code in pythonanywhere that affected the connection as far as I recall.
Any idea of why this might be happening? Does Aiven free tier have some kind of limitations regarding simultaneous connections? Just in case I stop the local app, but still the same issue.
All plans have connection limits. The limits for the free plan are unfortunately not specified there; when I tried SHOW max_connections
on my own PostgreSQL 16 free plan, I got 20.
Bear in mind there may be existing replication and administration connections, both those set up by you and used by the platform; and some connections will be reserved for the superuser (three in my case), so you won’t be able to use as many as you might expect.
If your application holds onto connections implicitly until the end of a request, that may also impact the available number.
If you can set up an intermediary local connection pooler that might be the best way to go, then you can control the connections made to the backend. This may be available in your platform, else you might have to spin up an instance of pgbouncer yourself. Or upgrade to a Hobbyist plan for another 5 connections, or Startup for 100+ total and a built-in pooler.
I think if you had run into a connection limit it might have warned you more explicitly about that, though. Another possibility that strikes me is that you might be running into a firewall at one end or another. If you’re using Aiven’s IP restriction feature, check that it covers all ranges that may be used by the application. Check the port’s right/allowed by provider too!
I apreaciate the response, but at the end it didn’t help. The issue seems kind of random. At first the site in pythoneverywhere worked fine, suddently the whole app gave me the message I pasted above.
Just to be sure, in case I had modified something in the code that produced that error, I deleted the site and recreated. It didn’t work at first, but then, the next day the site would work. Now it’s working BUT I get the same response when I try to do a POST request. This is frustrating.
1 Like