This page describes how to create a Cloud SQL for PostgreSQL instance.
For detailed information about all instance settings, see Instance settings.
A newly-created instance has a postgres database.
The maximum number of instances you can have in a single project depends on the network architecture of those instances:
- New SQL network architecture: You can have up to 1000 instances per project.
- Old SQL network architecture: You can have up to 100 instances per project.
- Using both architectures: Your limit will be somewhere between 100 and 1000, depending on the distribution of your instances across the two architectures.
File a support case to request an increase. Read replicas are counted as instances.
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.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Install the gcloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init -
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
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Install the gcloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init -
Make sure you have the Cloud SQL Admin and Compute Viewer roles on
your user account.
Learn more about roles and permissions.
Create a PostgreSQL instance
Console
-
In the Google Cloud console, go to the Cloud SQL Instances page.
- Click Create instance.
- On the Choose your database engine panel of the Create an instance page, click Choose PostgreSQL.
In the Choose a Cloud SQL edition section of the Create a SQL Server instance page, select the Cloud SQL edition for your instance:
EnterpriseorEnterprise Plus.For more information about Cloud SQL editions, see Introduction to Cloud SQL editions.
- Select the edition preset for your instance. To see the available presets, click the Edition preset menu.
- In the Instance info section, select the database version for your
instance. To see the available versions, click the Database version
menu.
The database version can't be edited after the instance has been created.
- In the Instance ID field of the Instance info pane, enter
an ID for your instance.
You do not need to include the project ID in the instance name. This is done automatically where appropriate (for example, in the log files).
- Enter a password for the
postgresuser. -
Optional: Configure a password policy for the instance as follows:
- Select the Enable password policies checkbox.
- Click the Set password policy button, set one or more of
the following options, and click Save.
- Minimum length: Specifies the minimum number of characters that the password must have.
- Password complexity: Checks if the password is a combination of lowercase, uppercase, numeric, and non-alphanumeric characters.
- Restrict password reuse: Specifies the number of previous passwords that you can't reuse.
- Disallow username: Prevents the use of the username in the password.
- Set password change interval: Specifies the minimum number of hours after which you can change the password.
- In the Choose region and zonal availability section, select the
region and zone for your instance. Region availability might be different
based on your Cloud SQL for PostgreSQL edition. For more information, see
About instance settings.
Place your instance in the same region as the resources that access it. The region you select can't be modified in the future. In most cases, you don't need to specify a zone.
If you are configuring your instance for high availability, you can select both a primary and secondary zone.
The following conditions apply when the secondary zone is used during instance creation:
- The zones default to
Anyfor the primary zone andAny (different from primary)for the secondary zone. - If both the primary and secondary zones are specified, they must be distinct zones.
- The zones default to
- In the Customize your instance section, update settings for your
instance.
Begin by clicking SHOW CONFIGURATION OPTIONS to display the groups
of settings. Then, expand the groups you want to review and customize settings.
A Summary of all the options you select is shown on the right.
Customizing these instance settings is optional. Defaults are assigned in
every case where no customizations are made.
The following table is a quick reference to instance settings. For more details about each setting, see the instance settings page.
- Click Create Instance.
Note: It might take a few minutes to create your instance. However, you can view information about the instance while it's being created.
To see the password in clear text, click the Show password icon.
You can either enter the password manually or click Generate to have Cloud SQL create a password for you automatically.
gcloud
For information about installing and getting started with the gcloud CLI, see Installing gcloud CLI. For information about starting Cloud Shell, see the Cloud Shell documentation.
- Use the
gcloud sql instances createcommand to create the instance:
For Cloud SQL Enterprise Plus edition instances:
gcloud sql instances create INSTANCE_NAME \ --database-version=DATABASE_VERSION \ --region=REGION \ --tier=TIER \ --edition=ENTERPRISE_PLUS
For Cloud SQL Enterprise edition instances:
gcloud sql instances create INSTANCE_NAME \ --database-version=DATABASE_VERSION \ --region=REGION \ --cpu=NUMBER_CPUS \ --memory=MEMORY_SIZE \ --edition=ENTERPRISE
--tier flag if you choose
db-f1-micro or db-g1-small as the machine type:
gcloud sql instances create INSTANCE_NAME \ --tier=API_TIER_STRING \ --region=REGION
There are restrictions on the values for vCPUs and memory size:
- vCPUs must be either 1 or an even number between 2 and 96.
- Memory must be:
- 0.9 to 6.5 GB per vCPU
- A multiple of 256 MB
- At least 3.75 GB (3840 MB)
For example, the following command creates a Cloud SQL Enterprise edition instance with two vCPUs and 7,680 MB of memory:
gcloud sql instances create myinstance \ --database-version=POSTGRES_16 \ --cpu=2 \ --memory=7680MB \ --region=us-central1
The following command creates a Cloud SQL Enterprise Plus edition instance with four cores:
gcloud sql instances create myinstance \ --database-version=POSTGRES_16 \ --tier=db-perf-optimized-N-4 \ --edition=ENTERPRISE_PLUS \ --region=us-central1
--cpu and --memory.
The default value for REGION is us-central1.
Don't include sensitive or personally identifiable information
in your instance name; it is externally visible.
You do not need to include the project ID in the instance name. This is done automatically where
appropriate (for example, in the log files).
If you are creating an instance for
high availability, you
can specify both the primary and secondary zones, using the --zone
and --secondary-zone parameters. The following conditions
apply when the secondary zone is used during instance creation or edit:
- The zones must be valid zones.
- If the secondary zone is specified, the primary must also be specified.
- If the primary and secondary zones are specified, they must be distinct zones.
- If the primary and secondary zones are specified, they must belong to the same region.
You can add more parameters to determine other instance settings:
| Setting | Parameter | Notes |
|---|---|---|
| Required parameters | ||
| Database version | --database-version |
The database version, which is based on your Cloud SQL edition. |
| Region | --region |
See valid values. |
| Set password policy | ||
| Enable password policy | --enable-password-policy |
Enables the password policy when used. By default, the password policy
is disabled. When disabled using the --clear-password-policy
parameter, the other password policy parameters are reset.
|
| Minimum length | --password-policy-min-length |
Specifies the minimum number of characters that the password must have. |
| Password complexity | --password-policy-complexity |
Enables the password complexity check to ensure that the password
contains one of each of these types of characters: lowercase, uppercase,
numeric, and non-alphanumeric. Set the value to
COMPLEXITY_DEFAULT. |
| Restrict password reuse | --password-policy-reuse-interval |
Specifies the number of previous passwords that you can't reuse. |
| Disallow username | --password-policy-disallow-username-substring |
Prevents the use of the username in the password. Use
the --no-password-policy-disallow-username-substring
parameter to disable the check. |
| Set password change interval | --password-policy-password-change-interval |
Specifies the minimum duration after which you can change the password, for example, 2m for 2 minutes. |
| Connectivity | ||
| Managed Connection Pooling | --enable-connection-pooling |
Enables Managed Connection Pooling
in the new instance. You can configure advanced Managed Connection Pooling
settings after your instance is created.
Note: This feature is only available for Cloud SQL Enterprise Plus edition instances that are configured to meet Managed Connection Pooling requirements. |
| Private IP | --network
|
--network: Specifies the name of the VPC network you want
to use for this instance. Private services access must already be
configured for the network. Available only for the beta command
(gcloud beta sql instances create).
This parameter is valid only if:
|
| Data API Access | --data-api-access |
Controls connectivity to the instance using
Data API. It's
disallowed by default. Set the value to ALLOW_DATA_API to
let users use the Data API to connect to the instance. For instances
configured with a private IP address only, authorized users can call the Data API on
the instance from the public internet. Set the value to
DISALLOW_DATA_API to disallow using the Data API.
|
| Public IP | --authorized-networks |
For public IP connections, only connections from authorized networks can connect to your instance. Learn more. |
| SSL Enforcement |
|
The The |
| Server CA mode | --server-ca-mode |
The
|
| Automatic server certificate rotation | --server-certificate-rotation-mode |
The
|
| Network architecture | --enforce-new-sql-network-architecture |
Enforce the use of the new network architecture for the instance upon creation. Using this flag when you create an instance before that project has been fully upgraded to the new network architecture can lead to IP address overconsumption or a failure to create instances if there aren't sufficient IP addresses remaining in the allocated IP range. For more information, see Upgrade an instance to the new network architecture and Allocate an IP address range. |
| Machine type and storage | ||
| Machine type | --tier |
Used to specify a shared-core instance
(db-f1-micro
or db-g1-small).
For a custom instance configuration, use the --cpu or
--memory parameters instead. See
Custom instance configuration.
|
| Storage type | --storage-type |
Determines whether your instance uses SSD or HDD storage. Learn more. |
| Storage capacity | --storage-size |
The amount of storage provisioned for the instance, in GB. Learn more. |
| Automatic storage increase | --storage-auto-increase |
Determines whether Cloud SQL automatically provides more storage for your instance when free space runs low. Learn more. |
| Automatic storage increase limit | --storage-auto-increase-limit |
Determines how large Cloud SQL can automatically grow storage.
Available only for the beta command
(gcloud beta sql instances create).
Learn more.
|
| Data cache (optional) | --enable-data-cache |
Enables or deactivates the data cache for instances. For more information, see data cache. |
| Automatic backups and high availability | ||
| High availability | --availability-type |
For a highly-available instance, set to REGIONAL.
Learn more.
|
Secondary zone | --secondary-zone |
If you're creating an instance for
high availability,
you can specify both the primary and secondary zones using the
--zone and --secondary-zone parameters. The
following restrictions apply when the secondary zone is used during
instance creation or edit:
If the primary and secondary zones are specified, they must be distinct zones. If the primary and secondary zones are specified, they must belong to the same region. |
| Automatic backups | --backup-start-time |
The window of time when you would like backups to start. Learn more. |
| Retention settings for automated backups | --retained-backups-count |
The number of automated backups to retain. Learn more. |
| Retention settings for binary logging | --retained-transaction-log-days |
The number of days to retain write-ahead logs for point-in-time recovery. Learn more. |
| Point-in-time recovery | --enable-point-in-time-recovery |
Enables point-in-time recovery and write-ahead logging. Learn more. |
| Add database flags | ||
| Database flags | --database-flags |
You can use database flags to control settings and parameters for your instance. Learn more about database flags. |
| Maintenance schedule | ||
| Maintenance window | --maintenance-window-day,
--maintenance-window-hour |
Determines a one-hour window when Cloud SQL can perform disruptive maintenance on your instance. If you don't set the window, then disruptive maintenance can be done at any time. Learn more. |
| Maintenance timing | --maintenance-release-channel |
Your preferred timing for instance updates, relative to other
instances in the same project. Use preview for earlier
updates, and production for later updates.
Learn more.
|
| Integration with Agent Platform | ||
--enable-google-ml-integration |
Enables Cloud SQL instances to connect to Agent Platform to pass requests for real-time predictions and insights to the AI. | |
--database-flags cloudsql.enable_google_ml_integration=on |
By turning this flag on, Cloud SQL can integrate with Agent Platform. | |
| Custom SAN | ||
| Add a custom subject alternative name (SAN) | --custom-subject-alternative-names=DNS_NAMES |
If you want to use a custom DNS name to connect to a Cloud SQL instance instead of using an IP address, then configure the custom subject alternative name (SAN) setting while creating the instance. The custom DNS name that you insert into the custom SAN setting is added to the SAN field of the server certificate of the instance. This lets you use the custom DNS name with hostname validation securely. Before you can use the custom DNS name in your clients and applications, you must set up the mapping between the DNS name and the IP address. This is known as DNS resolution. You can add a comma-separated list of up to three custom DNS names to the custom SAN setting. |
If you are not using the Cloud SQL Auth Proxy, you will use this address as the host address that your applications or tools use to connect to the instance.
postgres user:
gcloud sql users set-password postgres \ --instance=INSTANCE_NAME \ --password=PASSWORD
Terraform
To create an instance, use a Terraform resource.
Apply the changes
To apply your Terraform configuration in a Google Cloud project, complete the steps in the following sections.
Prepare Cloud Shell
- Launch Cloud Shell.
-
Set the default Google Cloud project where you want to apply your Terraform configurations.
You only need to run this command once per project, and you can run it in any directory.
export GOOGLE_CLOUD_PROJECT=PROJECT_ID
Environment variables are overridden if you set explicit values in the Terraform configuration file.
Prepare the directory
Each Terraform configuration file must have its own directory (also called a root module).
-
In Cloud Shell, create a directory and a new
file within that directory. The filename must have the
.tfextension—for examplemain.tf. In this tutorial, the file is referred to asmain.tf.mkdir DIRECTORY && cd DIRECTORY && touch main.tf
-
If you are following a tutorial, you can copy the sample code in each section or step.
Copy the sample code into the newly created
main.tf.Optionally, copy the code from GitHub. This is recommended when the Terraform snippet is part of an end-to-end solution.
- Review and modify the sample parameters to apply to your environment.
- Save your changes.
-
Initialize Terraform. You only need to do this once per directory.
terraform init
Optionally, to use the latest Google provider version, include the
-upgradeoption:terraform init -upgrade
Apply the changes
-
Review the configuration and verify that the resources that Terraform is going to create or
update match your expectations:
terraform plan
Make corrections to the configuration as necessary.
-
Apply the Terraform configuration by running the following command and entering
yesat the prompt:terraform apply
Wait until Terraform displays the "Apply complete!" message.
- Open your Google Cloud project to view the results. In the Google Cloud console, navigate to your resources in the UI to make sure that Terraform has created or updated them.
Delete the changes
To delete your changes, do the following:
- To disable deletion protection, in your Terraform configuration file set the
deletion_protectionargument tofalse.deletion_protection = "false"
- Apply the updated Terraform configuration by running the following command and
entering
yesat the prompt:terraform apply
-
Remove resources previously applied with your Terraform configuration by running the following command and entering
yesat the prompt:terraform destroy
REST v1
Create the instance
This example creates an instance. Some optional parameters, such as backups and binary logging are also included. For a complete list of parameters for this call, see the Instances:insert page. For information about instance settings, including valid values for region, see Instance settings.
Don't include sensitive or personally identifiable information
in your instance ID; it is externally visible.
You do not need to include the project ID in the instance name. This is done automatically where
appropriate (for example, in the log files).
Before using any of the request data, make the following replacements:
- PROJECT_ID: your project ID
- INSTANCE_ID: your instance ID
- REGION: the region
- DATABASE_VERSION: enum string of the database version (for example,
POSTGRES_18) - PASSWORD: the password for the root user
- MACHINE_TYPE: enum string of the machine (tier) type, as:
db-custom-[CPUS]-[MEMORY_MBS] EDITION_TYPE: your Cloud SQL edition
- DATA_CACHE_ENABLED: (optional) set to
trueto enable data cache for your instance - PRIVATE_NETWORK: specify the name of the Virtual Private Cloud (VPC) network that you want to use for this instance. Private services access must already be configured for the network.
- AUTHORIZED_NETWORKS: for public IP connections, specify the connections from authorized networks that can connect to your instance.
- CA_MODE: specify a
certificate authority hierarchy
for the instance, either
GOOGLE_MANAGED_INTERNAL_CAorGOOGLE_MANAGED_CAS_CA. If you don't specifyserverCaMode, then the default configuration isGOOGLE_MANAGED_INTERNAL_CA. This feature is in Preview. - SERVER_CERTIFICATE_ROTATION_MODE: For automatic server certificate rotation for your instance,
specify
AUTOMATIC_ROTATION_DURING_MAINTENANCE. If you don't specifyserverCertificateRotationMode, then the default configuration isNO_AUTOMATIC_ROTATION. - DNS_NAMES: add a comma-separated list of up to three DNS names to the server certificate of your Cloud SQL instance. You can secure multiple DNS names with a single certificate. This feature is available in Preview and for
CUSTOMER_MANAGED_CAS_CAinstances only.
To set a password policy while creating an instance, include the passwordValidationPolicy object in the request. Set the following parameters, as required:
enablePasswordPolicy: Enables the password policy when set totrue.To remove the password policy, you can use a
PATCHrequest withnullas the value forenablePasswordPolicy. In this case, the other password policy parameters are reset.minLength: Specifies the minimum number of characters that the password must have.complexity: Checks if the password is a combination of lowercase, uppercase, numeric, and non-alphanumeric characters. The default value isCOMPLEXITY_DEFAULT.reuseInterval: Specifies the number of previous passwords that you can't reuse.disallowUsernameSubstring: Prevents the use of the username in the password when set totrue.passwordChangeInterval: Specifies the minimum duration after which you can change the password. The value is in seconds with up to nine fractional digits, terminated bys. For example,3.5s.
To create the instance so that it can integrate with Agent Platform, include the enableGoogleMlIntegration object in the request. This integration lets you apply large language models (LLMs), which are hosted in Agent Platform, to a Cloud SQL for PostgreSQL database.
Set the following parameters, as required:
enableGoogleMlIntegration: when this parameter is set totrue, Cloud SQL instances can connect to Agent Platform to pass requests for real-time predictions and insights to the AIcloudsql.enable_google_ml_integration: when this parameter is set toon, Cloud SQL can integrate with Agent Platform
You can use the sqlNetworkArchitecture field to enforce the use of the new network
architecture for the instance upon creation, even if the project isn't fully upgraded.
For more details about the new network architecture and its implications, see
Upgrade an instance to the new network architecture and Allocate an IP address range.
HTTP method and URL:
POST https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances
Request JSON body:
{
"name": "INSTANCE_ID",
"region": "REGION",
"databaseVersion": "DATABASE_VERSION",
"rootPassword": "PASSWORD",
"settings": {
"tier": "MACHINE_TYPE",
"edition": "EDITION_TYPE",
"enableGoogleMlIntegration": "true" | "false"
"databaseFlags":
[
{
"name": "cloudsql.enable_google_ml_integration",
"value": "on" | "off"
}
]
"dataCacheConfig": {
"dataCacheEnabled": DATA_CACHE_ENABLED
},
"backupConfiguration": {
"enabled": true
},
"passwordValidationPolicy": {
"enablePasswordPolicy": true
"minLength": "MIN_LENGTH",
"complexity": COMPLEXITY_DEFAULT,
"reuseInterval": "REUSE_INTERVAL",
"disallowUsernameSubstring": "DISALLOW_USERNAME_SUBSTRING",
"passwordChangeInterval": "PASSWORD_CHANGE_INTERVAL"
},
"ipConfiguration": {
"privateNetwork": "PRIVATE_NETWORK",
"authorizedNetworks": [AUTHORIZED_NETWORKS],
"ipv4Enabled": false,
"enablePrivatePathForGoogleCloudServices": true,
"serverCaMode": "CA_MODE",
"serverCertificateRotationMode": "SERVER_CERTIFICATE_ROTATION_MODE",
"customSubjectAlternativeNames": "DNS_NAMES"
},
"dataApiAccess": "ALLOW_DATA_API"
},
"sqlNetworkArchitecture": "NEW_NETWORK_ARCHITECTURE"
}
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2019-09-25T22:19:33.735Z",
"operationType": "CREATE",
"name": "OPERATION_ID",
"targetId": "INSTANCE_ID",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",
"targetProject": "PROJECT_ID"
}
The response is a long-running operation, which might take a few minutes to complete.
Retrieve the IPv4 address
Retrieve the automatically assigned IPv4 address for the new instance:
Before using any of the request data, make the following replacements:
- project-id: your project ID
- instance-id: instance ID created in prior step
HTTP method and URL:
GET https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{
"kind": "sql#instance",
"state": "RUNNABLE",
"databaseVersion": "MYSQL_8_0_18",
"settings": {
"authorizedGaeApplications": [],
"tier": "db-f1-micro",
"kind": "sql#settings",
"pricingPlan": "PER_USE",
"replicationType": "SYNCHRONOUS",
"activationPolicy": "ALWAYS",
"ipConfiguration": {
"authorizedNetworks": [],
"ipv4Enabled": true
},
"locationPreference": {
"zone": "us-west1-a",
"kind": "sql#locationPreference"
},
"dataDiskType": "PD_SSD",
"backupConfiguration": {
"startTime": "18:00",
"kind": "sql#backupConfiguration",
"enabled": true,
"binaryLogEnabled": true
},
"settingsVersion": "1",
"storageAutoResizeLimit": "0",
"storageAutoResize": true,
"dataDiskSizeGb": "10"
},
"etag": "--redacted--",
"ipAddresses": [
{
"type": "PRIMARY",
"ipAddress": "10.0.0.1"
}
],
"serverCaCert": {
...
},
"instanceType": "CLOUD_SQL_INSTANCE",
"project": "project-id",
"serviceAccountEmailAddress": "redacted@gcp-sa-cloud-sql.iam.gserviceaccount.com",
"backendType": "SECOND_GEN",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id",
"connectionName": "project-id:region:instance-id",
"name": "instance-id",
"region": "us-west1",
"gceZone": "us-west1-a"
}
Look for the ipAddress field in the response.
REST v1beta4
Create the instance
This example creates an instance. Some optional parameters, such as backups and binary logging are also included. For a complete list of parameters for this call, see the instances:insert page. For information about instance settings, including valid values for region, see Instance settings
Don't include sensitive or personally identifiable information
in your instance ID; it is externally visible.
You do not need to include the project ID in the instance name. This is done automatically where
appropriate (for example, in the log files).
Before using any of the request data, make the following replacements:
- PROJECT_ID: your project ID
- INSTANCE_ID: your instance ID
- REGION: the region
- DATABASE_VERSION: enum string of the database version (for example,
POSTGRES_18) - PASSWORD: the password for the root user
- MACHINE_TYPE: enum string of the machine (tier) type, as:
db-custom-[CPUS]-[MEMORY_MBS] EDITION_TYPE: your Cloud SQL edition
- DATA_CACHE_ENABLED: (optional) set to
trueto enable data cache for your instance - PRIVATE_NETWORK: Specify the name of the Virtual Private Cloud (VPC) network that you want to use for this instance. Private services access must already be configured for the network.
- AUTHORIZED_NETWORKS: For public IP connections, specify the connections from authorized networks that can connect to your instance.
- CA_MODE: specify a
certificate authority hierarchy
for the instance, either
GOOGLE_MANAGED_INTERNAL_CAorGOOGLE_MANAGED_CAS_CA. If you don't specifyserverCaMode, then the default configuration isGOOGLE_MANAGED_INTERNAL_CA. This feature is in Preview. - SERVER_CERTIFICATE_ROTATION_MODE: For automatic server certificate rotation for your instance, specify
AUTOMATIC_ROTATION_DURING_MAINTENANCE. If you don't specifyserverCertificateRotationMode, then the default configuration isNO_AUTOMATIC_ROTATION. - DNS_NAMES: add a comma-separated list of up to three DNS names to the server certificate of your Cloud SQL instance. You can secure multiple DNS names with a single certificate. This feature is available in Preview and for
CUSTOMER_MANAGED_CAS_CAinstances only.
To set a password policy while creating an instance, include the passwordValidationPolicy object in the request. Set the following parameters, as required:
enablePasswordPolicy: Enables the password policy when set totrue.To remove the password policy, you can use a
PATCHrequest withnullas the value forenablePasswordPolicy. In this case, the other password policy parameters are reset.minLength: Specifies the minimum number of characters that the password must have.complexity: Checks if the password is a combination of lowercase, uppercase, numeric, and non-alphanumeric characters. The default value isCOMPLEXITY_DEFAULT.reuseInterval: Specifies the number of previous passwords that you can't reuse.disallowUsernameSubstring: Prevents the use of the username in the password when set totrue.passwordChangeInterval: Specifies the minimum duration after which you can change the password. The value is in seconds with up to nine fractional digits, terminated bys. For example,3.5s.
To create the instance so that it can integrate with Agent Platform, include the enableGoogleMlIntegration object in the request. This integration lets you apply large language models (LLMs), which are hosted in Agent Platform, to a Cloud SQL for PostgreSQL database.
Set the following parameters, as required:
enableGoogleMlIntegration: when this parameter is set totrue, Cloud SQL instances can connect to Agent Platform to pass requests for real-time predictions and insights to the AIcloudsql.enable_google_ml_integration: when this parameter is set toon, Cloud SQL can integrate with Agent Platform
You can use the sqlNetworkArchitecture field to enforce the use of the new network
architecture for the instance upon creation, even if the project isn't fully upgraded.
For more details about the new network architecture and its implications, see
Upgrade an instance to the new network architecture and Allocate an IP address range.
HTTP method and URL:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances
Request JSON body:
{
"name": "INSTANCE_ID",
"region": "REGION",
"databaseVersion": "DATABASE_VERSION",
"rootPassword": "PASSWORD",
"settings": {
"tier": "MACHINE_TYPE",
"edition": "EDITION_TYPE",
"enableGoogleMlIntegration": "true" | "false"
"databaseFlags":
[
{
"name": "cloudsql.enable_google_ml_integration",
"value": "on" | "off"
}
]
"dataCacheConfig": {
"dataCacheEnabled": DATA_CACHE_ENABLED
},
"backupConfiguration": {
"enabled": true
},
"passwordValidationPolicy": {
"enablePasswordPolicy": true
"minLength": "MIN_LENGTH",
"complexity": COMPLEXITY_DEFAULT,
"reuseInterval": "REUSE_INTERVAL",
"disallowUsernameSubstring": "DISALLOW_USERNAME_SUBSTRING",
"passwordChangeInterval": "PASSWORD_CHANGE_INTERVAL"
},
"ipConfiguration": {
"privateNetwork": "PRIVATE_NETWORK",
"authorizedNetworks": [AUTHORIZED_NETWORKS],
"ipv4Enabled": false,
"enablePrivatePathForGoogleCloudServices": true,
"serverCaMode": "CA_MODE",
"serverCertificateRotationMode": "SERVER_CERTIFICATE_ROTATION_MODE",
"customSubjectAlternativeNames": "DNS_NAMES"
},
"dataApiAccess": "ALLOW_DATA_API"
},
"sqlNetworkArchitecture": "NEW_NETWORK_ARCHITECTURE"
}
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/INSTANCE_ID",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-01T19:13:21.834Z",
"operationType": "CREATE",
"name": "OPERATION_ID",
"targetId": "INSTANCE_ID",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",
"targetProject": "PROJECT_ID"
}
The response is a long-running operation, which might take a few minutes to complete.
Retrieve the IPv4 address
Retrieve the automatically assigned IPv4 address for the new instance:
Before using any of the request data, make the following replacements:
- project-id: your project ID
- instance-id: instance ID created in prior step
HTTP method and URL:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{
"kind": "sql#instance",
"state": "RUNNABLE",
"databaseVersion": "MYSQL_8_0_18",
"settings": {
"authorizedGaeApplications": [],
"tier": "db-f1-micro",
"kind": "sql#settings",
"pricingPlan": "PER_USE",
"replicationType": "SYNCHRONOUS",
"activationPolicy": "ALWAYS",
"ipConfiguration": {
"authorizedNetworks": [],
"ipv4Enabled": true
},
"locationPreference": {
"zone": "us-west1-a",
"kind": "sql#locationPreference"
},
"dataDiskType": "PD_SSD",
"backupConfiguration": {
"startTime": "18:00",
"kind": "sql#backupConfiguration",
"enabled": true,
"binaryLogEnabled": true
},
"settingsVersion": "1",
"storageAutoResizeLimit": "0",
"storageAutoResize": true,
"dataDiskSizeGb": "10"
},
"etag": "--redacted--",
"ipAddresses": [
{
"type": "PRIMARY",
"ipAddress": "10.0.0.1"
}
],
"serverCaCert": {
...
},
"instanceType": "CLOUD_SQL_INSTANCE",
"project": "project-id",
"serviceAccountEmailAddress": "redacted@gcp-sa-cloud-sql.iam.gserviceaccount.com",
"backendType": "SECOND_GEN",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id",
"connectionName": "project-id:region:instance-id",
"name": "instance-id",
"region": "us-west1",
"gceZone": "us-west1-a"
}
Look for the ipAddress field in the response.
Generate the write endpoint
A write endpoint is a global domain name service (DNS) name that resolves to the IP address of the current primary instance automatically. This endpoint redirects incoming connections to the new primary instance automatically in case of a replica failover or switchover operation. You can use the write endpoint in a SQL connection string instead of an IP address. By using a write endpoint, you can avoid having to make application connection changes when a region outage occurs.
For more information about using a write endpoint to connect to an instance, see Connect to an instance using a write endpoint.
Custom instance configurations
Determines memory and virtual cores available for your Cloud SQL instance. Machine types are part of a machine series, and machine series availability is determined by your Cloud SQL edition.
For Cloud SQL Enterprise Plus edition instances, Cloud SQL
offers predefined machine types for your instances in
the N2 and C4A
machine series.
For Cloud SQL Enterprise edition instances, Cloud SQL offers the
general purpose shared core, general purpose dedicated core,
and the N4 machine series.
If you require real-time processing, such as online transaction processing (OLTP), make sure that your instance has enough memory to contain the entire working set. However, there are other factors that can impact memory requirements, such as number of active connections, and internal overhead processes. Perform load testing to avoid performance issues in your production environment.
When you configure your instance, select sufficient memory and vCPUs to handle your needs, and scale up your instance as your requirements increase. A machine configuration with insufficient vCPUs might lose its SLA coverage. For more information, see Operational guidelines.
To learn more about the machine types and machine series available for your Cloud SQL instance, see Machine series overview.
Troubleshoot
What's next
- Create a PostgreSQL database on the instance.
- Create PostgreSQL users on the instance.
- Secure and control access to the instance.
- Connect to the instance with a PostgreSQL client.
- Import data into the database.
- Learn about instance settings.
