Run a Postgres Database for Free in Google Cloud!

Run a Postgres Database for Free in Google Cloud!

Running a Postgres Database in Google Cloud for Free

In this video, the speaker explains how to set up a virtual machine using Compute Engine in Google Cloud to run a Postgres database for free. The speaker emphasizes that this is only suitable for development projects and small proof of concepts.

Setting Up Firewall Rule

  • To allow traffic to come in on TCP Port 5432, create a firewall rule.
  • Go to VPC Network > Firewall and create a new firewall rule.
  • Name the rule "allow postgres" and set the description as "allows postgres on Port 5432".
  • Choose the network (default).
  • Set direction of traffic as ingress and action as allow.
  • Allow traffic to specific instances with a tag on it.
  • Name the tag something that makes sense (e.g., allow TCP 5432).
  • Set source IP range as 0.0.0.0 to allow traffic from any IP.
  • Specify ports and only allow TCP by 432.

Creating Virtual Machine

  • Go to Compute Engine and create a new instance.
  • Name the instance (e.g., postgresdb).
  • Make sure that the region matches one of the regions in the free tier criteria.
  • Change machine type series to E2 micro.
  • Change boot disk to standard persistent disk with size less than 30 gigs.

Running Postgres Database Using Docker

  • Install Docker on your local machine if you haven't already done so.
  • SSH into your virtual machine using gcloud command-line tool or web-based SSH client provided by Google Cloud Console
  • Pull down an official Postgres image from Docker Hub
  • Run containerized Postgres image with port forwarding enabled

Conclusion

This video provides step-by-step instructions on how to set up a virtual machine using Compute Engine in Google Cloud Platform, allowing users to run a Postgres database for free. The speaker emphasizes that this is only suitable for development projects and small proof of concepts.

Creating a VM and Setting up Docker Engine

In this section, the speaker explains how to create a virtual machine (VM) and set up Docker engine.

Creating a VM

  • To create a VM, scroll down and click "create" after filling in the necessary information.
  • SSH into the server to set up Docker engine.

Setting up Docker Engine

  • Install Docker engine using the commands provided in Docker's documentation.
  • Run sudo apt-get update to ensure that the server is up-to-date.
  • Install required packages using sudo apt install.
  • Set up repositories for APT installer using sudo add-apt-repository.
  • Run sudo apt-get update again.
  • Install Docker and its dependencies using sudo apt install docker-ce.
  • Test if installation is successful by running docker run hello-world.

Setting Up Postgres Database with Docker

In this section, the speaker explains how to set up Postgres database with Docker.

Pulling Postgres Image

  • Pull latest version of Postgres image using sudo docker pull postgres.

Running Postgres Container

  • Run Postgres container using sudo docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres.
  • -e POSTGRES_PASSWORD=mysecretpassword sets password for logging in.
  • -d postgres specifies which image to use.

Connecting to Postgres Database

  • Use Azure Data Studio or any other tool to connect to external IP address of virtual machine on Port 5432.
  • Username is "postgres".
  • Password is what was used in the previous command (mysecretpassword).

Connecting to Azure Data Studio

In this section, the speaker demonstrates how to connect to Azure Data Studio.

Steps for connecting to Azure Data Studio

  • Open Azure Data Studio.
  • Click on "New Connection".
  • Enter the server name and authentication type.
  • Click on "Connect".

Warning about using this method for production databases

  • This method should not be used for production databases or anything that is very important. It's only suitable for small Dev projects and proof of concepts.

Conclusion

  • If you enjoyed the video, consider liking and subscribing. If there were any mistakes in the demonstration, let the speaker know in the comments.
Video description

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: https://cloud.google.com/free/docs/free-cloud-features#compute Docker Engine install docs: https://docs.docker.com/engine/install/debian/ Follow me on social media! Twitter: https://twitter.com/ScriptBytesIO Instagram: https://www.instagram.com/scriptbytes/