Trigger: Use when working with Google Cloud Cloud Sql — setup, configuration, and best practices.
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: **Trigger**: Use when working with Google Cloud Cloud Sql — setup, configuration, and best practices.4---56**Trigger**: Use when working with Google Cloud Cloud Sql — setup, configuration, and best practices.78# Cloud SQL Basics910Cloud SQL is a fully managed relational database service for MySQL, PostgreSQL,11and SQL Server. It automates time-consuming tasks like patches, updates,12backups, and replicas, while providing high performance and availability for13your applications.1415## Prerequisites1617Ensure you have the necessary IAM permissions to create and manage Cloud SQL18instances. The **Cloud SQL Admin** (`roles/cloudsql.admin`) role provides full19access to Cloud SQL resources.2021## Quick Start (PostgreSQL)22231. **Enable the API:**24 25 ```bash26 gcloud services enable sqladmin.googleapis.com --quiet27 ```28292. **Create an Instance:**30 31 ```bash32 gcloud sql instances create INSTANCE_NAME \33 --database-version=POSTGRES_18 \34 --cpu=2 \35 --memory=7680MiB \36 --region=REGION \37 --quiet38 ```39403. **Set a password for the default user:**4142 Because this is a Cloud SQL for PostgreSQL instance, the default admin user43 is `postgres`:44 45 ```bash46 gcloud sql users set-password postgres \47 --instance=INSTANCE_NAME --password=PASSWORD \48 --quiet49 ```50514. **Create a database:**52 53 ```bash54 gcloud sql databases create DATABASE_NAME \55 --instance=INSTANCE_NAME \56 --quiet57 ```58595. **Get the instance connection name:**6061 You need the instance connection name (which is formatted as62 `PROJECT_ID:REGION:INSTANCE_NAME`) to connect using the Cloud SQL Auth63 Proxy. Retrieve it with the following command:64 65 ```bash66 gcloud sql instances describe INSTANCE_NAME \67 --format="value(connectionName)" \68 --quiet69 ```70716. **Connect to the instance:**7273 The Cloud SQL Auth Proxy must be running to be able to connect to the74 instance. In a separate terminal, start the proxy using the connection name:75 76 ```bash77 ./cloud-sql-proxy INSTANCE_CONNECTION_NAME78 ```7980 With the proxy running, connect using `psql` in another terminal:81 82 ```bash83 psql "host=127.0.0.1 port=5432 user=postgres dbname=DATABASE_NAME password=PASSWORD sslmode=disable"84 ```8586## Reference Directory8788- [Core Concepts](references/core-concepts.md): Cloud SQL editions (Enterprise89 & Enterprise Plus), instance architecture, read pools, high availability (HA),90 and supported database engines.9192- [CLI Usage](references/cli-usage.md): Essential `gcloud sql` commands for93 instance, database, and user management.9495- [Client Libraries & Connectors](references/client-library-usage.md):96 Connecting to Cloud SQL using Python, Java, Node.js, and Go.9798- [MCP Usage](references/mcp-usage.md): Using the Cloud SQL remote MCP99 server and Gemini CLI extension.100101- [Infrastructure as Code](references/iac-usage.md): Terraform102 configuration for instances, databases, and users.103104- [IAM & Security](references/iam-security.md): Predefined roles, SSL/TLS105 certificates, and Auth Proxy configuration.106107- [Disaster Recovery & Backups](references/dr-backups.md): Backup types,108 Point-in-Time Recovery (PITR), replicas, read pools comparison, and Enterprise Plus Advanced DR.109110*If you need product information not found in these references, use the111 Developer Knowledge MCP server `search_documents` tool.*