In this post, you are going to create a Cloud SQL for PostgreSQL in Google Cloud Platform and connect it to Compute Engine VM Instance.

Prerequisites

  1. Your Compute Engine Instance is setup and running.
  2. For setting up Compute Engine, see the Setting up Compute Engine Instance.
  3. Domain name is pointed to your virtual machine.
  4. For setting up Cloud DNS, see the Setting up Google Cloud DNS for your domain.

Creating a Second Generation instance

  1. Go to Storage >> Cloud SQL in GCP console.
  2. Click Create Instance.
  3. Select PostgreSQL and click next.
  4. Enter instance name (recommended to use your domain name without the .com or .co.eu extension).
  5. Enter the password for the default user and copy it safe.
  6. Set the region for your PostgreSQL instance the same as you set in your Compute Engine VM Instance.
Create PostgreSQL Instance

Under Configuration options update the following

  1. Click set Connectivity, and under Authorized Networks click Add Networks.
  2. Enter the name in the Name field (this is optional).
  3. Enter your Compute Engine Instance IP address in the Network field.
  4. Click Done.

This setting will authorize your Compute Engine VM Instance to connect to this Cloud SQL Instance.

Connect VM Instance to Cloud SQL

Click Configure machine type and storage and choose Micro Instance

Choose SSD in Storage type

Leave everything to default and click create.

It will take some time to create a new Cloud SQL instance.

Creating a database and a user

Once your instance is created click on the instance name to view all details of the instance.

Here in the Overview tab, you can find the Public IP address in the Connect to this instance.

This IP address is the PostgreSQL hostname you need to provide while setting up your application.

PostgreSQL instance details

Now click on the Database tab and create a new database by clicking the Create Database button.

Conclusion

Now you have created a new Cloud SQL instance for PostgreSQL on Google Cloud Platform and connected it with the Compute Engine Instance.

Write A Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Where Writing Meets Entrepreneurship!

Get FREE Google Cloud Tutorials.
GET NOW
close-link
Please help us get 1000 likes in Facebook. Thank You!
LIKE NOW

Stay Connected!

Get latest tutorials on Google Cloud and Open Source topics
SUBSCRIBE
close-link