Create an instance

This page describes how to create a Cloud SQL for SQL Server instance.

For detailed information about all of the instance settings, see Instance settings.

A newly-created instance has a sqlserver database.

After creating a Cloud SQL instance, you add databases to it by creating or importing them.

Choose between Cloud SQL Enterprise Plus edition and Cloud SQL Enterprise edition

When creating a Cloud SQL for SQL Server instance, you have different machine families to choose from with several machine configurations, depending on the Cloud SQL edition.

With Cloud SQL Enterprise Plus edition, you have two machine families to choose from:

  • Performance-optimized: offers a balanced price performance for various SQL Server workloads with a memory-to-compute ratio of 1 vCPU:8 GB RAM.
  • Memory-optimized: offers high-memory-to-compute ratios for memory-intensive workloads with 1 vCPU:32 GB RAM. Memory-optimized machines are well suited for SQL Server workloads requiring complex queries, analytics, and business intelligence reporting that benefit from storing larger datasets in memory during data processing.

With Cloud SQL Enterprise edition, you have several machine configurations to choose from, based on your vCPU and memory requirements. The following sections show the vCPU and memory configuration for each database version and machine type:

SQL Server 2017 Express, SQL Server 2019 Express, and SQL Server 2022 Express

Machine type vCPU/Memory
Lightweight
  • 1 vCPU, 3.75 GB
  • 2 vCPUs, 3.75 GB
  • 4 vCPUs, 3.75 GB
Standard
  • 1 vCPU, 3.75 GB
  • 2 vCPUs, 7.50 GB
  • 4 vCPUs, 15 GB
High Memory
  • 4 vCPUs, 26 GB
  • 8 vCPUs, 52 GB
Custom 1 to 8 vCPUs, 3.75 GB to 52 GB

SQL Server 2017 Web, SQL Server 2019 Web, and SQL Server 2022 Web

Machine type vCPU/Memory
Lightweight
  • 1 vCPU, 3.75 GB
  • 2 vCPUs, 3.75 GB
  • 4 vCPUs, 3.75 GB
Standard
  • 1 vCPU, 3.75 GB
  • 2 vCPUs, 7.50 GB
  • 4 vCPUs, 15 GB
High Memory
  • 4 vCPUs, 26 GB
  • 8 vCPUs, 52 GB
  • 16 vCPUs, 104 GB
Custom 1 to 32 vCPUs, 3.75 GB to 208 GB

SQL Server 2017 Standard, SQL Server 2019 Standard, and SQL Server 2022 Standard

Machine type vCPU/Memory
Lightweight
  • 1 vCPU, 3.75 GB
  • 2 vCPUs, 3.75 GB
  • 4 vCPUs, 3.75 GB
Standard
  • 1 vCPU, 3.75 GB
  • 2 vCPUs, 7.50 GB
  • 4 vCPUs, 15 GB
High Memory
  • 4 vCPUs, 26 GB
  • 8 vCPUs, 52 GB
  • 16 vCPUs, 104 GB
Custom 1 to 48 vCPUs, 3.75 GB to 312 GB

SQL Server 2017 Enterprise, SQL Server 2019 Enterprise, and SQL Server 2022 Enterprise

Machine type vCPU/Memory
Lightweight
  • 2 vCPUs, 3.75 GB
  • 4 vCPUs, 3.75 GB
Standard
  • 2 vCPUs, 7.50 GB
  • 4 vCPUs, 15 GB
High Memory
  • 4 vCPUs, 26 GB
  • 8 vCPUs, 52 GB
  • 16 vCPUs, 104 GB
Custom 2 to 96 vCPUs, 3.75 GB to 624 GB

Simultaneous multithreading

Simultaneous multithreading (SMT) on Cloud SQL for SQL Server enables you to run two virtual CPUs (vCPUs) as independent, separate threads on one physical core. SMT is enabled by default; however, you can disable it, and this might reduce your licensing costs.

Disabling SMT might impact your instance performance. To understand the impact of disabling SMT on your instance's performance, we recommend that you perform load testing on your instance.

Create an instance

Console

  1. Go to the Cloud SQL Instances page in the Google Cloud console.

    Go to Cloud SQL Instances

  2. Click Create instance.
  3. On the Choose your database engine panel of the Create an instance page, click Choose SQL Server.
  4. In the Choose a Cloud SQL edition section of the Create a SQL Server instance page, select the Cloud SQL edition for your instance: Enterprise or Enterprise plus.

    For more information about Cloud SQL editions, see Introduction to Cloud SQL for SQL Server editions.

  5. Select the edition preset for your instance. To see the available presets, click the Edition preset menu.
  6. In the Instance info section, select the database version for your instance. To see the available versions, click the Database version menu.
  7. In the Instance ID field, 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).

  8. In the Password field, enter a password for the user.
  9. In the Choose region and zonal availability section, select the region and zone for your instance.

    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.

  10. In the Customize your instance section, update the settings for your instance. For example, you can prevent accidental instance deletion.
  11. Click Create instance.
  12. After the initialization process of the instance completes, click the instance name to open it.

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.

You must use gcloud version 243.0.0 or later.

For information about protecting an instance against accidental deletion, see Prevent deletion of an instance.

  1. Create the instance:
    For Cloud SQL Enterprise Plus edition instances:
    gcloud sql instances create INSTANCE_NAME \
    --database-version=DATABASE_VERSION \
    --region=REGION \
    --tier=TIER \
    --root-password=ROOT_PASSWORD
    --edition=ENTERPRISE_PLUS
    For Cloud SQL Enterprise edition instances:
    gcloud sql instances create INSTANCE_NAME \
    --database-version=DATABASE_VERSION \
    --region=REGION \
    --cpu=NUMBER_OF_vCPUs \
    --memory=MEMORY_SIZE \
    --root-password=ROOT_PASSWORD
    --edition=ENTERPRISE

    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).

    As noted earlier on this page, the values for vCPUs and memory size are limited for Cloud SQL Enterprise edition. See Choose between Cloud SQL Enterprise Plus edition and Cloud SQL Enterprise edition.

    For example, the following string creates an instance with two vCPUs and 7,680 MB of memory:

    gcloud sql instances create myinstance \
    --database-version=SQLSERVER_2017_STANDARD \
    --region=us-central1 \
    --cpu=2 \
    --memory=7680MB \
    --root-password=EXAMPLE_PASSWORD
    --edition=ENTERPRISE

    For some sample values, see Sample machine types.

    To learn about the parameters for instance settings, see gcloud sql instances create.

  2. Note the automatically-assigned IP address.

    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.

  3. Set the password for the user:
    gcloud sql users set-password sqlserver no-host --instance=[INSTANCE_NAME] \
           --password=[PASSWORD]

Terraform

To create an instance, use a Terraform resource.

resource "google_sql_database_instance" "instance" {
  name             = "sqlserver-instance"
  region           = "us-central1"
  database_version = "SQLSERVER_2019_STANDARD"
  root_password    = "INSERT-PASSWORD-HERE"
  settings {
    tier = "db-custom-2-7680"
  }
  # set `deletion_protection` to true, will ensure that one cannot accidentally delete this instance by
  # use of Terraform whereas `deletion_protection_enabled` flag protects this instance at the GCP level.
  deletion_protection = false
}

REST v1

1. Create the instance

Not all possible fields are shown in the basic API call below. For a prototype of a JSON request, see Settings.

Also see the Instances:insert page. For information about instance settings, including valid values for regions, see Instance settings. For information about machine types, see Custom instance configurations.

Do not include sensitive or personally identifiable information in instance-id; the value 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).

The collation field (not shown in the basic API call below) enables you to set a default value for the type of collation used for the databases in your instance. This collation default is permanent at the instance level but not at the database level. You can change this default with a database administration tool, but only for a specific database that you are creating or updating. You cannot change the collation default for an instance after creating the instance (unless you recreate the instance). For information about collations in SQL Server, see Collation and Unicode support. For a prototype of a JSON request, see Settings. Here is an example string you could specify for the collation parameter: SQL_Latin1_General_CP1_CI_AS.

The timeZone field (not shown in the basic API call below) lets you to set a time zone for an instance. After you create an instance, you can change the time zone of an instance. For more information and a list of accepted strings, see Settings. Here is an example string you could specify for the timeZone field: "Pacific Standard Time". See more.

To create an instance that is integrated with Managed Microsoft AD, specify a domain, such as subdomain.mydomain.com, for the domain field. For more information, see Creating an instance with Windows Authentication. Additionally, note the procedures and constraints for integrating with a managed AD domain in a different project.

For information on setting the value of machine-type in the request body, see Custom instance configurations.

Before using any of the request data, make the following replacements:

  • PROJECT_ID: your project ID.
  • INSTANCE_ID: the instance ID.
  • REGION: the region name.
  • DATABASE_VERSION: an enum string of the database version. For example: SQLSERVER_2017_STANDARD.
  • PASSWORD: the password for the root user.
  • MACHINE_TYPE: an enum string of the machine (tier) type. For example:
    db-perf-optimized-N-4.
  • EDITION_TYPE: your Cloud SQL edition. The default value is ENTERPRISE.
  • DATA_CACHE_ENABLED: (optional) to enable Data cache for your instance, set the value of this parameter to true.

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",
    "backupConfiguration": {
      "enabled": true
    },
    "dataCacheConfig" = {
      "dataCacheEnabled": DATA_CACHE_ENABLED
    },
  }
}

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": "2020-01-01T19:13:21.834Z",
  "operationType": "CREATE",
  "name": "OPERATION_ID",
  "targetId": "INSTANCE_ID",
  "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",
  "targetProject": "PROJECT_ID"
}

After the instance is created, you can further configure the default user account.

2. Retrieve the IPv4 address of the instance

Optionally, you can retrieve the automatically-assigned IPv4 address. In the response, that address is in the ipAddress field.

Before using any of the request data, make the following replacements:

  • PROJECT_ID: your project ID
  • INSTANCE_ID: your instance ID, created in the previous 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": "DATABASE_VERSION",
  "settings": {
    "authorizedGaeApplications": [],
    "tier": "MACHINE_TYPE",
    "kind": "sql#settings",
    "pricingPlan": "PER_USE",
    "replicationType": "SYNCHRONOUS",
    "activationPolicy": "ALWAYS",
    "ipConfiguration": {
      "authorizedNetworks": [],
      "ipv4Enabled": true
    },
    "locationPreference": {
      "zone": "ZONE",
      "kind": "sql#locationPreference"
    },
    "dataDiskType": "PD_SSD",
    "backupConfiguration": {
      "startTime": "19:00",
      "kind": "sql#backupConfiguration",
      "enabled": true
    },
    "settingsVersion": "1",
    "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": "BACKEND_TYPE",
  "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID",
  "connectionName": "PROJECT_ID:REGION:INSTANCE_ID",
  "name": "INSTANCE_ID",
  "region": "REGION",
  "gceZone": "ZONE"
}

REST v1beta4

1. Create the instance

Not all possible fields are shown in the basic API call below. For a prototype of a JSON request, see Settings.

Also see the Instances:insert page. For information about instance settings, including valid values for regions, see Instance settings. For information about machine types, see Custom instance configurations.

Do not include sensitive or personally identifiable information in instance-id; the value 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).

The collation field (not shown in the basic API call below) enables you to set a default value for the type of collation used for the databases in your instance. This collation default is permanent at the instance level but not at the database level. You can change this default with a database administration tool, but only for a specific database that you are creating or updating. You cannot change the collation default for an instance after creating the instance (unless you recreate the instance). For information about collations in SQL Server, see Collation and Unicode support. For a prototype of a JSON request, see Settings. Here is an example string you could specify for the collation parameter: SQL_Latin1_General_CP1_CI_AS.

The timeZone field (not shown in the basic API call below) lets you to set a time zone for an instance. After you create an instance, you can change the time zone of an instance. For more information and a list of accepted strings, see Settings. Here is an example string you could specify for the timeZone field: "Pacific Standard Time". See more.

To create an instance that is integrated with Managed Microsoft AD, specify a domain, such as subdomain.mydomain.com, for the domain field. For more information, see Creating an instance with Windows Authentication. Additionally, note the procedures and constraints for integrating with a managed AD domain in a different project.

For information on setting the value of machine-type in the request body, see Custom instance configurations.

Before using any of the request data, make the following replacements:

  • PROJECT_ID: your project ID.
  • INSTANCE_ID: the instance ID.
  • REGION: the region name.
  • DATABASE_VERSION: an enum string of the database version.
  • MACHINE_TYPE: an enum string of the machine (tier) type. For example:
    db-perf-optimized-N-4.
  • PASSWORD: the password for the root user.
  • MACHINE_TYPE: an enum string of the machine (tier) type, as: db-custom-[CPUS]-[MEMORY_MBS].
  • EDITION_TYPE: your Cloud SQL edition. The default value is ENTERPRISE.
  • DATA_CACHE_ENABLED: (optional) to enable Data cache for your instance, set the value of this parameter to true.

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",
    "backupConfiguration": {
      "enabled": true
    },
    "dataCacheConfig" = {
      "dataCacheEnabled": DATA_CACHE_ENABLED
    },
  }
}

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"
}

After the instance is created, you can further configure the default user account.

2. Retrieve the IPv4 address of the instance

Optionally, you can retrieve the automatically-assigned IPv4 address. In the response, that address is in the ipAddress field.

Before using any of the request data, make the following replacements:

  • PROJECT_ID: your project ID
  • INSTANCE_ID: your instance ID, created in the previous 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": "DATABASE_VERSION",
  "settings": {
    "authorizedGaeApplications": [],
    "tier": "MACHINE_TYPE",
    "kind": "sql#settings",
    "pricingPlan": "PER_USE",
    "replicationType": "SYNCHRONOUS",
    "activationPolicy": "ALWAYS",
    "ipConfiguration": {
      "authorizedNetworks": [],
      "ipv4Enabled": true
    },
    "locationPreference": {
      "zone": "ZONE",
      "kind": "sql#locationPreference"
    },
    "dataDiskType": "PD_SSD",
    "backupConfiguration": {
      "startTime": "19:00",
      "kind": "sql#backupConfiguration",
      "enabled": true
    },
    "settingsVersion": "1",
    "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": "BACKEND_TYPE",
  "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/INSTANCE_ID",
  "connectionName": "PROJECT_ID:REGION:INSTANCE_ID",
  "name": "INSTANCE_ID",
  "region": "REGION",
  "gceZone": "ZONE"
}

Generate the write endpoint

If you plan to create a Cloud SQL Enterprise Plus edition instance, and you want Cloud SQL to generate a write endpoint automatically for the instance, then enable the Cloud DNS API for your Google Cloud project.

If you already have a Cloud SQL Enterprise Plus edition instance and you want Cloud SQL to generate a write endpoint automatically, then create a replica that's enabled for advanced disaster recovery.

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 regional outage occurs.

For more information about obtaining the write endpoint for the instance, see View instance information. For more information about using the write endpoint to connect to the instance, see Connect by using a write endpoint.

Custom instance configurations

Custom instance configurations let you select the amount of memory and CPUs that your instance needs. This flexibility lets you choose the appropriate VM shape for your workload. Machine type availability is determined by your Cloud SQL edition.

For workloads that require real-time processing, 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. You should perform load testing to avoid performance issues in your production environment.

When you configure your instance, select enough memory and vCPUs to handle your workload, and upgrade as your workload increases. A machine configuration with insufficient vCPUs could lose its SLA coverage. For more information, see Operational guidelines.

Machine types for Cloud SQL Enterprise edition instances

For Cloud SQL Enterprise edition instances, you can also create custom instance configurations using the gcloud sql instances create command.

Machine type names use the following format: db-custom-NUMBER_OF_vCPUs-MEMORY

Replace NUMBER_OF_vCPUs with the number of CPUs in the machine and MEMORY with the amount of memory in the machine.

For example, if your machine name is db-custom, and your machine has 1 CPU and 3840 MB of RAM, then the format for the machine is db-custom-1-3840.

When selecting the number of CPUs and amount of memory, there are some restrictions on the configuration that you choose:

  • The number of vCPUs that you can configure for your instance is based on your SQL server version.
  • The number of vCPUs must be either 1 or an even number between 2 and 96.
  • The memory size must be:
    • 0.9 to 6.5 GB per vCPU
    • A multiple of 256 MB
    • At least 3.75 GB (3840 MB)

Machine types for Cloud SQL Enterprise Plus edition instances

For Cloud SQL Enterprise Plus edition instances, machine types are predefined as described in the following sections.

Performance-optimized machine family

This machine family offers balanced price-performance for a wide variety of SQL Server workloads with a memory to compute ratio of 1 vCPU:8 GB RAM. The performance-optimized machine family provides the following machine types to choose from:

Enterprise plus machine type vCPUs Memory (GB)
db-perf-optimized-N-2 2 16
db-perf-optimized-N-4 4 32
db-perf-optimized-N-8 8 64
db-perf-optimized-N-16 16 128
db-perf-optimized-N-32 32 256
db-perf-optimized-N-48 48 384
db-perf-optimized-N-64 64 512
db-perf-optimized-N-80 80 640
db-perf-optimized-N-96 96 768
db-perf-optimized-N-128 128 864

Memory-optimized machine family

This machine family offers high memory to compute ratios for memory-intensive workloads with 1 vCPU:32 GB RAM. Memory-optimized machines are well suited for SQL Server workloads requiring complex queries, analytics and business intelligence reporting that benefit from storing larger datasets in memory during data processing. Memory-optimized machine family provides the following machine types to choose from:

Machine type vCPUs Memory (GB)
db-memory-optimized-N-4 4 128
db-memory-optimized-N-8 8 256
db-memory-optimized-N-16 16 512

Troubleshoot

Issue Troubleshooting
Error message: Failed to create subnetwork. Router status is temporarily unavailable. Please try again later. Help Token: [token-ID]. Try to create the Cloud SQL instance again.

What's next