Create and manage partitions

This page describes how to create and manage Spanner partitions.

Before you begin

To use partitions, you must set the opt_in_dataplacement_preview database option in your empty database:

Console

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

    Instances

  2. Select the instance in which you want to add partitions.

  3. Select the empty database in which you want to partition data.

  4. In the navigation menu, click Spanner Studio.

  5. In the Spanner Studio page, click New tab or use the empty editor tab.

  6. Enter the following ALTER DATABASE DDL statement.

    ALTER DATABASE DATABASE_ID SET OPTIONS (opt_in_dataplacement_preview = true);
    

    Replace DATABASE_ID with the unique identifier of your database.

  7. Click Run.

gcloud

To set the opt_in_dataplacement_preview database option, use gcloud spanner databases ddl update.

gcloud spanner databases ddl update DATABASE_ID \
  --instance=INSTANCE_ID \
  --ddl="ALTER DATABASE db SET OPTIONS (opt_in_dataplacement_preview = true);"

Replace the following:

  • DATABASE_ID: the permanent identifier for your Spanner database.
  • INSTANCE_ID: the permanent identifier for your Spanner instance.

Create a partition

Console

  1. In the Google Cloud console, open the Spanner page.

    Go to Spanner

  2. Select the instance in which you want to add partitions.

  3. In the navigation menu, select Partitions.

  4. Click Create partition.

  5. Enter a Partition ID to permanently identify your partition. The partition ID must also be unique within your Google Cloud project. You cannot change the partition ID later.

  6. In the Choose a configuration section, select Regional or Multi-region. Alternatively, if you want to compare the specifications between the regions, then click Compare region configurations.

  7. Select a configuration from the drop-down menu.

  8. In the Allocate compute capacity section, under Unit, click one of the following:

    • Processing units for small instance partitions.
    • Nodes for large instances. A node is 1000 processing units.
  9. Enter a value for the unit selected.

    Your partition must have at least one node or 1000 processing units.

  10. Click Create to create the partition.

gcloud

To create a partition, use gcloud beta spanner instance-partitions create.

gcloud beta spanner instance-partitions create PARTITION_ID \
  --config=PARTITION_CONFIG \
  --description="PARTITION_DESCRIPTION" \
  --instance=INSTANCE_ID \
  [--nodes=NODE_COUNT | --processing-units=PROCESSING_UNIT_COUNT]

Replace the following:

  • PARTITION_ID: the permanent partition identifier that is unique within your Google Cloud project. You can't change the partition ID later.
  • PARTITION_CONFIG: the permanent identifier of your partition configuration, which defines the geographic location of the partition and affects where data is stored.
  • PARTITION_DESCRIPTION: the name to display for the partition in the Google Cloud console. The partition name must be unique within your Google Cloud project.
  • INSTANCE_ID: the permanent identifier for your Spanner instance where this partition resides.
  • NODE_COUNT: the compute capacity of the partition, expressed as a number of nodes. One node equals 1000 processing units.
  • PROCESSING_UNIT_COUNT: the compute capacity of the instance, expressed as a number of processing units. Your partition must have at least 1000 processing units. Enter quantities in multiples of 1000 (1000, 2000, 3000 and so on).

For example, to create a partition europe-partition in eur3 with 5 nodes, run the following:

  gcloud beta spanner instance-partitions create europe-partition --config=eur3 \
    --description="europe-partition" --instance=test-instance --nodes=5

Describe a partition

gcloud

To describe a partition, use gcloud beta spanner instance-partitions describe.

gcloud beta spanner instance-partitions describe PARTITION_ID \
  --instance=INSTANCE_ID

Replace the following:

  • PARTITION_ID: the permanent identifier for the partition.
  • INSTANCE_ID: the permanent identifier for the instance.

For example, to describe partition europe-partition, run the following:

  gcloud beta spanner instance-partitions describe europe-partition
    --instance=test-instance

List partitions

Console

  1. In the Google Cloud console, open the Spanner page.

    Go to Spanner

  2. Select an instance from the list.

  3. In the navigation menu, select Partitions.

    A list of partitions associated with that instance is shown.

gcloud

To list your partitions, use gcloud beta spanner instance-partitions list.

gcloud beta spanner instance-partitions list --instance=INSTANCE_ID

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

Edit a partition

The following section explains how to change the compute capacity of your partition. You can't change the partition ID, name, or configuration.

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.

If you want to increase the compute capacity of a partition, your Google Cloud project must have sufficient quota to add the compute capacity. The time it takes for the increase request to complete depends on the size of the request. In most cases, requests complete within a few minutes. On rare occasions, a scale up might take up to an hour to complete.

Console

  1. In the Google Cloud console, open the Spanner page.

    Go to Spanner

  2. Select an instance from the list.

  3. In the navigation menu, select Partitions.

  4. In the list of partitions, under the Actions column, click More Actions and select Edit.

  5. Change the compute capacity by choosing a measurement unit (processing units or nodes), and then entering a quantity. When using processing units, enter quantities in multiples of 1000 (1000, 2000, 3000 and so on). Each node equals 1000 processing units.

    Your partition must have at least one node (1000 processing units).

  6. Click Save.

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

gcloud

To change the compute capacity of your partition, use gcloud beta spanner instance-partitions update. When using this command, specify the compute capacity as a number of nodes or processing units.

gcloud beta spanner instance-partitions update PARTITION_ID /
  --instance=INSTANCE_ID /
  [--nodes=NODE_COUNT | --processing-units=PROCESSING_UNIT_COUNT]
  [--async]

Replace the following:

  • PARTITION_ID: the permanent identifier for the partition.
  • INSTANCE_ID: the permanent identifier for the instance.
  • NODE_COUNT: the new compute capacity of the partition, expressed as a number of nodes. One node equals 1000 processing units.
  • PROCESSING_UNIT_COUNT: the new compute capacity of the partition, expressed as a number of processing units. Your partition must have at least 1000 processing units. Enter quantities in multiples of 1000 (1000, 2000, 3000 and so on).

Optional flags:

  • --async: Use this flag if you want your request to return immediately, without waiting for the operation in progress to complete.

You can check the status of your request by running gcloud spanner operations describe.

Delete a partition

You can't delete a partition while it's associated with any placements or data. You must first move any data that's in the partition or delete the placement tables that use the partition before you can delete the partition.

Console

  1. In the Google Cloud console, open the Spanner page.

    Go to Spanner

  2. Select an instance from the list.

  3. In the navigation menu, select Partitions.

  4. In the list of partitions, under the Actions column, click More Actions, and select Delete.

  5. Follow the instructions to confirm that you want to delete the partition.

  6. Click Delete.

gcloud

Use the gcloud beta spanner instance-partitions delete command.

gcloud beta spanner instance-partitions delete PARTITION_ID
  --instance=INSTANCE_ID

What's next