Currently, I have finished a web app that is using Postgresql as the database queries information from the db on one of my pages. This feature works locally. When I deployed my web app to streamlit-cloud I made sure to connect my PostgreSQL server to a Google Cloud PostgreSQL server instance. I used my GCP instance information for the secrets.toml file wherein my secrets.toml looks like this:
[postgres]
host = "my public ip address from GCP server instance"
port = 5432
dbname = "postgres"
user = "postgres"
password = "my GCP server instance password"
### Steps to reproduce
Am I setting up my secrets.toml file wrong for production? I know the dbname, user password are correct (since it works locally), but not as sure about the port or host to utilize the GCP server instance that’s connected to my PostgreSQL database. Expected behavior:
I expect that my deployed app on streamlit cloud should be able to connect to the google cloud server instance connected to my PostgreSQL database and query from the database like the web app does locally.
Actual behavior:
When the deployed app tries to query from the database it errors instead.
Error: psycopg2.OperationalError: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs (if you're on Streamlit Cloud, click on 'Manage app' in the lower right of your app).
Original Error:
psycopg2.OperationalError: connection to server at
"host(my public ip address from GCP server instance) ", port 5432 failed:
Connection timed out
Is the server running on that host and accepting TCP/IP connections?
So it seems that there may need to be authorization of IP address for apps to access the database on the Google Cloud platform. Particularly, Google Cloud seems to have an in-depth coverage on how to access the database instance using a public IP or private IP as well as using authorized networks for whitelisting access to the database.
Please explore more in the suggested resources from Google Cloud:
Hi I read the documentation and I’m still currently stuck on how to utilize GCSQL with my deployed app on streamlit community cloud. Could you help me troubleshoot my issue? I’ll detail some of the steps I’ve followed thus far I must be missing something but I am not familiar with networking so I’m a little lost.
Set up GoogleCloudSQL server instance with PostgreSQL DB in pgadmin4
1a. Utilized the public IP address as the Host name/address
1b. Made sure in pgadmin4 that i could query from the data (successful)
Set up private IP address for GCSQL server instance (From what I read this is needed to allow my web app that is deployed on streamlit cloud to access the server might be incorrect on this assumption)
2a. To set up private IP address had to set up VPC network for it (not exactly sure about this process either)
Tried utilizing my private IP address given by GCSQL inside my .secrets file for host and for my PostgreSQL database however I still run into the same error but this time even locally I cannot connect to the private IP address. When I utilize the public IP address given by GCSQL I am able to connect locally but not through my deployed app.
I tried researching about how to utilize GCSQL sever instances however I’m still confused on how to configure the settings (which ip address to use public or private?) to allow the deployed streamlit clout web app to access the SQL server on Google Cloud.
As to why I can connect locally to the server instance using the public ip address I’m assuming its because I added the ip address of my machine to the Authorized networks. I’m still lost on how to setup the networking but did I miss any important steps to help me connect my app to GCSQL?
I was able to fix the issue by adding 0.0.0.0/0 (should allow any ipv4 address to access the deployed website) to authorized public IP addresses inside the google cloud SQL sever instance.
From what I’ve read you shouldn’t do this however I couldn’t get the VPC and private IP address configuration to work even though it had the same 0.0.0.0/0 allowance.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.