Run a Postgres Database for Free in Google Cloud!
Vložit
- čas přidán 22. 08. 2024
- Learn how to run a Postgres Database in Google Cloud for free using a Virtual Machine in Compute Engine. In this video I show how to run the database using Docker, making it quick and easy to stand up the database.
This is intended only for small test projects or proof of concepts. Anything bigger should use Cloud SQL or a much larger VM.
Be sure to always check Google Cloud's Free tier docs to make sure nothing has changed and the VM is still free!
GCP free tier docs: cloud.google.c...
Docker Engine install docs: docs.docker.co...
Follow me on social media!
Twitter: / scriptbytesio
Instagram: / scriptbytes
Thank you so much, man. I used your video to host my first ever Docker container for a job interview challenge. Hopefully they'll think it's pretty cool!
Oh that’s awesome! I’m glad this helped.
Good luck, I hope you get the job!
God Bless you sir! I've been trying to do it for 4 days. I did it thanks to you! Thank you a lot :)
You’re welcome! I’m glad it helped!
You might consider a playlist series "GCP for beginner", it's difficult to find any decent content to learn GCP as a beginner. Thanks for this video.
Great suggestion! Thanks for watching.
Great video! So helpful worked right away.
Thank you. For reference, the order in which you type the docker flag commands is important, ie putting the port after postgres will throw an error
Nice tutorial. Thank you!
Thanks for watching!
I did everything listed in the video, but i cannot connect to the db via dbeaver client (i'm getting request time out).
I tried checking stuff with chatgpt (all settings are correct, i can ping the external ip, i can connect to the db via GC's shell .. but not from dbeaver. I'm on Mac (drivers were installed). I'm stuck
Thank you kind Sir
You’re welcome, thanks for watching!
getting this error when i try to connect
Connection to refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
Connection refused: connect
Connection refused: connect
Hard to tell without seeing it, might check that the ports are mapped correctly in the docker run command?
hi! I'm guessing you made the same mistake I did. check the database creation command, you must indicate the port 5432:5432. if you don't, you will get that error. check the video at minute 6:44.
@@MrLESPERGUER I have same problem how to fix that ? thank
What would you recommend for production?
After stopping and starting my VM instance, i get the "Connection to refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections."
Was working fine before I stopped my instance last night, any solutions?
Edit: If i setup a new docker container it allows the connection through. Do I have to setup a new container everytime?
You have to restart the container after the vm is restarted.
thanks sir
Thanks so much for this tutorial. I've created the 5432 firewall rule, added the appropriate network tag to the VM, and started the postgres docker with port 5432 forwarded from the docker to the vm. The connection times out whenever I try to connect. Do you have any suggestions for where I should start troubleshooting?
I ended up solving it by putting all my cloud run components on the same vpc network. Thanks again for the very informative video!
Glad you got it working!
What is the reason why Its not good for production?
I should have clarified that better, that's related more to the size of the server. Also you do have to manage backups and server upgrades/updates yourself.
Another option would be Cloud SQL, which is a fully managed service on GCP.
@@scriptbytes cloud sql is not free?
@@rmcf3972 Unfortunately they don't offer a free tier for Cloud SQL. The smallest Postgres database is going to be around $10/mo or so.
Awesome 👍
excellent
postgres-db:~$ sudo apt-get install lab-release
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package lab-release
I cant find lab-release. please help . and also please share the commands that you did afterwards
All the commands I used were straight from the docker installation docs link in the description. However it does look like things have changed since this video and the commands are different.
I would reference the docs for that section of the video and hopefully that will get it working for you.
Is it possible to do all of this same process but with mySQL?
It should be doable as long as you substitute the correct docker commands
Hey... How can I use the this IP address to connect with a backend on on my laptop ... I want to set this up in the .env and use the remote postgres database
You can use the External IP address of the server as the hostname in your connection. So for example in a .Net API, the connection string format would look like this:
Host=1.2.3.4;Port=5432;Database=YourDatabaseName;Username=UserName;Password=Password123
@@scriptbytes I think we will need to setup a local socket sql connection right? We can do that using cloud_sql_proxy. Example, after installing cloud_sql_proxy, run the following command: cloud_sql_proxy -instances=example-project-dev:us-central1:example-db-name=tcp:5432. Then we can include credentials in the app connection string
Hey sir.
I've had my database up and running for 4 days now i think.
When i go to billing it says it has costed me 19 usd now.
Am i doing anything wrong?
It seems like that it is cloud sql that costs
$19 in 4 days sounds like it’s a larger server config. Might check that.
Ya if you decide to use cloud sql there is a cost. There’s no free tier for cloud sql unfortunately.
Hi, there is an info that the cost of instance is about $6. So it is not entirely for free?
If you only have 1 VM running, and it fits all the criteria, it's free. It shows the cost on the setup screen but it's free if it meets the free tier criteria.
@@scriptbytes Cool Thanks for clarification.
Why did you make boot disk 20GB? Why not the bare minimum or the maximum?
No reason in particular. Mostly just to show how to do it in case you’d need to go bigger or smaller.
@@scriptbytes If I set the boot disk setting here too high does that mean I lose out on space for my data? Assuming I want to stay within the 30GB max free tier.
@@River-iw1og No, the boot disk in this case is the only disk, so it's just the total amount of space available for your server.
The higher the setting here the more space you have for everything on the server.
It works! Thanks. But i have an issue. Google cloud has blocked my postgres db by two times :( They've said that my project doing crypto mining.
I've tried to do like in a video
Sorry I dunno how to help with that.
had the same problem. some official postgres docker images have kinsing malware. if you run 'top' command and see kdevtmpfsi
Will I be charged for the external ip address?
No, it mentions that in the free tier docs page:
cloud.google.com/free/docs/free-cloud-features#compute
"Compute Engine free tier does not charge for an external IP address."