Can't connect to a remote PostgreSQL from my deployed Streamlit app

I am trying to access PostgreSQL DB on A2 hosting from a deployed streamlit app and receive an error below:

PostgreSQL error: (psycopg2.OperationalError) connection to server at “” (, port 5432 failed: FATAL: no pg_hba.conf entry for host “”, user “db-user”, database “database-name”, SSL off

(Background on this error at: Error Messages — SQLAlchemy 2.0 Documentation)

A2 Hosting tech support say that whitelisted the IP address of my Streamlit app, however in the logs they don’t even see a connection request. I can connect to the DB from my local Streamlit app by using PuTTY tunneling as the hosting company suggested and perform all DB operations. However, the deployed application throws an exception above.

Hi @jivishov,

Unfortunately, if you need to allow-list the hosted app’s IP address, Streamlit Community Cloud won’t be the best hosting option, since it doesn’t offer stable outbound IP addresses. I’d recommend hosting your app on another platform that does offer stable outbound IP addresses, or running the app locally – check out our community deployment wiki here.

Thank you for your reply, @Caroline!

This makes sense, but there is one point actually to mention for clarification.

Each time (it has been a few days) I run the page, I get same IP address ( to be displayed in the error message. The same address is allow-listed by the DB hosting company. Does that mean that the IP displayed is different than the one from which request sent?
Also, they don’t get any connection request from the same IP: “The IP address is already allowed on our PostgreSQL configuration file. Also, the errors are not logging on our end regarding this connection.”
I asked the hosting company to see if there are requests from other IP addresses to confirm if the problem is exactly how you described and not anything from my side.

Streamlit Community Cloud doesn’t necessarily use consistent outbound IP addresses – I would assume that’s the cause of the issue you’re seeing, but unfortunately I can’t say that with 100% certainty

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.