Create and manage instances

This page describes how to create, list, edit, and delete Spanner instances.

Create an instance

You can create an instance with the Google Cloud console, the Google Cloud CLI, or client libraries. You can also create an instance with a custom instance configuration by adding optional read-only replicas.

Console

  1. Go to the Create an instance page in the Google Cloud console.

    Create an instance

  2. Enter an Instance name to display in the Google Cloud console. The instance name must be unique within your Google Cloud project.

  3. Enter an Instance ID to permanently identify your instance. The instance ID must also be unique within your Google Cloud project. You cannot change the instance ID later.

  4. Under Choose a configuration, click Regional or Multi-region. Alternatively, if you want to compare the specifications between two regions, then click Compare region configurations.

  5. Select a configuration from the drop-down.

  6. Optional: Add read-only replicas to scale reads and support low latency stale reads. When you create and add a read-only replica to an instance configuration using the Google Cloud console, the custom instance configuration is created automatically. To add a read-only replica, do the following:

    1. Expand Configure read-only replicas.

    2. Click Add read-only replica.

    3. Select a region and number.

  7. In the Configure compute capacity section, under Select unit, click one of the following:

    • Processing units for small instances.
    • Nodes for large instances. A node is 1000 processing units.

    For more information, see Compute capacity, nodes and processing units.

  8. Under Choose a scaling mode, click one of the following:

    • Manual allocation if you want to manually set compute capacity for fixed compute resources and costs.

      • Quantity indicates the number of processing units or nodes to use for this instance.
    • Autoscaling (Preview), to let Spanner automatically add and remove compute capacity. For more information about the managed managed autoscaler, see Managed autoscaler for Spanner. Configure the following managed autoscaler options:

      • Minimum indicates the minimum limit to scale down to, depending on the measurement unit that you choose for Compute capacity. For more information, see Determine the minimum limit.
      • Maximum indicates the maximum limit to scale up to, depending on the measurement unit that you choose for Compute capacity. For more information, see Determine the maximum limit.
      • High priority CPU utilization target indicates the target percentage of high priority CPU to use. For more information, see Determine the CPU utilization target.
      • Storage utilization target indicates the target percentage of storage to use. For more information, see Determine the Storage Utilization Target.
  9. Click Create to create the instance.

gcloud

Use the gcloud spanner instances create command to create an instance. Specify the compute capacity as the number of nodes or processing units that you want on the instance.

gcloud spanner instances create INSTANCE-ID \
--config=INSTANCE-CONFIG \
--description=INSTANCE-DESCRIPTION \
--nodes=NODE-COUNT

or

gcloud spanner instances create INSTANCE-ID \
--config=INSTANCE-CONFIG \
--description=INSTANCE-DESCRIPTION \
--processing-units=PROCESSING-UNIT-COUNT

Replace the following:

  • INSTANCE-ID: a permanent identifier that is unique within your Google Cloud project. You cannot change the instance ID later.
  • INSTANCE-CONFIG: a permanent identifier of your instance configuration, which defines the geographic location of the instance and affects how data is replicated. For custom instance configurations, it starts with custom-. For more information, see instance configurations.
  • INSTANCE-DESCRIPTION: the name to display for the instance in the Google Cloud console. The instance name must be unique within your Google Cloud project.
  • NODE-COUNT: the compute capacity of the instance, expressed as a number of nodes. Each node equals 1000 processing units.

  • PROCESSING-UNIT-COUNT: the compute capacity of the instance, expressed as a number of processing units. Enter quantities up to 1000 in multiples of 100 (100, 200, 300 and so on) and enter greater quantities in multiples of 1000 (1000, 2000, 3000 and so on). Note: Don't use this parameter if you're creating an instance that you intend to enable with the managed autoscaler later.

Add managed autoscaling (Preview)

You can also configure new instances to use managed autoscaling with the gcloud beta spanner instances create command. For more information, see Managed autoscaler for Spanner.

Use the following command to create an instance with managed autoscaler.

  gcloud beta spanner instances create INSTANCE-ID \
    --config=INSTANCE-CONFIG \
    --description=INSTANCE-DESCRIPTION \
    --autoscaling-min-processing-units=MINIMUM_PROCESSING_UNITS \
    --autoscaling-max-processing-units=MAXIMUM_PROCESSING_UNITS \
    --autoscaling-high-priority-cpu-target=CPU_PERCENTAGE \
    --autoscaling-storage-target=STORAGE_PERCENTAGE

or

  gcloud beta spanner instances create INSTANCE-ID \
    --config=INSTANCE-CONFIG \
    --description=INSTANCE-DESCRIPTION \
    --autoscaling-min-nodes=MINIMUM_NODES \
    --autoscaling-max-nodes=MAXIMUM_NODES \
    --autoscaling-high-priority-cpu-target=CPU_PERCENTAGE \
    --autoscaling-storage-target=STORAGE_PERCENTAGE

Replace the following:

  • INSTANCE-ID: a permanent identifier that is unique within your Google Cloud project. You cannot change the instance ID later.
  • INSTANCE-CONFIG: a permanent identifier of your instance configuration, which defines the geographic location of the instance and affects how data is replicated. For custom instance configurations, it starts with custom-. For more information, see instance configurations.
  • INSTANCE-DESCRIPTION: the name to display for the instance in the Google Cloud console. The instance name must be unique within your Google Cloud project.
  • MINIMUM_PROCESSING_UNITS, MINIMUM_NODES: the minimum number of processing units or nodes when scaling down. For more information, see Determine the minimum limit.
  • MAXIMUM_PROCESSING_UNITS, MAXIMUM_NODES: the maximum number of processing units or nodes when scaling up. For more information, see Determine the maximum limit.
  • CPU_PERCENTAGE: the target percentage of high priority CPU to use, from 10 to 90%. If you're optimizing for cost, then use a higher percentage. For more information, see Determine the CPU utilization target.
  • STORAGE_PERCENTAGE: the target percentage of storage to use, from 10 to 99%. For more information, see Determine the storage utilization target.

Examples for using custom configurations

To create an instance test-instance in the base regional instance configuration us-central1, run:

gcloud spanner instances create test-instance --config=regional-us-central1 \
  --description="Test Instance" --nodes=1

To create an instance custom-eur6-instance in the custom multi-region instance configuration custom-eur6, first create a custom instance configuration.

Then, run:

  gcloud spanner instances create custom-eur6-instance --config=custom-eur6 \
      --description="Instance with custom read-only" --nodes=1

You should see a message similar to the following example after running either one of the commands above:

Creating instance...done.

C++

To learn how to install and use the client library for Spanner, see Spanner client libraries.

To authenticate to Spanner, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

void CreateInstance(google::cloud::spanner_admin::InstanceAdminClient client,
                    std::string const& project_id,
                    std::string const& instance_id,
                    std::string const& display_name,
                    std::string const& config_id) {
  namespace spanner = ::google::cloud::spanner;
  spanner::Instance in(project_id, instance_id);

  auto project = google::cloud::Project(project_id);
  std::string config_name =
      project.FullName() + "/instanceConfigs/" + config_id;
  auto instance =
      client
          .CreateInstance(spanner::CreateInstanceRequestBuilder(in, config_name)
                              .SetDisplayName(display_name)
                              .SetNodeCount(1)
                              .SetLabels({{"cloud_spanner_samples", "true"}})
                              .Build())
          .get();
  if (!instance) throw std::move(instance).status();
  std::cout << "Created instance [" << in << "]:\n" << instance->DebugString();
}

C#

To learn how to install and use the client library for Spanner, see Spanner client libraries.

To authenticate to Spanner, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.


using Google.Api.Gax.ResourceNames;
using Google.Cloud.Spanner.Admin.Instance.V1;
using Google.Cloud.Spanner.Common.V1;
using Google.LongRunning;
using System;

public class CreateInstanceSample
{
    public Instance CreateInstance(string projectId, string instanceId)
    {
        // Create the InstanceAdminClient instance.
        InstanceAdminClient instanceAdminClient = InstanceAdminClient.Create();

        // Initialize request parameters.
        Instance instance = new Instance
        {
            InstanceName = InstanceName.FromProjectInstance(projectId, instanceId),
            ConfigAsInstanceConfigName = InstanceConfigName.FromProjectInstanceConfig(projectId, "regional-us-central1"),
            DisplayName = "This is a display name.",
            NodeCount = 1,
            Labels =
            {
                { "cloud_spanner_samples", "true" },
            }
        };
        ProjectName projectName = ProjectName.FromProject(projectId);

        // Make the CreateInstance request.
        Operation<Instance, CreateInstanceMetadata> response = instanceAdminClient.CreateInstance(projectName, instanceId, instance);

        Console.WriteLine("Waiting for the operation to finish.");

        // Poll until the returned long-running operation is complete.
        Operation<Instance, CreateInstanceMetadata> completedResponse = response.PollUntilCompleted();

        if (completedResponse.IsFaulted)
        {
            Console.WriteLine($"Error while creating instance: {completedResponse.Exception}");
            throw completedResponse.Exception;
        }

        Console.WriteLine($"Instance created successfully.");

        return completedResponse.Result;
    }
}

Go

To learn how to install and use the client library for Spanner, see Spanner client libraries.

To authenticate to Spanner, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

import (
	"context"
	"fmt"
	"io"

	instance "cloud.google.com/go/spanner/admin/instance/apiv1"
	instancepb "google.golang.org/genproto/googleapis/spanner/admin/instance/v1"
)

func createInstance(w io.Writer, projectID, instanceID string) error {
	// projectID := "my-project-id"
	// instanceID := "my-instance"
	ctx := context.Background()
	instanceAdmin, err := instance.NewInstanceAdminClient(ctx)
	if err != nil {
		return err
	}
	defer instanceAdmin.Close()

	op, err := instanceAdmin.CreateInstance(ctx, &instancepb.CreateInstanceRequest{
		Parent:     fmt.Sprintf("projects/%s", projectID),
		InstanceId: instanceID,
		Instance: &instancepb.Instance{
			Config:      fmt.Sprintf("projects/%s/instanceConfigs/%s", projectID, "regional-us-central1"),
			DisplayName: instanceID,
			NodeCount:   1,
			Labels:      map[string]string{"cloud_spanner_samples": "true"},
		},
	})
	if err != nil {
		return fmt.Errorf("could not create instance %s: %w", fmt.Sprintf("projects/%s/instances/%s", projectID, instanceID), err)
	}
	// Wait for the instance creation to finish.
	i, err := op.Wait(ctx)
	if err != nil {
		return fmt.Errorf("waiting for instance creation to finish failed: %w", err)
	}
	// The instance may not be ready to serve yet.
	if i.State != instancepb.Instance_READY {
		fmt.Fprintf(w, "instance state is not READY yet. Got state %v\n", i.State)
	}
	fmt.Fprintf(w, "Created instance [%s]\n", instanceID)
	return nil
}

Create an instance with managed autoscaling using Go (Preview)

import (
	"context"
	"fmt"
	"io"

	instance "cloud.google.com/go/spanner/admin/instance/apiv1"
	"cloud.google.com/go/spanner/admin/instance/apiv1/instancepb"
	"google.golang.org/genproto/protobuf/field_mask"
)

// Example of creating an autoscaling instance with Go.
// projectID is the ID of the project that the new instance will be in.
// instanceID is the ID of the new instance to be created.
func createInstanceWithAutoscalingConfig(w io.Writer, projectID, instanceID string) error {
	// projectID := "my-project-id"
	// instanceID := "my-instance"
	ctx := context.Background()
	instanceAdmin, err := instance.NewInstanceAdminClient(ctx)
	if err != nil {
		return fmt.Errorf("could not create instance admin client for project %s: %w", projectID, err)
	}
	defer instanceAdmin.Close()

	instanceName := fmt.Sprintf("projects/%s/instances/%s", projectID, instanceID)
	fmt.Fprintf(w, "Creating instance %s.", instanceName)

	op, err := instanceAdmin.CreateInstance(ctx, &instancepb.CreateInstanceRequest{
		Parent:     fmt.Sprintf("projects/%s", projectID),
		InstanceId: instanceID,
		Instance: &instancepb.Instance{
			Config:      fmt.Sprintf("projects/%s/instanceConfigs/%s", projectID, "regional-us-central1"),
			DisplayName: "Create instance example",
			AutoscalingConfig: &instancepb.AutoscalingConfig{
				AutoscalingLimits: &instancepb.AutoscalingConfig_AutoscalingLimits{
					MinLimit: &instancepb.AutoscalingConfig_AutoscalingLimits_MinNodes{
						MinNodes: 1,
					},
					MaxLimit: &instancepb.AutoscalingConfig_AutoscalingLimits_MaxNodes{
						MaxNodes: 2,
					},
				},
				AutoscalingTargets: &instancepb.AutoscalingConfig_AutoscalingTargets{
					HighPriorityCpuUtilizationPercent: 65,
					StorageUtilizationPercent:         95,
				},
			},
			Labels: map[string]string{"cloud_spanner_samples": "true"},
		},
	})
	if err != nil {
		return fmt.Errorf("could not create instance %s: %w", instanceName, err)
	}
	fmt.Fprintf(w, "Waiting for operation on %s to complete...", instanceID)
	// Wait for the instance creation to finish.
	i, err := op.Wait(ctx)
	if err != nil {
		return fmt.Errorf("waiting for instance creation to finish failed: %w", err)
	}
	// The instance may not be ready to serve yet.
	if i.State != instancepb.Instance_READY {
		fmt.Fprintf(w, "instance state is not READY yet. Got state %v\n", i.State)
	}
	fmt.Fprintf(w, "Created instance [%s].\n", instanceID)

	instance, err := instanceAdmin.GetInstance(ctx, &instancepb.GetInstanceRequest{
		Name: instanceName,
		// Get the autoscaling_config field from the newly created instance.
		FieldMask: &field_mask.FieldMask{Paths: []string{"autoscaling_config"}},
	})
	if err != nil {
		return fmt.Errorf("failed to get instance [%s]: %w", instanceName, err)
	}
	fmt.Fprintf(w, "Instance %s has autoscaling_config: %s.", instanceID, instance.AutoscalingConfig)
	return nil
}

Java

To learn how to install and use the client library for Spanner, see Spanner client libraries.

To authenticate to Spanner, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.


import com.google.cloud.spanner.Spanner;
import com.google.cloud.spanner.SpannerOptions;
import com.google.cloud.spanner.admin.instance.v1.InstanceAdminClient;
import com.google.spanner.admin.instance.v1.CreateInstanceRequest;
import com.google.spanner.admin.instance.v1.Instance;
import com.google.spanner.admin.instance.v1.InstanceConfigName;
import com.google.spanner.admin.instance.v1.ProjectName;
import java.util.concurrent.ExecutionException;

class CreateInstanceExample {

  static void createInstance() {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "my-project";
    String instanceId = "my-instance";
    createInstance(projectId, instanceId);
  }

  static void createInstance(String projectId, String instanceId) {
    // Set Instance configuration.
    int nodeCount = 2;
    String displayName = "Descriptive name";

    // Create an Instance object that will be used to create the instance.
    Instance instance =
        Instance.newBuilder()
            .setDisplayName(displayName)
            .setNodeCount(nodeCount)
            .setConfig(
                InstanceConfigName.of(projectId, "regional-us-central1").toString())
            .build();

    try (Spanner spanner =
        SpannerOptions.newBuilder()
            .setProjectId(projectId)
            .build()
            .getService();
        InstanceAdminClient instanceAdminClient = spanner.createInstanceAdminClient()) {

      // Wait for the createInstance operation to finish.
      Instance createdInstance = instanceAdminClient.createInstanceAsync(
          CreateInstanceRequest.newBuilder()
              .setParent(ProjectName.of(projectId).toString())
              .setInstanceId(instanceId)
              .setInstance(instance)
              .build()).get();
      System.out.printf("Instance %s was successfully created%n", createdInstance.getName());
    } catch (ExecutionException e) {
      System.out.printf(
          "Error: Creating instance %s failed with error message %s%n",
          instance.getName(), e.getMessage());
    } catch (InterruptedException e) {
      System.out.println("Error: Waiting for createInstance operation to finish was interrupted");
    }
  }
}

Create an instance with managed autoscaling using Java (Preview)


import com.google.cloud.spanner.Spanner;
import com.google.cloud.spanner.SpannerOptions;
import com.google.cloud.spanner.admin.instance.v1.InstanceAdminClient;
import com.google.spanner.admin.instance.v1.AutoscalingConfig;
import com.google.spanner.admin.instance.v1.CreateInstanceRequest;
import com.google.spanner.admin.instance.v1.Instance;
import com.google.spanner.admin.instance.v1.InstanceConfigName;
import com.google.spanner.admin.instance.v1.ProjectName;
import java.util.concurrent.ExecutionException;

class CreateInstanceWithAutoscalingConfigExample {

  static void createInstance() {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "my-project";
    String instanceId = "my-instance";
    createInstance(projectId, instanceId);
  }

  static void createInstance(String projectId, String instanceId) {
    try (Spanner spanner =
        SpannerOptions.newBuilder()
            .setProjectId(projectId)
            .build()
            .getService();
        InstanceAdminClient instanceAdminClient = spanner.createInstanceAdminClient()) {
      // Set Instance configuration.
      String configId = "regional-us-central1";
      String displayName = "Descriptive name";

      // Create an autoscaling config.
      // When autoscaling_config is enabled, node_count and processing_units fields
      // need not be specified.
      AutoscalingConfig autoscalingConfig =
          AutoscalingConfig.newBuilder()
              .setAutoscalingLimits(
                  AutoscalingConfig.AutoscalingLimits.newBuilder().setMinNodes(1).setMaxNodes(2))
              .setAutoscalingTargets(
                  AutoscalingConfig.AutoscalingTargets.newBuilder()
                      .setHighPriorityCpuUtilizationPercent(65)
                      .setStorageUtilizationPercent(95))
              .build();
      Instance instance =
          Instance.newBuilder()
              .setAutoscalingConfig(autoscalingConfig)
              .setDisplayName(displayName)
              .setConfig(
                  InstanceConfigName.of(projectId, configId).toString())
              .build();

      // Creates a new instance
      System.out.printf("Creating instance %s.%n", instanceId);
      try {
        // Wait for the createInstance operation to finish.
        Instance instanceResult = instanceAdminClient.createInstanceAsync(
            CreateInstanceRequest.newBuilder()
                .setParent(ProjectName.of(projectId).toString())
                .setInstanceId(instanceId)
                .setInstance(instance)
                .build()).get();
        System.out.printf("Autoscaler instance %s was successfully created%n",
            instanceResult.getName());
      } catch (ExecutionException e) {
        System.out.printf(
            "Error: Creating instance %s failed with error message %s%n",
            instance.getName(), e.getMessage());
      } catch (InterruptedException e) {
        System.out.println("Error: Waiting for createInstance operation to finish was interrupted");
      }
    }
  }
}

Node.js

To learn how to install and use the client library for Spanner, see Spanner client libraries.

To authenticate to Spanner, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.


// Imports the Google Cloud client library
const {Spanner} = require('@google-cloud/spanner');

// Creates a client
const spanner = new Spanner({
  projectId: projectId,
});

const instanceAdminClient = await spanner.getInstanceAdminClient();
/**
 * TODO(developer): Uncomment the following lines before running the sample.
 **/
// const projectId = 'my-project-id';
// const instanceId = 'my-instance';

// Creates a new instance
try {
  console.log(
    `Creating instance ${instanceAdminClient.instancePath(
      projectId,
      instanceId
    )}.`
  );
  const [operation] = await instanceAdminClient.createInstance({
    instanceId: instanceId,
    parent: instanceAdminClient.projectPath(projectId),
    instance: {
      config: instanceAdminClient.instanceConfigPath(
        projectId,
        'regional-us-central1'
      ),
      nodeCount: 1,
      displayName: 'Display name for the instance.',
      labels: {
        cloud_spanner_samples: 'true',
        created: Math.round(Date.now() / 1000).toString(), // current time
      },
    },
  });

  console.log(`Waiting for operation on ${instanceId} to complete...`);
  await operation.promise();

  console.log(`Created instance ${instanceId}.`);
} catch (err) {
  console.error('ERROR:', err);
}

PHP

To learn how to install and use the client library for Spanner, see Spanner client libraries.

To authenticate to Spanner, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

use Google\Cloud\Spanner\Admin\Instance\V1\Client\InstanceAdminClient;
use Google\Cloud\Spanner\Admin\Instance\V1\CreateInstanceRequest;
use Google\Cloud\Spanner\Admin\Instance\V1\Instance;

/**
 * Creates an instance.
 * Example:
 * ```
 * create_instance($projectId, $instanceId);
 * ```
 *
 * @param string $projectId  The Spanner project ID.
 * @param string $instanceId The Spanner instance ID.
 */
function create_instance(string $projectId, string $instanceId): void
{
    $instanceAdminClient = new InstanceAdminClient();
    $parent = InstanceAdminClient::projectName($projectId);
    $instanceName = InstanceAdminClient::instanceName($projectId, $instanceId);
    $configName = $instanceAdminClient->instanceConfigName($projectId, 'regional-us-central1');
    $instance = (new Instance())
        ->setName($instanceName)
        ->setConfig($configName)
        ->setDisplayName('dispName')
        ->setNodeCount(1);

    $operation = $instanceAdminClient->createInstance(
        (new CreateInstanceRequest())
        ->setParent($parent)
        ->setInstanceId($instanceId)
        ->setInstance($instance)
    );

    print('Waiting for operation to complete...' . PHP_EOL);
    $operation->pollUntilComplete();

    printf('Created instance %s' . PHP_EOL, $instanceId);
}

Python

To learn how to install and use the client library for Spanner, see Spanner client libraries.

To authenticate to Spanner, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

def create_instance(instance_id):
    """Creates an instance."""
    from google.cloud.spanner_admin_instance_v1.types import \
        spanner_instance_admin

    spanner_client = spanner.Client()

    config_name = "{}/instanceConfigs/regional-us-central1".format(
        spanner_client.project_name
    )

    operation = spanner_client.instance_admin_api.create_instance(
        parent=spanner_client.project_name,
        instance_id=instance_id,
        instance=spanner_instance_admin.Instance(
            config=config_name,
            display_name="This is a display name.",
            node_count=1,
            labels={
                "cloud_spanner_samples": "true",
                "sample_name": "snippets-create_instance-explicit",
                "created": str(int(time.time())),
            },
        ),
    )

    print("Waiting for operation to complete...")
    operation.result(OPERATION_TIMEOUT_SECONDS)

    print("Created instance {}".format(instance_id))

Ruby

To learn how to install and use the client library for Spanner, see Spanner client libraries.

To authenticate to Spanner, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

# project_id  = "Your Google Cloud project ID"
# instance_id = "Your Spanner instance ID"

require "google/cloud/spanner"
require "google/cloud/spanner/admin/instance"

instance_admin_client = Google::Cloud::Spanner::Admin::Instance.instance_admin

project_path = instance_admin_client.project_path project: project_id
instance_path = instance_admin_client.instance_path project: project_id, instance: instance_id
instance_config_path = instance_admin_client.instance_config_path project: project_id, instance_config: "regional-us-central1"

job = instance_admin_client.create_instance parent: project_path,
                                            instance_id: instance_id,
                                            instance: { name: instance_path,
                                                        config: instance_config_path,
                                                        display_name: instance_id,
                                                        node_count: 2,
                                                        labels: { cloud_spanner_samples: "true" } }

puts "Waiting for create instance operation to complete"

job.wait_until_done!

if job.error?
  puts job.error
else
  puts "Created instance #{instance_id}"
end

List instances

You can show a list of your Spanner instances.

Console

Go to the Spanner Instances page in the Google Cloud console.

Go to the Instances page

The Google Cloud console shows a list of your Spanner instances, along with each instance's ID, display name, configuration, and compute capacity expressed in both processing units and in nodes.

gcloud

Use the gcloud spanner instances list command:

gcloud spanner instances list

The gcloud CLI prints a list of your Spanner instances, along with each instance's ID, display name, configuration, and compute capacity.

Edit an instance

The following sections explain how to change an instance's display name and compute capacity. You cannot change the instance ID or instance configuration.

Change the display name

Console

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

    Go to the Instances page

  2. Click the name of the instance that you want to rename.

  3. Click Edit instance.

  4. Enter a new instance name. This name must be unique within the Google Cloud project.

  5. Click Save.

gcloud

Use the gcloud spanner instances update command:

gcloud spanner instances update INSTANCE-ID --description=INSTANCE-NAME

Replace the following:

  • INSTANCE-ID: the permanent identifier for the instance.
  • INSTANCE-NAME: the name to display for the instance in the Google Cloud console. The instance name must be unique within your Google Cloud project.

Change the compute capacity

You must provision enough compute capacity to keep CPU utilization and storage utilization below the recommended maximums. For more information, see the quotas and limits for Spanner.

There are a few cases in which you cannot reduce the compute capacity of an existing instance:

  • Removing compute capacity would require your instance to store more than 4 TB of data per 1000 processing units (1 node).
  • Based on your historic usage patterns, Spanner has created a large number of splits for your instance's data, and in some rare cases Spanner wouldn't be able to manage the splits after removing compute capacity.

In the latter case, you might try reducing the compute capacity by progressively smaller amounts until you find the minimum capacity that Spanner needs to manage all of the instance's splits. If the instance no longer requires so many splits due to a change in usage patterns, Spanner might eventually merge some splits together and allow you to try reducing the instance's compute capacity further after a week or two.

When removing compute capacity, monitor your CPU utilization and request latencies in Cloud Monitoring to ensure CPU utilization stays under 65% for regional instances and 45% for each region in multi-region instances. You might experience a temporary increase in request latencies while removing compute capacity.

If you want to increase the compute capacity of an instance, your Google Cloud project must have sufficient quota to add the compute capacity.

Console

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

    Go to the Instances page

  2. Click the name of the instance that you want to change.

  3. Click Edit Instance.

  4. Change the compute capacity by choosing the measurement units (processing units or nodes) and then entering a quantity. When using processing units, enter quantities up to 1000 in multiples of 100 (100, 200, 300 and so on) and enter greater quantities in multiples of 1000 (1000, 2000, 3000 and so on). Each node equals 1000 processing units.

  5. Click Save.

If you see a dialog that says you have insufficient quota to add compute capacity in this location, follow the instructions to request a higher quota.

gcloud

Use the gcloud spanner instances update command. When using this command, specify the compute capacity as a number of nodes or processing units.

gcloud spanner instances update INSTANCE-ID --nodes=NODE-COUNT

or

gcloud spanner instances update INSTANCE-ID
--processing-units=PROCESSING-UNIT-COUNT

Replace the following:

  • INSTANCE-ID: the permanent identifier for the instance.
  • NODE-COUNT: the compute capacity of the instance, expressed as a number of nodes. Each node equals 1000 processing units.
  • PROCESSING-UNIT-COUNT: the compute capacity of the instance, expressed as a number of processing units. Enter quantities up to 1000 in multiples of 100 (100, 200, 300 and so on) and enter greater quantities in multiples of 1000 (1000, 2000, 3000 and so on).

Enable or modify managed autoscaler on an instance

The following limitations apply when you add or change the managed autoscaling feature on an existing instance:

  • You can't enable the managed autoscaler on an instance that you are moving.
  • You can't move an instance while the managed autoscaler is enabled.

Console

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

    Go to the Instances page

  2. Click the name of the instance that you want to enable the managed autoscaler on.

  3. Click Edit instance.

  4. Under Configure compute capacity, click Autoscaling.

  5. For Minimum, select the minimum limit to use when scaling down. For more information, see Determine the minimum limit.

  6. For Maximum, select the maximum limit to use when scaling up. For more information, see Determine the maximum limit.

  7. For High priority CPU utilization target, select the percentage of high priority CPU to use. For more information, see Determine the CPU utilization target.

  8. For Storage utilization target, select the percentage of storage to use. For more information, see Determine the storage utilization target.

  9. Click Save.

gcloud

Use the gcloud beta spanner instances update command to add the managed autoscaler to an instance. For more information and limitations, see Google Cloud CLI flags and limitations.

You can add the managed autoscaler with the following command:

  gcloud beta spanner instances update \
    --autoscaling-min-processing-units=MINIMUM_PROCESSING_UNITS \
    --autoscaling-max-processing-units=MAXIMUM_PROCESSING_UNITS \
    --autoscaling-high-priority-cpu-target=CPU_PERCENTAGE \
    --autoscaling-storage-target=STORAGE_PERCENTAGE

or

  gcloud beta spanner instances update \
    --autoscaling-min-processing-units=MINIMUM_NODES \
    --autoscaling-max-processing-units=MAXIMUM_NODES \
    --autoscaling-high-priority-cpu-target=CPU_PERCENTAGE \
    --autoscaling-storage-target=STORAGE_PERCENTAGE

Replace the following:

  • MINIMUM_PROCESSING_UNITS, MINIMUM_NODES: the minimum number of processing units or nodes to use when scaling down. For more information, see Determine the minimum limit.
  • MAXIMUM_PROCESSING_UNITS, MAXIMUM_NODES: the maximum number of processing units or nodes to use when scaling up. For more information, see Determine the maximum limit.
  • CPU_PERCENTAGE: the target percentage of high priority CPU to use, from 10% to 90%. If you're optimizing for cost and don't require low latency on all requests, then use a higher percentage. For more information, see Determine the CPU utilization target.
  • STORAGE_PERCENTAGE: the target percentage of storage to use, from 10% to 99%. For more information, see Determine the Storage Utilization Target.

After you add the managed autoscaler to an instance, you can also modify the managed autoscaler settings. For example, if you want to increase the maximum number of processing units to 10000, run the following command:

gcloud beta spanner instances update \
     --autoscaling-max-processing-units=10000

Change an instance from using managed autoscaler to manual scaling

Console

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

    Go to the Instances page

  2. Click the name of the instance that you want to disable managed autoscaler on.

  3. Under Choose a scaling mode, click Manual allocation.

  4. Click Save.

gcloud

Use the gcloud beta spanner instances update command to update the instance.

Use the following command to change an instance from using the managed autoscaler to manual scaling:

  gcloud beta spanner instances update \
  --processing-units=PROCESSING-UNITS-COUNT

or

  gcloud beta spanner instances update \
  --nodes=NODE-COUNT

Replace PROCESSING-UNIT-COUNT or NODE-COUNT with the number of processing units or nodes that you want to use on the instance.

Label an instance

Labels help organize your resources.

Console

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

    Go to the Instances page

  2. Select the checkbox for the instance. The Info panel appears on the right-hand side of the page.

  3. Click the Labels tab in the Info panel. You can then add, delete or update labels for the Spanner instance.

Move an instance

For instructions on how to move your instance from any instance configuration to any other instance configuration, including between regional and multi-regional configurations, see Move an instance.

Delete an instance

You can delete an instance with the Google Cloud console or the Google Cloud CLI.

If you want to delete an instance that has one or more databases with deletion protection enabled, you must first disable the deletion protection on all databases in that instance before you can delete the instance.

Console

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

    Go to the Instances page

  2. Click the name of the instance that you want to delete.

  3. Click Delete instance.

  4. Follow the instructions to confirm that you want to delete the instance.

  5. Click Delete.

gcloud

Use the gcloud spanner instances delete command, replacing INSTANCE-ID with the instance ID:

gcloud spanner instances delete INSTANCE-ID

Stop or restart an instance

Spanner is a fully managed database service which oversees its own underlying tasks and resources, including monitoring and restarting processes when necessary with zero downtime. As there is no need to manually stop or restart a given instance, Spanner does not offer a way to do so.

What's next