Hosting and connecting to a google cloud sql databse

Viewed 61

I'm currently building a website that I would like to privately host so it can only be used internally. My goal is to store file uploads into a google cloud bucket then document certain things into a cloud sql db for filtering later on.

I've been able to store and pull my files from a bucket and I was also able to set up my database in cloud sql however I'm not totally sure how to send SQL query's to my database from my website. I've tried going through the documentation but I'm a bit lost as to what I need. So if anyone knows what I should be looking at that would be a lot of help. Anything like a guide on the google documentation, because I'm not sure which I need to follow or anything.

Additional information

  • Currently my website is hosted locally because I haven't decided on a website hosting service yet any recommendations would be helpful.
  • I was using a postgres database as practice for creating endpoints and developing my database structure.
  • I am using a PERN stack so postgres, express, react and node.js

If there's anything else you would like specified I'm more then happy to provide any additional information.

Update:

I was able to connect my postgres db to cloudsql. I would explain how but this video does a great job of it.

How to connect psql db to cloud sql

However I'm running into an issue when I try to connect using an SSL connection. I have the files my only issue is I don't know where to store these files.

1 Answers

The general recommendation is to use the Cloud SQL Auth Proxy to connect to your Cloud SQL instance.

Basically you'd run the proxy wherever you're running your webapp and then have your webapp connect to the proxy as if it were a local database.

You'll start the proxy like this:

./cloudsql_auth_proxy -instances=<INSTANCE_CONNCECTION_NAME>=tcp:5432

That will start a listener on 5432 on localhost that you can connect your webapp to.

Alternatively, you could use Authorized Networks to allow-list the IP address of the machine where your app runs.

Check out the docs here: https://cloud.google.com/sql/docs/postgres/connect-overview.

Related