To create instance, select "+ CREATE INSTANCE" button then choose whatever you are going to create on Cloud SQL. In this case, needless to say, choose PostgresSQL.
Choose your instance info then "CREATE INSTANCE" then GCP starts to create the instance in a background.
"Password" is for the user name "postgres" which is a default created root user.
It will take 5 to 10 minutes.
After the instance was created, check the connection to it with Cloud SQL Auth Proxy from your local PC. This can be only when you create public IP. The detail of Cloud SQL Proxy, check here.
Run Cloud SQL Auth Proxy
First, the cloud sql auth proxy should be running on your local pc. The command is like that.
./cloud_sql_proxy -instances=<project-id>:<region>:<instance-id>=tcp:0.0.0.0:5432
Access to the PostgresSQL
Next, the command to access to the PostgresSQL on GCP Cloud SQL is
psql -U postgres — host 127.0.0.1
Password for user postgres:
Note: — is double hyphen.
passward for user postgres is the password which you register when creating the instance.
Add User
From User tab, a new user is created.
With Build-in authentication, a new user can be created so input Username and Password then "ADD". Easy.
Access to the PostgresSQL as a created new user
When you login PostgresSQL with the command,
psql -U <created-new-user-name> — host 127.0.0.1
this does not work.
The result should be like this,
psql: error: connection to server at “127.0.0.1”, port 5432 failed: FATAL: database “<created-new-user-name>” does not exist
When logging to a db as postgres, the db name is selected automatically as "postgres" and the database is created initially.
You can check it on "Databases" tab.
That is why, if you want to login the database whose name is "postgres" from your local pc through Cloud SQL Auth Proxy, the database name must be selected.
psql “host=127.0.0.1 sslmode=disable dbname=postgres user=<created-new-user-name>”
Password for user poc-user:
psql (14.1, server 13.4)
Type “help” for help.
postgres=>
Great! The access is successful.
In detail, check the above link to the GCP official documentation.