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
- Your Compute Engine Instance is setup and running.
- For setting up Compute Engine, see the Setting up Compute Engine Instance.
- Domain name is pointed to your virtual machine.
- For setting up Cloud DNS, see the Setting up Google Cloud DNS for your domain.
Get your Professional Google Cloud Architect certificate with this easy to learn course now.
Creating a Second Generation instance
- Go to Storage >> Cloud SQL in GCP console.
- Click Create Instance.
- Select PostgreSQL and click next.
- Enter instance name (recommended to use your domain name without the .com or .co.eu extension).
- Enter the password for the default user and copy it safe.
- Set the region for your PostgreSQL instance the same as you set in your Compute Engine VM Instance.

Under Configuration options update the following
- Click set Connectivity, and under Authorized Networks click Add Networks.
- Enter the
name
in the Name field (this is optional). - Enter your
Compute Engine Instance IP address
in the Network field. - Click Done.
This setting will authorize your Compute Engine VM Instance to connect to this Cloud SQL Instance.

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.

Now click on the Database tab and create a new database by clicking the Create Database button.
Get your Professional Google Cloud Architect certificate with this easy to learn course now.
Conclusion
Now you have created a new Cloud SQL instance for PostgreSQL on Google Cloud Platform and connected it with the Compute Engine Instance.