Stay organized with collections Save and categorize content based on your preferences.
This page contains information and examples for connecting to a Cloud SQL instance from a service running in the App Engine standard environment.
Cloud SQL is a fully-managed database service that helps you set up, maintain, manage, and administer your relational databases in the cloud.
App Engine is a fully managed, serverless platform for developing and hosting web applications at scale. You can choose from several popular languages, libraries, and frameworks to develop your apps, then let App Engine take care of provisioning servers and scaling your app instances based on demand.
Set up a Cloud SQL instanceBy default, Cloud SQL assigns a public IP address to a new instance. You also have the option to assign a private IP address. For more information about the connectivity options for both, see the Connecting Overview page.
serverCaMode
for the instance. You must select the per-instance CA option (GOOGLE_MANAGED_INTERNAL_CA
) as the server CA mode for instances that you want to connect to from App Engine standard environment web applications.The steps to configure App Engine standard environment depend on the type of IP address that you assigned to your Cloud SQL instance.
Public IP (default)To configure App Engine standard environment to enable connections to a Cloud SQL instance using public IP:
gcloud sql instances describe
command:
gcloud sql instances describe INSTANCE_NAMEReplace INSTANCE_NAME with the name of your Cloud SQL instance.
Ensure that the service account your app is using to authenticate calls to Cloud SQL has the Cloud SQL Client
IAM role.
For detailed instructions on adding IAM roles to a service account, see Granting Roles to Service Accounts.
By default, your app will authorize your connections using an App Engine service account. The service account identity is in the format PROJECT_ID@appspot.gserviceaccount.com
.
If the authorizing service account belongs to a different project than the Cloud SQL instance, the Cloud SQL Admin API and IAM permissions will need to be added for both projects.
Private IPIf the authorizing service account belongs to a different project than the one containing the Cloud SQL instance, do the following:
5432
.After you configure App Engine standard environment, you can connect to your Cloud SQL instance.
Public IP (default)For public IP paths, App Engine standard environment provides encryption and connects using the Cloud SQL Auth Proxy in two ways:
Once correctly configured, you can connect your service to your Cloud SQL instance's Unix domain socket accessed on the environment's filesystem at the following path: /cloudsql/INSTANCE_CONNECTION_NAME
.
The INSTANCE_CONNECTION_NAME uses the format project:region:instance-id
. You can find it on the Overview page for your instance in the Google Cloud console or by running the following command:
gcloud sql instances describe [INSTANCE_NAME]
These connections are automatically encrypted without any additional configuration.
The code samples shown below are extracts from more complete examples on the GitHub site. Click View on GitHub
to see more.
.s.PGSQL.5432
suffix in the socket path. Some libraries apply this suffix automatically, but others require you to specify the socket path as follows:
/cloudsql/INSTANCE_CONNECTION_NAME/.s.PGSQL.5432Warning: Linux-based operating systems have a maximum socket path length of 108 characters. If the total length of the path exceeds this length, you cannot connect with a socket from App Engine standard environment. Connect with Cloud SQL connectors
The Cloud SQL connectors are language specific libraries that provide encryption and IAM-based authorization when connecting to a Cloud SQL instance.
PythonTo see this snippet in the context of a web application, view the README on GitHub.
JavaTo see this snippet in the context of a web application, view the README on GitHub.
Note:
To see this snippet in the context of a web application, view the README on GitHub.
Node.jsTo see this snippet in the context of a web application, view the README on GitHub.
Private IPFor private IP paths, your application connects directly to your instance through a VPC network. This method uses TCP to connect directly to the Cloud SQL instance without using the Cloud SQL Auth Proxy.
Connect with TCPConnect using the private IP address of your Cloud SQL instance as the host and port 5432
.
You can use the Cloud SQL Auth Proxy when testing your application locally. See the quickstart for using the Cloud SQL Auth Proxy for detailed instructions.
Connection PoolsConnections to underlying databases may be dropped, either by the database server itself, or by the underlying infrastructure. To mitigate this, we recommend that you use a client library that supports connection pools and automatic reconnection.
Connection LimitsEach App Engine instance running in a standard environment cannot have more than 100 concurrent connections to an instance. For PHP 5.5 apps, the limit is 60 concurrent connections. This limit applies per application instance. This means that each instance of the App Engine application can have that many connections to the database, and as it scales the total number of connections per deployment can grow. For more information, see Scaling elements.
You can limit the maximum number of connections used per instance by using a connection pool. For more detailed examples on how to limit the number of connections, see the Managing database connections page.
App Engine applications are subject to request time limits depending on usage and environment. For more information, see how instances are managed in App Engine standard environment standard and flexible environments.
API Quota LimitsApp Engine provides a mechanism that connects using the Cloud SQL Auth Proxy, which uses the Cloud SQL Admin API. API quota limits apply to the Cloud SQL Auth Proxy. When the Cloud SQL Admin API starts, it uses a quota of two and an average of two per hour afterwards. The default quota is 180 per minute per user. App Engine applications are also subject to additional quotas and limits as discussed on the App Engine Quotas page.
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 2025-07-02 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-07-02 UTC."],[],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4