Connect to Cloud SQL for PostgreSQL from Compute Engine
Learn how to deploy a sample app on your Linux or Windows based Compute Engine VM instance connected to a PostgreSQL instance by using the Google Cloud console and a client application.
Assuming that you complete all the steps in a timely manner, the resources created in this quickstart typically cost less than one dollar (USD).
Before you begin
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Cloud APIs necessary to run a Cloud SQL sample app on a Compute Engine VM instance.
Click the Enable APIs button to enable the API required for this quickstart.
This enables the following API:
- Cloud SQL Admin API
Install the gcloud CLI which provides command-line access to your Google Cloud resources. The gcloud CLI is used to run the
gcloud CLI
commands presented throughout this quickstart. All the commands are formatted to be run in a terminal or a Powershell window.Run the following
gcloud
command:gcloud services enable sqladmin.googleapis.com
This command enables the following API:
- Cloud SQL Admin API
Set up Cloud SQL
Create a Cloud SQL instance
Public IP
Create an instance with a public IP address
-
In the Google Cloud console, go to the Cloud SQL Instances page.
- Click Create instance.
- Click PostgreSQL.
- In the Instance ID field, enter
quickstart-instance
. - In the Password field, enter a password for the postgres user. Save this password for future use.
- In the Choose region and zonal availability section, select Single zone.
- Expand the Show Configurations section.
- In the Machine Type drop-down list, select Lightweight.
- Click Create Instance and then wait until the instance initializes and starts.
Create an instance with a public IP address
Before running the gcloud sql instances create
command as follows, replace DB_ROOT_PASSWORD with the password of your database user.
Optionally, modify the values for the following parameters:
- --database_version: The database engine type and version. If left unspecified, the API default is used. See the gcloud database versions documentation to see the currently available versions.
- --cpu: The number of cores desired in the machine.
- --memory: Whole number value indicating how much memory is desired in the machine. A size unit should be provided (for example, 3072MB or 9GB). If no units are specified, GB is assumed.
- --region: Regional location of the instance
(for example asia-east1, us-east1). If left unspecified, the default
us-central
is used. See the full list of regions.
Run the gcloud
sql instances create
command to create a Cloud SQL instance.
gcloud sql instances createquickstart-instance --database-version=POSTGRES_13 --cpu=1 --memory=4GB --region=us-central --root-password=DB_ROOT_PASSWORD
Private IP
Allocate an IP address range and create a private connection to configure private services access for Cloud SQL
-
In the Google Cloud console, go to the VPC networks page.
- Select the
default
VPC network. - Select the Private service connection tab.
- Select the Allocated IP ranges for services tab.
- Click Allocate IP range.
- For the Name of the allocated range, specify
google-managed-services-default
. - Select the Automatic option for IP range and specify the prefix length as
16
. - Click Allocate to create the allocated range.
- Select the Private connections to services tab for the
default
VPC network. - Click Create connection to create a private connection between your network and a service producer.
- For the Assigned allocation, select
google-managed-services-default
. - Click Connect to create the connection.
Create an instance with private IP address and SSL enabled
-
In the Google Cloud console, go to the Cloud SQL Instances page.
- Click Create instance.
- Click PostgreSQL.
- Enter
quickstart-instance
for Instance ID. - Enter a password for the postgres user. Save this password for future use.
- Click the Single zone option for Choose region and zonal availability.
- Click and expand Show configuration options.
- For Machine Type, select Lightweight.
- In Connections, select Private IP.
- Select default in the Network drop-down menu.
- Clear the Public IP checkbox to create an instance only with a private IP.
- Click Create instance and then wait for the instance to initialize and start.
- Click Connections.
- In the Security section, select Allow only SSL connections to enable SSL connections.
- In the Allow only SSL connections dialog, click Save and then wait for the instance to restart.
Allocate an IP address range and create a private connection to configure private services access for Cloud SQL
-
Run the
gcloud compute addresses create
command to allocate an IP address range.gcloud compute addresses create
google-managed-services-default --global --purpose=VPC_PEERING --prefix-length=16 --description="peering range for Google" --network=default -
Run the
gcloud services vpc-peerings connect
command to create a private connection to the allocated IP address range. Replace YOUR_PROJECT_ID with your project's project ID.gcloud services vpc-peerings connect --service=servicenetworking.googleapis.com --ranges=
google-managed-services-default --network=default --project=YOUR_PROJECT_ID
Create an instance with private IP address and SSL enabled
-
Before running the command as follows, replace DB_ROOT_PASSWORD with the password of your database user.
- --database_version: The database engine type and version. If left unspecified, the API default is used. See the gcloud database versions documentation to see the currently available versions.
- --cpu: The number of cores in the machine.
- --memory: A whole number value indicating how much memory to include in the machine. A size unit can be provided (for example, 3072MB or 9GB). If no units are specified, GB is assumed.
- --region: The regional location of the instance
(for example asia-east1, us-east1). If left unspecified, the default
us-central1
is used. See the full list of regions. Run the
gcloud sql instances patch
command to enable only allow SSL connections for the instance.
Optionally, modify the values for the following parameters:
Run the gcloud
sql instances create
command to create a Cloud SQL instance with a Private IP address.
gcloud beta sql instances createquickstart-instance --database-version=POSTGRES_13 --cpu=1 --memory=4GB --region=us-central --root-password=DB_ROOT_PASSWORD --no-assign-ip --network=default
gcloud sql instances patchquickstart-instance --require-ssl
Create a database
-
In the Google Cloud console, go to the Cloud SQL Instances page.
- Select
quickstart-instance
. - Open the Databases tab.
- Click Create database.
- In the New database dialog box, enter
quickstart_db
as the name of the database.
- Click Create.
Run the gcloud
sql databases create
command to create a database.
gcloud sql databases createquickstart_db --instance=quickstart-instance
Create a user
-
In the Google Cloud console, go to the Cloud SQL Instances page.
- To open the Overview page of an instance, click the instance name.
- Select Users from the SQL navigation menu.
- Click Add user account.
- On the Add a user account to instance instance_name page,
add the following information:
- In the Username field, enter
quickstart-user
- In the Password field, specify a password for your database user. Make a note of this for use in a later step of this quickstart.
- In the Username field, enter
- Click Add.
Before running the following command, make the following replacements:
- PASSWORD with a password for your database user. Make a note of this for use in a later step of this quickstart.
Run the gcloud sql users create
command to create the user.
gcloud sql users createquickstart-user --instance=quickstart-instance --password=PASSWORD
User name length limits are the same for Cloud SQL as for on-premises PostgreSQL.
Configure a Compute Engine service account
Create a service account
- In the Google Cloud console, go to the Create service account page.
- Select a Google Cloud project.
- Enter a
quickstart-service-account
as the service account name. - Optional: Enter a description of the service account.
- Click Create and continue and continue to the next step.
- Choose the Cloud SQL Client role to grant to the service account on the project.
- Click Add another role and choose the Storage Object Viewer role to grant to the service account on the project.
- Click Continue.
- Click Done to finish creating the service account.
Create a service account
- To create the service account, run the
gcloud iam service-accounts create
command: DESCRIPTION
: an optional description of the service account- To grant your service account the Cloud SQL Client role
and the Storage Object Viewer role on your project, run the
gcloud projects add-iam-policy-binding
command. Replace PROJECT_ID with your Google Cloud project ID:gcloud projects add-iam-policy-binding
PROJECT_ID --member="serviceAccount:quickstart-service-account@PROJECT_ID .iam.gserviceaccount.com" --role="roles/cloudsql.client" --role="roles/storage.objectViewer"
gcloud iam service-accounts create quickstart-service-account --description="DESCRIPTION " --display-name="quickstart-service-account "
Replace the following value:
Create Compute Engine VM instance
Create a Compute Engine VM Instance to host a sample web app that connects to Cloud SQL.
Create a Linux VM Instance
-
In the Google Cloud console, go to the VM instances page.
- Click the Create instance button.
- For VM instance Name enter
quickstart-vm-instance
. - For Service accounts select
quickstart-service-account
. - For Firewall select the Allow HTTP traffic option.
- Click Create to create the VM instance.
Before running the following command, replace YOUR_PROJECT_ID with your project ID.
Run the following gcloud compute instances create
command.
gcloud compute instances createquickstart-vm-instance --image-family=debian-10 --image-project=debian-cloud --machine-type=e2-medium --service-account=quickstart-service-account@YOUR_PROJECT_ID .iam.gserviceaccount.com --scopes=https://www.googleapis.com/auth/cloud-platform --tags=http-server --zone=us-central1-a
Create a Windows VM Instance
-
In the Google Cloud console, go to the VM instances page.
- Click the Create instance button.
- For VM instance Name enter
quickstart-vm-instance
. - For Boot disc click the Change button.
- For Operating system select Windows Server.
- For Version select Windows Server 2022 Datacenter.
- Click the Select button.
- For Service accounts select
quickstart-service-account
. - For Firewall select the Allow HTTP traffic option.
- Click Create to create the VM instance.
- After 2-3 minutes once the VM instance has started, click the Set Windows Password button on the VM instance details page.
- Copy and save this password in a secure location as you will be using it to access your VM instance in the next step of this quickstart.
Before running the following command, replace YOUR_PROJECT_ID with your project ID.
Run the following gcloud compute instances create
command in a Terminal Window.
gcloud compute instances createquickstart-vm-instance --image-project=windows-cloud --image-family=windows-2022 --machine-type=e2-medium --service-account=quickstart-service-account@YOUR_PROJECT_ID .iam.gserviceaccount.com --scopes=https://www.googleapis.com/auth/cloud-platform --tags=http-server --zone=us-central1-a
After 2-3 minutes once the VM instance has started, run the following command to set the Windows password on the VM instance.
gcloud compute reset-windows-passwordquickstart-vm-instance
Copy and save this password in a secure location as you will be using it to access your VM instance in the next step of this quickstart.
Access Compute Engine VM instance
Access Linux VM Instance
Note: When you connect to VMs using the Google Cloud console, Compute Engine creates an ephemeral SSH key for you. For more information about SSH keys, see SSH connections to Linux VMs
Use the
gcloud compute ssh
command to connect
to a Linux VM instance. Replace YOUR_PROJECT_ID with your project ID:
gcloud compute ssh --project=YOUR_PROJECT_ID --zone=us-central1-a quickstart-vm-instance
Access Windows VM Instance
Chrome RDP for Google Cloud is a third-party plugin that lets you connect to Windows instances by using the Chrome browser. The plugin is integrated with the Google Cloud console. After you install the plugin, connect to any Windows Server instance by using the RDP button in the Google Cloud console .
To connect using the Chrome RDP plugin, do the following:
- Install the Chrome RDP for Google Cloud extension.
- In Google Cloud console, go to the VM instances page and find the Windows instance you want to connect to.
- Click the RDP button for the instance you want to connect to. The Chrome RDP extension opens.
- Since your VM instance does not have a domain configured, you can leave the Domain field blank
- Enter your username, and password, and click OK to connect.
- If prompted, press Continue to accept the certificate.

See Connect to Windows VMs using RDP for more options for accessing a Compute Engine Windows VM instance.
Setup development environment for programming language
Set up the Compute Engine VM instance's development environment for your preferred programming language.
Setup Linux VM Instance development environment
Complete the following steps to set up the Compute Engine VM instance's development environment to run the Go sample app.
- Go to the setup guide for a Go development environment.
- Complete the instructions in the Install Go section.
Complete the following steps to set up the Compute Engine VM instance's development environment to run the Java sample app.
- Go to the setup guide for a Java development environment.
- Complete the instructions in the Install a JDK (Java Development Kit) section.
- Complete the instructions in the Install a build automation tool to set up Apache Maven.
Complete the following steps to set up the Compute Engine VM instance's development environment to run the Node.js sample app.
- Go to setup guide for a Node.js development environment.
- Complete the instructions in the Installing Node.js and npm section.
Complete the following steps to set up the Compute Engine VM instance's development environment to run the Python sample app.
- Go to setup guide for a Python development environment.
- Complete the instructions in the Installing Python section.
Setup Windows VM Instance development environment
Complete the following steps to set up the Compute Engine VM instance's development environment to run the Go sample app.
- Go to the setup guide for a Go development environment.
- Complete the instructions in the Install Go section.
Complete the following steps to set up the Compute Engine VM instance's development environment to run the Java sample app.
- Go to the setup guide for a Java development environment.
- Complete the instructions in the Install a JDK (Java Development Kit) section.
- Complete the instructions in the Install a build automation tool section to set up Apache Maven.
Complete the following steps to set up the Compute Engine VM instance's development environment to run the Node.js sample app.
- Go to setup guide for a Node.js development environment.
- Complete the instructions in the Installing Node.js and npm section.
Complete the following steps to set up the Compute Engine VM instance's development environment to run the Python sample app.
- Install Python and the PIP package manager for Python.
- Go to setup guide for a Python development environment.
- Complete the instructions in the Installing Python section.
- The instructions above will have you visit the Python Releases for Windows download page. From that page click the Latest Python 3 Release link.
- On the Python 3.X.X page, click the Windows Installer 64-bit link to download the installer file to your Windows Compute Engine VM instance.
- Once you've downloaded the Python installer to the VM instance, open the folder containing the downloaded file. Then right click on the installer file and select Run as administrator.
- In the Install Python dialog that appears, select the option to Add Python 3.X.X to PATH and click → Install Now.
- Use PIP to install virtualenv.
- Open Powershell on the Windows Compute Engine VM instance and
run the following
pip install
command.
pip install virtualenv
Install Git
Install Git, an open source version control system on to your Compute Engine VM instance.
Compute Engine Linux VM instance
On your Compute Engine Linux VM instance, follow the official Git installation documentation for Linux.
- Run the suggested Debian/Ubuntu
install git
command using thesudo
command prefix to run the command as an administrator. The full installation command to run in the terminal should be formatted as follows:
sudo apt-get install git
Compute Engine Windows VM instance
On your Compute Engine Windows VM instance, follow the official Git installation documentation for Windows to download the 64-bit Standalone Installer and run it to install Git.
Clone sample app
Clone a sample app to your Compute Engine VM instance using the git clone
command.
On your Compute Engine VM instance, open a new terminal or Powershell window. Run the following commands to clone the Go sample app and change the directory to the directory containing the sample app.
-
Clone the sample app.
git clone https://github.com/GoogleCloudPlatform/golang-samples
-
Change directory to the directory containing the sample app.
cd golang-samples/cloudsql/postgres/database-sql
On your Compute Engine VM instance, open a new terminal or Powershell window. Run the following commands to clone the Java sample app and change the directory to the directory containing the sample app.
-
Clone the sample app.
git clone https://github.com/GoogleCloudPlatform/java-docs-samples
-
Change directory to the directory containing the sample app.
cd java-docs-samples/cloud-sql/postgres/servlet
On your Compute Engine VM instance, open a new terminal or Powershell window. Run the following commands to clone the Node.js sample app and change the directory to the directory containing the sample app.
-
Clone the sample app.
git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples
-
Change directory to the directory containing the sample app.
cd nodejs-docs-samples/cloud-sql/postgres/knex
On your Compute Engine VM instance, open a new terminal or Powershell window. Run the following commands to clone the Python sample app and change the directory to the directory containing the sample app.
-
Clone the sample app.
git clone https://github.com/GoogleCloudPlatform/python-docs-samples
-
Change directory to the directory containing the sample app.
cd python-docs-samples/cloud-sql/postgres/sqlalchemy
Configure and run a Cloud SQL sample app
With a Cloud SQL instance, database, and service account with client permissions, you can now configure a sample application running on your Compute Engine VM instance to connect to your Cloud SQL instance.
Public IP Cloud SQL Instance and Linux based Compute Engine VM
On the Compute Engine VM instance in the open terminal, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacements:
- INSTANCE_CONNECTION_NAME with your instance's Connection name that appears on the Cloud SQL instances page in the Google Cloud console.
- YOUR_DB_PASSWORD with the password of the
quickstart-user
that you created in the previous Create a user quickstart step.
export INSTANCE_CONNECTION_NAME='INSTANCE_CONNECTION_NAME ' export DB_PORT='5432' export DB_NAME='quickstart_db ' export DB_USER='quickstart-user ' export DB_PASS='YOUR_DB_PASSWORD '
On the Compute Engine VM instance in the open terminal, run the following commands to get the Go sample app's dependencies on to your Compute Engine VM instance and run the sample app.
-
Get the dependencies required to run to sample app.
go get ./...
-
Run the sample app.
go run cmd/app/main.go
On your local computer get the Compute Engine VM instance's external IP address where the sample app is running and view it in a browser.
- In a terminal or in Powershell on your local computer, get the Compute Engine VM instance's external IP address by running the
following
gcloud compute instances describe
command: -
View the running sample app. Open a browser on your local computer and go to
the Compute Engine VM instance's external IP address and port :8080.
http://
COMPUTE_ENGINE_VM_EXTERNAL_IP_ADDRESS :8080
gcloud compute instances describequickstart-vm-instance --format="value(networkInterfaces[0].accessConfigs[].natIP)"
To stop the sample app, press Control+C in the Compute Engine VM instance terminal where you started the sample app.
On the Compute Engine VM instance in the open terminal, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacements:
- INSTANCE_CONNECTION_NAME with your instance's Connection name that appears on the Cloud SQL instances page in the Google Cloud console.
- YOUR_DB_PASSWORD with the password of the
quickstart-user
that you created in the previous Create a user quickstart step.
export INSTANCE_CONNECTION_NAME='INSTANCE_CONNECTION_NAME ' export DB_PORT='5432' export DB_NAME='quickstart_db ' export DB_USER='quickstart-user ' export DB_PASS='YOUR_DB_PASSWORD '
On the Compute Engine VM instance in the open terminal, run the following command to get the Java sample app's dependencies on to your Compute Engine VM instance and run the sample app.
mvn jetty:run
On your local computer get the Compute Engine VM instance's external IP address where the sample app is running and view it in a browser.
- In a terminal or in Powershell on your local computer, get the Compute Engine VM instance's external IP address by running the
following
gcloud compute instances describe
command: -
View the running sample app. Open a browser on your local computer and go to
the Compute Engine VM instance's external IP address and port :8080.
http://
COMPUTE_ENGINE_VM_EXTERNAL_IP_ADDRESS :8080
gcloud compute instances describequickstart-vm-instance --format="value(networkInterfaces[0].accessConfigs[].natIP)"
To stop the sample app, press Control+C in the Compute Engine VM instance terminal where you started the sample app.
-
On the Compute Engine VM instance in the open terminal, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacement:
- YOUR_DB_PASSWORD with the password of the
quickstart-user
that you created in the previous Create a user quickstart step.
export INSTANCE_HOST='127.0.0.1' export DB_PORT='5432' export DB_NAME='
quickstart_db ' export DB_USER='quickstart-user ' export DB_PASS='YOUR_DB_PASSWORD ' - YOUR_DB_PASSWORD with the password of the
- Download the Cloud SQL Auth Proxy.
curl -o cloud-sql-proxy \ https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.0.0/cloud-sql-proxy.linux.amd64
- Set permissions to make the Cloud SQL Auth Proxy file executable.
chmod +x cloud-sql-proxy
- Run the Cloud SQL Auth Proxy as a background process. Replace INSTANCE_CONNECTION_NAME with your
instance's Connection name that appears on the Cloud SQL instances page in the Google Cloud console.
./cloud-sql-proxy
INSTANCE_CONNECTION_NAME &
On the Compute Engine VM instance in the open terminal, run the following commands to get the required Node.js packages on to your Compute Engine VM instance and run the sample app.
-
Install the Node.js packages necessary to run the app locally.
npm install
-
Run the sample app.
npm start
On your local computer get the Compute Engine VM instance's external IP address where the sample app is running and view it in a browser.
- In a terminal or in Powershell on your local computer, get the Compute Engine VM instance's external IP address by running the
following
gcloud compute instances describe
command: -
View the running sample app. Open a browser on your local computer and go to
the Compute Engine VM instance's external IP address and port :8080.
http://
COMPUTE_ENGINE_VM_EXTERNAL_IP_ADDRESS :8080
gcloud compute instances describequickstart-vm-instance --format="value(networkInterfaces[0].accessConfigs[].natIP)"
To stop the sample app, press Control+C in the Compute Engine VM instance terminal where you started the sample app.
On the Compute Engine VM instance in the open terminal, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacements:
- INSTANCE_CONNECTION_NAME with your instance's Connection name that appears on the Cloud SQL instances page in the Google Cloud console.
- YOUR_DB_PASSWORD with the password of the
quickstart-user
that you created in the previous Create a user quickstart step.
export INSTANCE_CONNECTION_NAME='INSTANCE_CONNECTION_NAME ' export DB_PORT='5432' export DB_NAME='quickstart_db ' export DB_USER='quickstart-user ' export DB_PASS='YOUR_DB_PASSWORD '
On the Compute Engine VM instance in the open terminal, run the following commands to get the Python sample app's requirements on to your Compute Engine VM instance and run the sample app.
-
Initialize a virtual environment and install the requirements to run to sample app.
python3 -m venv env source env/bin/activate pip install -r requirements.txt
-
Run the sample app.
python app.py
On your local computer, set up port forwarding over SSH by performing the instructions in next quickstart step. This enables you to use a browser on your local computer to view the app running on your Compute Engine VM instance.
- In a terminal or in Powershell on your local computer, run the following
gcloud compute ssh
command to setup port forwarding over SSH. Before running the command, replace YOUR_PROJECT_ID with your project ID. -
View the running sample app. With port forwarding actively running,
open a browser on your local computer and enter
http://127.0.0.1:8000
in the address bar of your browser..
gcloud compute ssh quickstart-vm-instance --project=YOUR_PROJECT_ID --zone=us-central1-a --ssh-flag='-L 8000:127.0.0.1:8080'
To stop the sample app, press Control+C in the Compute Engine VM instance terminal where you started the sample app.
Public IP Cloud SQL Instance and Windows based Compute Engine VM
On the Compute Engine VM instance in the open Powershell window, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacements:
- INSTANCE_CONNECTION_NAME with your instance's Connection name that appears on the Cloud SQL instances page in the Google Cloud console.
- YOUR_DB_PASSWORD with the password of the
quickstart-user
that you created in the previous Create a user quickstart step.
$env:INSTANCE_CONNECTION_NAME="INSTANCE_CONNECTION_NAME " $env:DB_PORT="5432" $env:DB_NAME="quickstart_db " $env:DB_USER="quickstart-user " $env:DB_PASS="YOUR_DB_PASSWORD "
On the Compute Engine VM instance in the open Powershell window, run the following commands to get the Go sample app's dependencies on to your Compute Engine VM instance and run the sample app.
-
Get the dependencies required to run to sample app.
go get ./...
-
Run the sample app.
go run cmd\app\main.go
-
View the running sample app. Open a browser on the Compute Engine VM instance and go to
http://127.0.0.1:8080
.
To stop the sample app, press Control+C in the Compute Engine VM instance Powershell window where you started the sample app.
On the Compute Engine VM instance in the open Powershell window, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacements:
- INSTANCE_CONNECTION_NAME with your instance's Connection name that appears on the Cloud SQL instances page in the Google Cloud console.
- YOUR_DB_PASSWORD with the password of the
quickstart-user
that you created in the previous Create a user quickstart step.
$env:INSTANCE_CONNECTION_NAME="INSTANCE_CONNECTION_NAME " $env:DB_PORT="5432" $env:DB_NAME="quickstart_db " $env:DB_USER="quickstart-user " $env:DB_PASS="YOUR_DB_PASSWORD "
-
On the Compute Engine VM instance in the open Powershell window, run the following command to get the Java sample app's dependencies on to your Compute Engine VM instance and run the sample app.
mvn jetty:run
-
View the running sample app. Open a browser on the Compute Engine VM instance and go to
http://127.0.0.1:8080
.
To stop the sample app, press Control+C in the Compute Engine VM instance Powershell window where you started the sample app.
-
On the Compute Engine VM instance in the open Powershell window, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacement:
- YOUR_DB_PASSWORD with the password of the
quickstart-user
that you created in the previous Create a user quickstart step.
$env:INSTANCE_HOST="127.0.0.1" $env:DB_PORT="5432" $env:DB_NAME="
quickstart_db " $env:DB_USER="quickstart-user " $env:DB_PASS="YOUR_DB_PASSWORD " - YOUR_DB_PASSWORD with the password of the
- Download the Cloud SQL Auth Proxy.
wget https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.0.0/cloud-sql-proxy.x64.exe ` -O cloud-sql-proxy.exe
- Run the Cloud SQL Auth Proxy as a background process. Replace INSTANCE_CONNECTION_NAME with your
instance's Connection name that appears on the Cloud SQL instances page in the Google Cloud console.
Start-Process -filepath ".\cloud-sql-proxy.exe" -ArgumentList ` "
INSTANCE_CONNECTION_NAME "
On the Compute Engine VM instance in the open Powershell window, run the following commands to get the required Node.js packages on to your Compute Engine VM instance and run the sample app.
-
Install the Node.js packages necessary to run the app locally.
npm install
-
Run the sample app.
npm start
-
View the running sample app. Open a browser on the Compute Engine VM instance and go to
http://127.0.0.1:8080
.
To stop the sample app, press Control+C in the Compute Engine VM instance Powershell window where you started the sample app.
On the Compute Engine VM instance in the open Powershell window, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacements:
- INSTANCE_CONNECTION_NAME with your instance's Connection name that appears on the Cloud SQL instances page in the Google Cloud console.
- YOUR_DB_PASSWORD with the password of the
quickstart-user
that you created in the previous Create a user quickstart step.
$env:INSTANCE_CONNECTION_NAME="INSTANCE_CONNECTION_NAME " $env:DB_PORT="5432" $env:DB_NAME="quickstart_db " $env:DB_USER="quickstart-user " $env:DB_PASS="YOUR_DB_PASSWORD "
On the Compute Engine VM instance in the open Powershell window, run the following commands to get the Python sample app's requirements on to your Compute Engine VM instance and run the sample app.
-
Initialize a virtual environment and install the requirements to run to sample app.
virtualenv --python python3 env .\env\Scripts\activate pip install -r requirements.txt
-
Run the sample app.
python app.py
-
View the running sample app. Open a browser on the Compute Engine VM instance and go to
http://127.0.0.1:8080
.
To stop the sample app, press Control+C in the Compute Engine VM instance Powershell window where you started the sample app.
Private IP Cloud SQL Instance and Linux based Compute Engine VM
Create and download SSL server and client certificates on to your local computer
-
In the Google Cloud console, go to the Cloud SQL Instances page.
- Click the
quickstart-instance
to see its Overview page - Click the Connections tab.
- Under the Security section, click Create client certificate.
- In the Create a client certificate dialog,
enter
quickstart-key
as the name and click Create. In the New SSL certificate created dialog, click each download link to download the certificates. Then, click Close.
Upload SSL certificates to Cloud Storage bucket
In a browser on your local computer, create a Cloud Storage bucket and upload SSL certificates to the bucket where they can then be accessed from the Compute Engine VM instance.
- Create a Cloud Storage bucket.
- For Name of your bucket, enter the following name. Replace
YOUR_PROJECT_ID with your project ID:
YOUR_PROJECT_ID -quickstart-certs - Click the Create button to create the bucket.
- Click the Upload Files button to upload files to the newly created Cloud Storage bucket.
- Select the following files to be uploaded from your local computer to Cloud Storage:
server-ca.pem
client-cert.pem
client-key.pem
On your local computer in a terminal or Powershell window open to the directory where you downloaded the SSL certificates, you can now create a Cloud Storage bucket and upload the SSL certificates to bucket where they can then be accessed from the Compute Engine VM instance. The gcloud CLI will be used to upload the files.
- Run the following
gcloud storage buckets create
command to make a new Cloud Storage bucket: - From the directory where you downloaded the certificates on your local computer,
run the following
gcloud storage cp
commands to copy the SSL certificates to the newly created Cloud Storage bucket:
gcloud storage buckets create gs://YOUR_PROJECT_ID -quickstart-certs --location=us-central1
gcloud storage cp server-ca.pem gs://YOUR_PROJECT_ID -quickstart-certs/ gcloud storage cp client-cert.pem gs://YOUR_PROJECT_ID -quickstart-certs/ gcloud storage cp client-key.pem gs://YOUR_PROJECT_ID -quickstart-certs/
Download SSL certificates using the gcloud CLI on the Compute Engine VM instance
On the Compute Engine VM instance in a terminal open to the golang-samples/cloudsql/postgres/database-sql
directory, run the following gcloud storage cp
commands
to download the SSL certificates from Cloud Storage to the certs
directory.
gcloud storage cp gs://YOUR_PROJECT_ID -quickstart-certs/server-ca.pem certs/. gcloud storage cp gs://YOUR_PROJECT_ID -quickstart-certs/client-cert.pem certs/. gcloud storage cp gs://YOUR_PROJECT_ID -quickstart-certs/client-key.pem certs/.
Set Environment Variables on the Compute Engine VM instance
On the Compute Engine VM instance in the open terminal, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacements:
- INSTANCE_HOST set to the Private IP address of your instance displayed on the Cloud SQL instances page in the Google Cloud console.
- YOUR_DB_PASSWORD with the password of the
quickstart-user
that you created in the previous Create a user quickstart step.
export INSTANCE_HOST='INSTANCE_HOST ' export DB_PORT='5432' export DB_NAME='quickstart_db ' export DB_USER='quickstart-user ' export DB_PASS='YOUR_DB_PASSWORD ' export DB_ROOT_CERT='certs/server-ca.pem' export DB_CERT='certs/client-cert.pem' export DB_KEY='certs/client-key.pem' export PRIVATE_IP='TRUE'
On the Compute Engine VM instance in the open terminal, run the following commands to get the Go sample app's dependencies on to your Compute Engine VM instance and run the sample app.
-
Get the dependencies required to run to sample app.
go get ./...
-
Run the sample app.
go run cmd/app/main.go
On your local computer get the Compute Engine VM instance's external IP address where the sample app is running and view it in a browser.
- In a terminal or in Powershell on your local computer, get the Compute Engine VM instance's external IP address by running the
following
gcloud compute instances describe
command: -
View the running sample app. Open a browser on your local computer and go to
the Compute Engine VM instance's external IP address and port :8080.
http://
COMPUTE_ENGINE_VM_EXTERNAL_IP_ADDRESS :8080
gcloud compute instances describequickstart-vm-instance --format="value(networkInterfaces[0].accessConfigs[].natIP)"
To stop the sample app, press Control+C in the Compute Engine VM instance terminal where you started the sample app.
Download SSL certificates using the gcloud CLI on the Compute Engine VM instance
On the Compute Engine VM instance in a terminal open to the java-docs-samples/cloud-sql/postgres/servlet
directory, run the following gcloud storage cp
commands
to download the SSL certificates from Cloud Storage to the current directory.
gcloud storage cp gs://YOUR_PROJECT_ID -quickstart-certs/server-ca.pem . gcloud storage cp gs://YOUR_PROJECT_ID -quickstart-certs/client-cert.pem . gcloud storage cp gs://YOUR_PROJECT_ID -quickstart-certs/client-key.pem .
Configure the SSL certificates for use in Java on the Compute Engine VM instance
- In the terminal on the Compute Engine VM instance, run the following command to
convert the downloaded PEM certificate and key to a PKCS12 archive using
openssl
. Before running the following command, replace SSL_CLIENT_KEY_PASSWD with your own custom keystore password to be used to create the Java client keystore.
openssl pkcs12 -export -in client-cert.pem -inkey client-key.pem \ -name "postgresclient" -passout pass:SSL_CLIENT_KEY_PASSWD \ -out client-keystore.p12
Set Environment Variables on the Compute Engine VM instance
On the Compute Engine VM instance in the open terminal, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacements:
- INSTANCE_HOST set to the Private IP address of your instance displayed on the Cloud SQL instances page in the Google Cloud console.
- SSL_CLIENT_KEY_PASSWD with the password you specified for creating the Java client keystore with
openssl
in the previous quickstart step. - YOUR_DB_PASSWORD with the password of the
quickstart-user
that you created in the previous Create a user quickstart step.
export INSTANCE_HOST='INSTANCE_HOST ' export DB_PORT='5432' export DB_NAME='quickstart_db ' export DB_USER='quickstart-user ' export DB_PASS='YOUR_DB_PASSWORD ' export SSL_CLIENT_KEY_PATH='client-keystore.p12 ' export SSL_CLIENT_KEY_PASSWD='SSL_CLIENT_KEY_PASSWD ' export SSL_SERVER_CA_PATH='server-ca.pem' export PRIVATE_IP='TRUE'
On the Compute Engine VM instance in the open terminal, run the following command to get the Java sample app's dependencies on to your Compute Engine VM instance and run the sample app.
mvn jetty:run
On your local computer get the Compute Engine VM instance's external IP address where the sample app is running and view it in a browser.
- In a terminal or in Powershell on your local computer, get the Compute Engine VM instance's external IP address by running the
following
gcloud compute instances describe
command: -
View the running sample app. Open a browser on your local computer and go to
the Compute Engine VM instance's external IP address and port :8080.
http://
COMPUTE_ENGINE_VM_EXTERNAL_IP_ADDRESS :8080
gcloud compute instances describequickstart-vm-instance --format="value(networkInterfaces[0].accessConfigs[].natIP)"
To stop the sample app, press Control+C in the Compute Engine VM instance terminal where you started the sample app.
Download SSL certificates using the gcloud CLI on the Compute Engine VM instance
On the Compute Engine VM instance in a terminal open to the nodejs-docs-samples/cloud-sql/postgres/knex
directory,
run the following gcloud storage cp
commands
to download the SSL certificates from Cloud Storage to the certs
directory.
gcloud storage cp gs://YOUR_PROJECT_ID -quickstart-certs/server-ca.pem certs/. gcloud storage cp gs://YOUR_PROJECT_ID -quickstart-certs/client-cert.pem certs/. gcloud storage cp gs://YOUR_PROJECT_ID -quickstart-certs/client-key.pem certs/.
Set Environment Variables on the Compute Engine VM instance
On the Compute Engine VM instance in the open terminal, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacements:
- INSTANCE_HOST set to the Private IP address of your instance displayed on the Cloud SQL instances page in the Google Cloud console.
- YOUR_DB_PASSWORD with the password of the
quickstart-user
that you created in the previous Create a user quickstart step.
export INSTANCE_HOST='INSTANCE_HOST ' export DB_PORT='5432' export DB_NAME='quickstart_db ' export DB_USER='quickstart-user ' export DB_PASS='YOUR_DB_PASSWORD ' export DB_ROOT_CERT='certs/server-ca.pem' export DB_CERT='certs/client-cert.pem' export DB_KEY='certs/client-key.pem' export PRIVATE_IP='TRUE'
On the Compute Engine VM instance in the open terminal, run the following commands to get the required Node.js packages on to your Compute Engine VM instance and run the sample app.
-
Install the Node.js packages necessary to run the app locally.
npm install
-
Run the sample app.
npm start
On your local computer get the Compute Engine VM instance's external IP address where the sample app is running and view it in a browser.
- In a terminal or in Powershell on your local computer, get the Compute Engine VM instance's external IP address by running the
following
gcloud compute instances describe
command: -
View the running sample app. Open a browser on your local computer and go to
the Compute Engine VM instance's external IP address and port :8080.
http://
COMPUTE_ENGINE_VM_EXTERNAL_IP_ADDRESS :8080
gcloud compute instances describequickstart-vm-instance --format="value(networkInterfaces[0].accessConfigs[].natIP)"
To stop the sample app, press Control+C in the Compute Engine VM instance terminal where you started the sample app.
Download SSL certificates using the gcloud CLI on the Compute Engine VM instance
On the Compute Engine VM instance in a terminal open to the python-docs-samples/cloud-sql/postgres/sqlalchemy
directory,
run the following gcloud storage cp
commands
to download the SSL certificates from Cloud Storage to the certs
directory.
gcloud storage cp gs://YOUR_PROJECT_ID -quickstart-certs/server-ca.pem certs/. gcloud storage cp gs://YOUR_PROJECT_ID -quickstart-certs/client-cert.pem certs/. gcloud storage cp gs://YOUR_PROJECT_ID -quickstart-certs/client-key.pem certs/.
Set Environment Variables on the Compute Engine VM instance
On the Compute Engine VM instance in the open terminal, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacements:
- INSTANCE_HOST set to the Private IP address of your instance displayed on the Cloud SQL instances page in the Google Cloud console.
- YOUR_DB_PASSWORD with the password of the
quickstart-user
that you created in the previous Create a user quickstart step.
export INSTANCE_HOST='INSTANCE_HOST ' export DB_PORT='5432' export DB_NAME='quickstart_db ' export DB_USER='quickstart-user ' export DB_PASS='YOUR_DB_PASSWORD ' export DB_ROOT_CERT='certs/server-ca.pem' export DB_CERT='certs/client-cert.pem' export DB_KEY='certs/client-key.pem' export PRIVATE_IP='TRUE'
On the Compute Engine VM instance in the open terminal, run the following commands to get the Python sample app's requirements on to your Compute Engine VM instance and run the sample app.
-
Initialize a virtual environment and install the requirements to run to sample app.
python3 -m venv env source env/bin/activate pip install -r requirements.txt
-
Run the sample app.
python app.py
On your local computer, set up port forwarding over SSH by performing the instructions in next quickstart step. This enables you to use a browser on your local computer to view the app running on your Compute Engine VM instance.
- In a terminal or in Powershell on your local computer, run the following
gcloud compute ssh
command to setup port forwarding over SSH. Before running the command, replace YOUR_PROJECT_ID with your project ID. -
View the running sample app. With port forwarding actively running,
open a browser on your local computer and enter
http://127.0.0.1:8000
in the address bar of your browser.
gcloud compute ssh quickstart-vm-instance --project=YOUR_PROJECT_ID --zone=us-central1-a --ssh-flag='-L 8000:127.0.0.1:8080'
To stop the sample app, press Control+C in the Compute Engine VM instance terminal where you started the sample app.
Private IP Cloud SQL Instance and Windows based Compute Engine VM
Create and download SSL server and client certificates on to your local computer
-
In the Google Cloud console, go to the Cloud SQL Instances page.
- Click the
quickstart-instance
to see its Overview page - Click the Connections tab.
- Under the Security section, click Create client certificate.
- In the Create a client certificate dialog,
enter
quickstart-key
as the name and click Create. In the New SSL certificate created dialog, click each download link to download the certificates. Then, click Close.
Upload SSL certificates to Cloud Storage bucket
In a browser on your local computer, create a Cloud Storage bucket and upload SSL certificates to the bucket where they can then be accessed from the Compute Engine VM instance.
- Create a Cloud Storage bucket.
- For Name of your bucket, enter the following name. Replace
YOUR_PROJECT_ID with your project ID:
YOUR_PROJECT_ID -quickstart-certs - Click the Create button to create the bucket.
- Click the Upload Files button to upload files to the newly created Cloud Storage bucket.
- Select the following files to be uploaded from your local computer to Cloud Storage:
server-ca.pem
client-cert.pem
client-key.pem
On your local computer in a terminal or Powershell window open to the directory where you downloaded the SSL certificates, you can now create a Cloud Storage bucket and upload the SSL certificates to bucket where they can then be accessed from the Compute Engine VM instance. The gcloud CLI will be used to upload the files.
- Run the following
gcloud storage buckets create
command to make a new Cloud Storage bucket: - From the directory where you downloaded the certificates on your local computer,
run the following
gcloud storage cp
commands to copy the SSL certificates to the newly created Cloud Storage bucket:
gcloud storage buckets create gs://YOUR_PROJECT_ID -quickstart-certs --location=us-central1
gcloud storage cp server-ca.pem gs://YOUR_PROJECT_ID -quickstart-certs/ gcloud storage cp client-cert.pem gs://YOUR_PROJECT_ID -quickstart-certs/ gcloud storage cp client-key.pem gs://YOUR_PROJECT_ID -quickstart-certs/
Download SSL certificates using the gcloud CLI on the Compute Engine VM instance
On the Compute Engine VM instance in a Powershell window open to the golang-samples/cloudsql/postgres/database-sql
directory, run the following gcloud storage cp
commands
to download the SSL certificates from Cloud Storage to the certs
directory.
gcloud storage cp gs://YOUR_PROJECT_ID -quickstart-certs/server-ca.pem certs/. gcloud storage cp gs://YOUR_PROJECT_ID -quickstart-certs/client-cert.pem certs/. gcloud storage cp gs://YOUR_PROJECT_ID -quickstart-certs/client-key.pem certs/.
Set Environment Variables on the Compute Engine VM instance
On the Compute Engine VM instance in the Powershell window, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacements:
- INSTANCE_HOST set to the Private IP address of your instance displayed on the Cloud SQL instances page in the Google Cloud console.
- YOUR_DB_PASSWORD with the password of the
quickstart-user
that you created in the previous Create a user quickstart step.
$env:INSTANCE_HOST="INSTANCE_HOST " $env:DB_PORT="5432" $env:DB_NAME="quickstart_db " $env:DB_USER="quickstart-user " $env:DB_PASS="YOUR_DB_PASSWORD " $env:DB_ROOT_CERT="certs/server-ca.pem" $env:DB_CERT="certs/client-cert.pem" $env:DB_KEY="certs/client-key.pem" $env:PRIVATE_IP="TRUE"
On the Compute Engine VM instance in the open Powershell window, run the following commands to get the Go sample app's dependencies on to your Compute Engine VM instance and run the sample app.
-
Get the dependencies required to run to sample app.
go get ./...
-
Run the sample app.
go run cmd\app\main.go
-
View the running sample app. Open a browser on the Compute Engine VM instance and go to
http://127.0.0.1:8080
.
To stop the sample app, press Control+C in the Compute Engine VM instance Powershell window where you started the sample app.
Download SSL certificates using the gcloud CLI on the Compute Engine VM instance
On the Compute Engine VM instance in a Powershell window open to the java-docs-samples/cloud-sql/postgres/servlet
directory, run the following gcloud storage cp
commands
to download the SSL certificates from Cloud Storage to the current directory.
gcloud storage cp gs://YOUR_PROJECT_ID -quickstart-certs/server-ca.pem . gcloud storage cp gs://YOUR_PROJECT_ID -quickstart-certs/client-cert.pem . gcloud storage cp gs://YOUR_PROJECT_ID -quickstart-certs/client-key.pem .
Configure the SSL certificates for use in Java on the Compute Engine VM instance
- In the terminal on the Compute Engine VM instance, run the following command to
convert the downloaded PEM certificate and key to a PKCS12 archive using
openssl
. Before running the following command, replace SSL_CLIENT_KEY_PASSWD with your own custom keystore password to be used to create the Java client keystore.
openssl pkcs12 -export -in client-cert.pem -inkey client-key.pem ` -name "postgresclient" -passout pass:SSL_CLIENT_KEY_PASSWD ` -out client-keystore.p12
Set Environment Variables on the Compute Engine VM instance
On the Compute Engine VM instance in the Powershell window, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacements:
- INSTANCE_HOST set to the Private IP address of your instance displayed on the Cloud SQL instances page in the Google Cloud console.
- YOUR_DB_PASSWORD with the password of the
quickstart-user
that you created in the previous Create a user quickstart step. - SSL_CLIENT_KEY_PASSWD with the password you specified for SSL_CLIENT_KEY_PASSWD.
$env:INSTANCE_HOST="INSTANCE_HOST " $env:DB_PORT="5432" $env:DB_NAME="quickstart_db " $env:DB_USER="quickstart-user " $env:DB_PASS="YOUR_DB_PASSWORD " $env:SSL_CLIENT_KEY_PATH="client-keystore.p12 " $env:SSL_CLIENT_KEY_PASSWD="SSL_CLIENT_KEY_PASSWD " $env:SSL_SERVER_CA_PATH="server-ca.pem" $env:PRIVATE_IP="TRUE"
-
On the Compute Engine VM instance in the open Powershell window, run the following command to get the Java sample app's dependencies on to your Compute Engine VM instance and run the sample app.
mvn jetty:run
-
View the running sample app. Open a browser on the Compute Engine VM instance and go to
http://127.0.0.1:8080
.
To stop the sample app, press Control+C in the Compute Engine VM instance Powershell window where you started the sample app.
Download SSL certificates using the gcloud CLI on the Compute Engine VM instance
On the Compute Engine VM instance in a Powershell window open to the nodejs-docs-samples/cloud-sql/postgres/knex
directory, run the following gcloud storage cp
commands
to download the SSL certificates from Cloud Storage to the certs
directory.
gcloud storage cp gs://YOUR_PROJECT_ID -quickstart-certs/server-ca.pem certs/. gcloud storage cp gs://YOUR_PROJECT_ID -quickstart-certs/client-cert.pem certs/. gcloud storage cp gs://YOUR_PROJECT_ID -quickstart-certs/client-key.pem certs/.
Set Environment Variables on the Compute Engine VM instance
On the Compute Engine VM instance in the Powershell window, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacements:
- INSTANCE_HOST set to the Private IP address of your instance displayed on the Cloud SQL instances page in the Google Cloud console.
- YOUR_DB_PASSWORD with the password of the
quickstart-user
that you created in the previous Create a user quickstart step.
$env:INSTANCE_HOST="INSTANCE_HOST " $env:DB_PORT="5432" $env:DB_NAME="quickstart_db " $env:DB_USER="quickstart-user " $env:DB_PASS="YOUR_DB_PASSWORD " $env:DB_ROOT_CERT="certs/server-ca.pem" $env:DB_CERT="certs/client-cert.pem" $env:DB_KEY="certs/client-key.pem" $env:PRIVATE_IP="TRUE"
On the Compute Engine VM instance in the open Powershell window, run the following commands to get the required Node.js packages on to your Compute Engine VM instance and run the sample app.
-
Install the Node.js packages necessary to run the app locally.
npm install
-
Run the sample app.
npm start
-
View the running sample app. Open a browser on the Compute Engine VM instance and go to
http://127.0.0.1:8080
.
To stop the sample app, press Control+C in the Compute Engine VM instance Powershell window where you started the sample app.
Download SSL certificates using the gcloud CLI on the Compute Engine VM instance
On the Compute Engine VM instance in a Powershell window open to the python-docs-samples/cloud-sql/postgres/sqlalchemy
directory, run the following gcloud storage cp
commands
to download the SSL certificates from Cloud Storage to the certs
directory.
gcloud storage cp gs://YOUR_PROJECT_ID -quickstart-certs/server-ca.pem certs/. gcloud storage cp gs://YOUR_PROJECT_ID -quickstart-certs/client-cert.pem certs/. gcloud storage cp gs://YOUR_PROJECT_ID -quickstart-certs/client-key.pem certs/.
Set Environment Variables on the Compute Engine VM instance
On the Compute Engine VM instance in the Powershell window, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacements:
- INSTANCE_HOST set to the Private IP address of your instance displayed on the Cloud SQL instances page in the Google Cloud console.
- YOUR_DB_PASSWORD with the password of the
quickstart-user
that you created in the previous Create a user quickstart step.
$env:INSTANCE_HOST="INSTANCE_HOST " $env:DB_PORT="5432" $env:DB_NAME="quickstart_db " $env:DB_USER="quickstart-user " $env:DB_PASS="YOUR_DB_PASSWORD " $env:DB_ROOT_CERT="certs/server-ca.pem" $env:DB_CERT="certs/client-cert.pem" $env:DB_KEY="certs/client-key.pem" $env:PRIVATE_IP="TRUE"
On the Compute Engine VM instance in the open Powershell window, run the following commands to get the Python sample app's requirements on to your Compute Engine VM instance and run the sample app.
-
Initialize a virtual environment and install the requirements to run to sample app.
virtualenv --python python3 env .\env\Scripts\activate pip install -r requirements.txt
-
Run the sample app.
python app.py
-
View the running sample app. Open a browser on the Compute Engine VM instance and go to
http://127.0.0.1:8080
.
To stop the sample app, press Control+C in the Compute Engine VM instance Powershell window where you started the sample app.
Clean up
To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.
Delete Cloud SQL instance
-
In the Google Cloud console, go to the Cloud SQL Instances page.
- Select the
quickstart-instance
instance to open the Instance details page. - In the icon bar at the top of the page, click Delete.
- In the Delete instance dialog box, type
quickstart-instance
, and then click Delete to delete the instance.
Delete Compute Engine VM instance
-
In the Google Cloud console, go to the VM instances page.
- Select the
quickstart-vm-instance
instance to open the Instance details page. - In the icon bar at the top of the page, click Delete.
- Click Delete to delete the instance.
Optional cleanup steps
If you're not using the Cloud SQL client role that you assigned to the
Compute Engine default
service account, you can remove it.
-
In the Google Cloud console, go to the IAM page.
- Click the edit icon (which looks like a pencil) for the IAM account named Compute Engine default service account.
- Delete the Cloud SQL client role.
- Click Save.
If you're not using the API that was enabled as part of this quickstart, you can disable it.
- API that was enabled within this quickstart:
- Cloud SQL Admin API
In the Google Cloud console, go to the APIs page.
Select any API that you would like to disable and then click the Disable API button.
What's next
Based on your needs, you can learn more about creating Cloud SQL instances.You also can learn about creating PostgreSQL users and databases for your Cloud SQL instance.
For more information about pricing, see Cloud SQL for PostgreSQL pricing.
Learn more about:
- Configuring your Cloud SQL instance with a public IP address.
- Configuring your Cloud SQL instance with a private IP address.
Additionally, you can learn about connecting to a Cloud SQL instance from other Google Cloud applications: