Creating instances

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

For detailed information about all instance settings, see Instance Settings.

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

Creating an instance

Console

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

    Go to the Cloud SQL Instances page

  2. Click Create instance.
  3. Select SQL Server and click Next.
  4. Enter a name.

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

  5. Enter a password for the user.
  6. Under Location, 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.

  7. Under Configuration options, update any other settings you need for your instance:

    Setting Notes
    Database version
    Database version SQL Server 2017 Standard (default)
    SQL Server 2017 Enterprise
    SQL Server 2017 Express
    SQL Server 2017 Web
    Connectivity
    Private IP Adds a private IP address for your instance. To enable connecting to the instance, additional configuration is required.
    Public IP Adds a public IP address for your instance. To enable connecting to the instance, additional configuration is required.
    Machine type and storage
    Cores The number of vCPUs for your instance. Learn more.
    Memory The amount of memory for your instance, in GBs. Learn more.
    Storage type Indicates that your instance uses SSD storage. All SQL Server instances use SSD storage. Learn more.
    Storage capacity The amount of storage provisioned for the instance. Learn more.
    Automatic storage increase Determines whether Cloud SQL automatically provides more storage for your instance when free space runs low. Learn more.
    Automatic backups and high availability
    High availability If you need your instance to be configured for high availability, you must select the High availability (regional) option. Learn more.
    Automatic backups The window of time when you would like backups to start.
    Retention settings for automatic backups The number of automated backups you would like to retain (from 1 to 365 days). Learn more.
    Authorized networks
    Database flags
    Flags and parameters You can use database flags to control settings and parameters for your instance. Learn more.

    Additionally, you can set a default value for the type of collation used for the databases in your instance. Under Default collation, in the dropdown menu, you can specify a default value for sorting data and related operations. This value determines the default sorting rules, case, and accent sensitivity for databases of this instance, which can save effort later. 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.
    Maintenance schedule
    Maintenance window Determines a one-hour window when Cloud SQL can perform disruptive maintenance on your instance. If you do not set the window, then disruptive maintenance can be done at any time. Learn more.
    Maintenance timing Your preferred timing for instance updates, relative to other instances in the same project. Learn more.
  8. Click Create.
  9. After the instance finishes initializing, click the instance name to open it.

gcloud

For information about installing and getting started with the gcloud command-line tool, see Installing Cloud SDK. For information about starting Cloud Shell, see the Cloud Shell documentation.

Until early March 2020, use the beta version of the gcloud sql instances create command. That is, use the gcloud beta sql instances create command.

Additionally, you must use gcloud version 243.0.0 or later.

  1. Create the instance:
    gcloud sql instances create [INSTANCE_NAME] \
    --database-version=SQLSERVER_2017_STANDARD \
    --cpu=[NUMBER_CPUS] \
    --memory=[MEMORY_SIZE] \
    --root-password=[INSERT-PASSWORD-HERE]
    

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

    There are restrictions on the values for vCPUs and memory size:

    Standard options (lightweight and high memory options are also available. See the Google Cloud Console for more information):

    Version CPU / Memory
    SQL Server 2017 Express Select from preset options:
    • 1vCPU, 3.75 GB
    • 2vCPU, 3.75 GB
    • 4vCPU, 3.75 GB
    SQL Server 2017 Web Select from preset or custom options:
    • 1vCPU, 4 GB
    • 2vCPUs, 8 GB
    • 4vCPUs, 16 GB
    • 1-16 vCPUs, 4 to 64 GB
    SQL Server 2017 Standard Select from preset or custom options:
    • 1vCPU, 4 GB
    • 2vCPUs, 8 GB
    • 4vCPUs, 16 GB
    • 1-24 vCPUs, 4 to 104 GB
    SQL Server 2017 Enterprise Select from preset or custom options:
    • 2vCPU, 8 GB
    • 4vCPU, 16 GB
    • 2-96 vCPUs, 8 to 104 GB

    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 \
    --cpu=2 \
    --memory=7680MB \
    --root-password=[INSERT-PASSWORD-HERE]
    

    For some sample values, see Sample machine types.

    You can also create a shared-core instance by using --tier db-f1-micro or --tier db-g1-small and dropping the --cpu and --memory parameters.

    You can add more parameters to determine other instance settings:

    Setting Parameter Notes
    Required parameters
    Database version --database-version SQLSERVER_2017_STANDARD, SQLSERVER_2017_ENTERPRISE, SQLSERVER_2017_EXPRESS, or SQLSERVER_2017_WEB
    Region --region See valid values.
    Connectivity
    Private IP --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). Learn more.
    Public IP --authorized-networks For public IP connections, only connections from authorized networks can connect to your instance. Learn more.
    Machine type and storage
    Machine type --tier Used to specify a shared-core instance (db-f1-micro or db-g1-small). You cannot specify the --cpu or --memory parameters if you use this parameter.
    Storage type --storage-type Indicates that your instance uses SSD storage (all SQL Server instances use SSD 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.
    Automatic backups and high availability
    High availability --availability-type For a highly-available instance, set to REGIONAL. Learn more.
    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.
    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. Learn more about how to format this parameter.
    Add a default collation
    Default collation --collation You can set a default value for the type of collation used for the databases in your instance. For example, you could specify the following value for this parameter:
    SQL_Latin1_General_CP1_CI_AS

    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.
    Set 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 do not 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.
  2. Note the automatically-assigned IP address.

    If you are not using the Cloud SQL 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]
    

REST v1beta4

1. Create the instance

For a complete list of parameters for this call, see the Instances:insert page. For information about instance settings, including valid values for region and machine type, see Instance settings.

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 tier parameter contains a string representing the number of CPUs and the amount of memory for the new instance. The string has the following format: db-custom-[CPUS]-[MEMORY_MBS]. For some examples, see Sample machine types. Additionally, you can create a shared-core instance by supplying db-f1-micro or db-g1-small as the value of the tier parameter.

The collation parameter (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 body, see Settings. Here is an example string you could specify for the collation parameter: SQL_Latin1_General_CP1_CI_AS.

Before using any of the request data below, 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://www.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://www.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://www.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 below, 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://www.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://www.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id",
  "connectionName": "project-id:region:instance-id",
  "name": "instance-id",
  "region": "region",
  "gceZone": "zone"
}

Sample machine types

With custom machine types, you can configure your instance with the amount of memory and CPUs that it needs. However, there are some restrictions on these values:

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

Here are some sample machine type values, based on the predefined machine types available for SQL Server instances:

Predefined machine type vCPUs Memory (MBs) API tier string
db-n1-standard-1 1 3840 db-custom-1-3840
db-n1-standard-2 2 7680 db-custom-2-7680
db-n1-standard-4 4 15360 db-custom-4-15360
db-n1-standard-8 8 30720 db-custom-8-30720
db-n1-standard-16 16 61440 db-custom-16-61440
db-n1-standard-32 32 122880 db-custom-32-122880
db-n1-standard-64 64 245760 db-custom-64-245760
db-n1-standard-96 96 368640 db-custom-96-368640
db-n1-highmem-2 2 13312 db-custom-2-13312
db-n1-highmem-4 4 26624 db-custom-4-26624
db-n1-highmem-8 8 53248 db-custom-8-53248
db-n1-highmem-16 16 106496 db-custom-16-106496
db-n1-highmem-32 32 212992 db-custom-32-212992
db-n1-highmem-64 64 425984 db-custom-64-425984
db-n1-highmem-96 96 638976 db-custom-96-638976

What's next