Learn how to deploy a sample app on App Engine standard environment 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).
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
roles/resourcemanager.projectCreator), which contains the
resourcemanager.projects.create permission. Learn how to grant
roles.
Verify that billing is enabled for your Google Cloud project.
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
roles/resourcemanager.projectCreator), which contains the
resourcemanager.projects.create permission. Learn how to grant
roles.
Verify that billing is enabled for your Google Cloud project.
Click the button below to enable the APIs required for this quickstart.
This enables the following APIs:
Click the following button to open Cloud Shell, which provides
command-line access to your Google Cloud resources directly from the browser.
Cloud Shell can be used to run the gcloud commands presented throughout this quickstart.
Run the following gcloud command using Cloud Shell:
gcloud services enable sqladmin.googleapis.com compute.googleapis.com \ cloudbuild.googleapis.com logging.googleapis.com
This command enables the following APIs:
Take the following steps to set up a Cloud SQL instance that you connect to over public IP:
In the Google Cloud console, go to the Cloud SQL Instances page.
quickstart-instance.Before running the command as follows, replace DB_ROOT_PASSWORD with the password of your database user.
Optionally, modify the values for the following parameters:
us-central is used.
Run the gcloud
sql instances create command to create a Cloud SQL instance.
gcloud sql instances create quickstart-instance \ --database-version=POSTGRES_14 \ --cpu=1 \ --memory=4GB \ --region=us-central \ --root-password=DB_ROOT_PASSWORD
Take the following steps to set up a Cloud SQL instance that you connect to over private IP:
In the Google Cloud console, go to the VPC networks page.
default VPC network.google-managed-services-default.16.default VPC network.google-managed-services-default.In the Google Cloud console, go to the Cloud SQL Instances page.
quickstart-instance.
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
Before running the command as follows, replace DB_ROOT_PASSWORD with the password of your database user.
Optionally, modify the values for the following parameters:
us-central1 is used.
See the full list of regions.
Run the gcloud
sql instances create command to create a Cloud SQL instance with a Private IP address.
gcloud sql instances create quickstart-instance \ --database-version=POSTGRES_14 \ --cpu=1 \ --memory=4GB \ --region=us-central \ --root-password=DB_ROOT_PASSWORD \ --no-assign-ip \ --network=default
Run the gcloud sql instances patch
command to enable only allow SSL connections for the instance.
gcloud sql instances patch quickstart-instance --require-ssl
Take the following steps to create a database:
In the Google Cloud console, go to the Cloud SQL Instances page.
quickstart-instance.quickstart-db.Run the gcloud
sql databases create command to create a database.
gcloud sql databases create quickstart-db --instance=quickstart-instance
In the Google Cloud console, go to the Cloud SQL Instances page.
quickstart-user.Before running the following command, make the following replacements:
Run the gcloud sql users create command to create the user.
gcloud sql users create quickstart-user \ --instance=quickstart-instance \ --password=PASSWORD
Username length limits are the same for Cloud SQL as for on-premises PostgreSQL.
In the Google Cloud console, go to the App Engine page.
gcloud app create
command to create an App Engine application:
gcloud app create
In the Google Cloud console, go to the Service accounts page.
gcloud command to get a list of
your project's service accounts:
gcloud iam service-accounts list
gcloud projects add-iam-policy-binding YOUR_PROJECT_ID \ --member="serviceAccount:SERVICE_ACCOUNT_EMAIL" \ --role="roles/cloudsql.client"
With a Cloud SQL instance, database, and service account with client permissions, you can now configure and deploy a sample application to connect to your Cloud SQL instance.
To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.
In the Google Cloud console, go to the Cloud SQL Instances page.
quickstart-instance instance to open the Instance details
page.quickstart-instance, and then
click Delete to delete the instance.
Disabling your app stops it from running instances and serving requests.
If your app is processing a request, your app completes the request before being
disabled.To disable an App Engine app and retain its data, do the following:
In the Google Cloud console, go to the Settings page:
In the Application settings tab, click Disable application.
In the App ID field, enter the ID of the app you want to disable, and then click Disable.
If you're not using the Cloud SQL client role that you assigned to the Compute Engine service account, you can remove it.
In the Google Cloud console, go to the Service accounts page.
If you're not using the APIs that were enabled as part of this quickstart, you can disable them.
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.
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:
Additionally, you can learn about connecting to a Cloud SQL instance from other Google Cloud applications:
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-06-11 UTC.