Connecting to GCP’s Cloud SQL (PostgresSQL) from PgAdmin — 3 simple steps
Goal : Connecting GCP’s Cloud SQL (PostgresSQL) from local PgAdmin
Steps :
- Set-up GCP and Create Database instance on GCP
- Install PgAdmin on your local computer
- Connect to Database Instance from PgAdmin
Step 1: Set-up GCP and Create Database instance & Database on GCP
Goto “https://cloud.google.com” and sign-in using your Google credentials.
Click on “console” and you will see the console as below :
Click on the hamburger icon on the top left and click on “SQL” on the left nav bar:
Create “Instance” by clicking on “Create Instance” button as below
Select “PostgreSQL”
Enter your preferred name for the instance (here I gave “gcspshiva-demo”) and make sure you create the password and please remember the same. This password is for user “postgres” by default. Later, you may create users based on your needs:
Creating instance takes sometime (2–3 mins) — time to get a quick coffee :-)
STEP 2: Install PgAdmin on your computer
Goto “https://www.pgadmin.org/download/”
and select your operating system and download PgAdmin
STEP 3: Connect to Database Instance from PgAdmin
Open PgAdmin on your computer
Click on Servers → Create → Server
Give a name to this new connection. Name can be any of your preferred name.
Note the host name OR IP Address & password from GCP as below (click on “SQL” to see the instance details:
Add instance IP address and the password (you noted while creating the instance) and click “save”
You will see below error :
To solve the above issue, go to “https://whatismyipaddress.com/” and note your IP address
Go back to GCP and click on the instance → connections
then click on “add network” and you will get below form and enter the your local computer IP address as below. Name is optional. Once done, press “save”
Go back to you PgAdmin on your computer and try connecting again.
Hurraayyyyy….now connected.
Now, you can create databases, tables etc etc using PgAdmin tool
Congratulations !