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
Go to the Instances page in the Google Cloud console.
Select the instance in which you want to add partitions.
Select the empty database in which you want to partition data.
In the navigation menu, click Spanner Studio.
In the Spanner Studio page, click
New tab or use the empty editor tab.Enter the following
ALTER DATABASE
DDL statement.GoogleSQL
ALTER DATABASE DATABASE_ID SET OPTIONS (opt_in_dataplacement_preview = true);
Replace DATABASE_ID with the unique identifier of your database.
PostgreSQL
ALTER DATABASE DATABASE_ID SET "spanner.opt_in_dataplacement_preview" = TRUE;
Replace DATABASE_ID with the unique identifier of your database.
Click Run.
gcloud
To set the opt_in_dataplacement_preview
database option, use
gcloud spanner databases ddl update
.
GoogleSQL
gcloud spanner databases ddl update DATABASE_ID \
--instance=INSTANCE_ID \
--ddl="ALTER DATABASE DATABASE_ID 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.
PostgreSQL
gcloud spanner databases ddl update DATABASE_ID \
--instance=INSTANCE_ID \
--ddl="ALTER DATABASE DATABASE_ID SET "spanner.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
In the Google Cloud console, open the Spanner page.
Select the instance in which you want to add partitions.
In the navigation menu, select Partitions.
Click Create partition.
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.
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.
Select a configuration from the drop-down menu.
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.
Enter a value for the unit selected.
Your partition must have at least one node or 1000 processing units.
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
Client libraries
C++
To learn how to install and use the client library for Spanner, see Spanner client libraries.
C#
To learn how to install and use the client library for Spanner, see Spanner client libraries.
Go
To learn how to install and use the client library for Spanner, see Spanner client libraries.
Java
To learn how to install and use the client library for Spanner, see Spanner client libraries.
Node.js
To learn how to install and use the client library for Spanner, see Spanner client libraries.
PHP
To learn how to install and use the client library for Spanner, see Spanner client libraries.
Python
To learn how to install and use the client library for Spanner, see Spanner client libraries.
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
In the Google Cloud console, open the Spanner page.
Select an instance from the list.
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
In the Google Cloud console, open the Spanner page.
Select an instance from the list.
In the navigation menu, select Partitions.
In the list of partitions, under the Actions column, click More Actions and select Edit.
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).
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
In the Google Cloud console, open the Spanner page.
Select an instance from the list.
In the navigation menu, select Partitions.
In the list of partitions, under the Actions column, click More Actions, and select Delete.
Follow the instructions to confirm that you want to delete the partition.
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
- Learn how to create and manage placement table and keys.