Cloud SQL Basics
Cloud SQL is a fully managed relational database service for MySQL, PostgreSQL,
and SQL Server. It automates time-consuming tasks like patches, updates,
backups, and replicas, while providing high performance and availability for
your applications.
Prerequisites
Ensure you have the necessary IAM permissions to create and manage Cloud SQL
instances. The Cloud SQL Admin (roles/cloudsql.admin) role provides full
access to Cloud SQL resources.
Quick Start (PostgreSQL)
Enable the API:
gcloud services enable sqladmin.googleapis.com --quiet
Create an Instance:
gcloud sql instances create INSTANCE_NAME \
--database-version=POSTGRES_18 \
--cpu=2 \
--memory=7680MiB \
--region=REGION \
--quiet
Set a password for the default user:
Because this is a Cloud SQL for PostgreSQL instance, the default admin user
is postgres:
gcloud sql users set-password postgres \
--instance=INSTANCE_NAME --password=PASSWORD \
--quiet
Create a database:
gcloud sql databases create DATABASE_NAME \
--instance=INSTANCE_NAME \
--quiet
Get the instance connection name:
You need the instance connection name (which is formatted as
PROJECT_ID:REGION:INSTANCE_NAME) to connect using the Cloud SQL Auth
Proxy. Retrieve it with the following command:
gcloud sql instances describe INSTANCE_NAME \
--format="value(connectionName)" \
--quiet
Connect to the instance:
The Cloud SQL Auth Proxy must be running to be able to connect to the
instance. In a separate terminal, start the proxy using the connection name:
./cloud-sql-proxy INSTANCE_CONNECTION_NAME
With the proxy running, connect using psql in another terminal:
psql "host=127.0.0.1 port=5432 user=postgres dbname=DATABASE_NAME password=PASSWORD sslmode=disable"
Reference Directory
Core Concepts: Cloud SQL editions (Enterprise
& Enterprise Plus), instance architecture, read pools, high availability (HA),
and supported database engines.
CLI Usage: Essential gcloud sql commands for
instance, database, and user management.
Client Libraries & Connectors:
Connecting to Cloud SQL using Python, Java, Node.js, and Go.
MCP Usage: Using the Cloud SQL remote MCP
server and Gemini CLI extension.
Infrastructure as Code: Terraform
configuration for instances, databases, and users.
IAM & Security: Predefined roles, SSL/TLS
certificates, and Auth Proxy configuration.
Disaster Recovery & Backups: Backup types,
Point-in-Time Recovery (PITR), replicas, read pools comparison, and Enterprise Plus Advanced DR.
If you need product information not found in these references, use the
Developer Knowledge MCP server search_documents tool.
1---2name: cloud-sql-basics3description: This file generates or explains Cloud SQL resources. Use this file when the user asks to create a Cloud SQL instance or database for MySQL, PostgreSQL, or SQL Server. Cloud SQL manages third-party MySQL, PostgreSQL, and SQL Server instances as resources in Cloud SQL. For example, when Cloud SQL creates an open-source MySQL instance, the resulting resource is a Cloud SQL for MySQL instance that Google Cloud manages. Cloud SQL handles backups, high availability, and secure connectivity for relational database workloads.4---5# Cloud SQL Basics67Cloud SQL is a fully managed relational database service for MySQL, PostgreSQL,8and SQL Server. It automates time-consuming tasks like patches, updates,9backups, and replicas, while providing high performance and availability for10your applications.1112## Prerequisites1314Ensure you have the necessary IAM permissions to create and manage Cloud SQL15instances. The **Cloud SQL Admin** (`roles/cloudsql.admin`) role provides full16access to Cloud SQL resources.1718## Quick Start (PostgreSQL)19201. **Enable the API:**21 22 ```bash23 gcloud services enable sqladmin.googleapis.com --quiet24 ```25262. **Create an Instance:**27 28 ```bash29 gcloud sql instances create INSTANCE_NAME \30 --database-version=POSTGRES_18 \31 --cpu=2 \32 --memory=7680MiB \33 --region=REGION \34 --quiet35 ```36373. **Set a password for the default user:**3839 Because this is a Cloud SQL for PostgreSQL instance, the default admin user40 is `postgres`:41 42 ```bash43 gcloud sql users set-password postgres \44 --instance=INSTANCE_NAME --password=PASSWORD \45 --quiet46 ```47484. **Create a database:**49 50 ```bash51 gcloud sql databases create DATABASE_NAME \52 --instance=INSTANCE_NAME \53 --quiet54 ```55565. **Get the instance connection name:**5758 You need the instance connection name (which is formatted as59 `PROJECT_ID:REGION:INSTANCE_NAME`) to connect using the Cloud SQL Auth60 Proxy. Retrieve it with the following command:61 62 ```bash63 gcloud sql instances describe INSTANCE_NAME \64 --format="value(connectionName)" \65 --quiet66 ```67686. **Connect to the instance:**6970 The Cloud SQL Auth Proxy must be running to be able to connect to the71 instance. In a separate terminal, start the proxy using the connection name:72 73 ```bash74 ./cloud-sql-proxy INSTANCE_CONNECTION_NAME75 ```7677 With the proxy running, connect using `psql` in another terminal:78 79 ```bash80 psql "host=127.0.0.1 port=5432 user=postgres dbname=DATABASE_NAME password=PASSWORD sslmode=disable"81 ```8283## Reference Directory8485- [Core Concepts](references/core-concepts.md): Cloud SQL editions (Enterprise86 & Enterprise Plus), instance architecture, read pools, high availability (HA),87 and supported database engines.8889- [CLI Usage](references/cli-usage.md): Essential `gcloud sql` commands for90 instance, database, and user management.9192- [Client Libraries & Connectors](references/client-library-usage.md):93 Connecting to Cloud SQL using Python, Java, Node.js, and Go.9495- [MCP Usage](references/mcp-usage.md): Using the Cloud SQL remote MCP96 server and Gemini CLI extension.9798- [Infrastructure as Code](references/iac-usage.md): Terraform99 configuration for instances, databases, and users.100101- [IAM & Security](references/iam-security.md): Predefined roles, SSL/TLS102 certificates, and Auth Proxy configuration.103104- [Disaster Recovery & Backups](references/dr-backups.md): Backup types,105 Point-in-Time Recovery (PITR), replicas, read pools comparison, and Enterprise Plus Advanced DR.106107*If you need product information not found in these references, use the108 Developer Knowledge MCP server `search_documents` tool.*