Create instances

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 values for vCPUs and memory size

When creating a Cloud SQL for SQL Server instance, 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. Click Choose SQL Server.
  4. 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).

  5. Enter a password for the user.
  6. Select the database version for your instance. To see the available versions, click the drop-down arrow.
  7. 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.

  8. In the Customize your instance section, update the settings for your instance. For example, you can prevent accidental instance deletion.
  9. Click Create.
  10. 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:
    gcloud beta sql instances create INSTANCE_NAME \
    --database-version=SQLSERVER_2017_STANDARD \
    --region=REGION_NAME \
    --cpu=NUMBER_OF_vCPUs \
    --memory=MEMORY_SIZE \
    --root-password=ROOT-PASSWORD
    

    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. See Choosing values for vCPUs and memory size.

    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
    

    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 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) enables you to set a permanent, default time zone for an instance. For the JSON representation that includes this field, see Settings. Here is an example string you could specify for the timeZone field: "Pacific Standard Time". Learn 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 desired instance ID
  • region: The desired region
  • database-version: Enum string of the database version. For example: SQLSERVER_2017_STANDARD
  • password: The password for the root user
  • machine-type: Enum string of the machine (tier) type, as: db-custom-[CPUS]-[MEMORY_MBS]

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

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

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

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