
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Create an instance and database
/ 40
Create a schema for the database
/ 30
Create an instance and database with CLI
/ 30
Cloud Spanner is Google’s fully managed, horizontally scalable relational database service. Customers in financial services, gaming, retail and many other industries trust it to run their most demanding workloads, where consistency and availability at scale are critical.
In this lab, you perform basic administrative tasks within a Cloud Spanner instance.
In this lab, you learn how to perform the following tasks:
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.
This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method. On the left is the Lab Details pane with the following:
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
If necessary, copy the Username below and paste it into the Sign in dialog.
You can also find the Username in the Lab Details pane.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
You can also find the Password in the Lab Details pane.
Click Next.
Click through the subsequent pages:
After a few moments, the Google Cloud console opens in this tab.
Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.
Click Activate Cloud Shell at the top of the Google Cloud console.
Click through the following windows:
When you are connected, you are already authenticated, and the project is set to your Project_ID,
gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
Output:
Output:
gcloud
, in Google Cloud, refer to the gcloud CLI overview guide.
The first step in using Cloud Spanner is to create an instance. An instance is an allocation of Google Cloud compute and storage resources. From the Console, open the navigation menu () > View All Products. Under Databases section, click Spanner.
Accept any acknowledgement or information window that may appear.
Then click Create a Provisioned Instance.
Fill in the following fields, leave the remainder with the default values:
Item | Value |
---|---|
Select an edition | Enterprise |
Instance Name | banking-instance |
Select a configuration | |
Configure compute capacity | Unit - Nodes // Quantity - 1 |
From the instance details page, click Create database.
For the database name, enter banking-db.
Skip the Define your schema (optional) step for now. You'll define your schema in the next section.
Click Create.
You're now on the Overview page for the new database you created. You can see that the page is similar to the Instance one, but the statistics refer to the specific database. Also note the new options on the left menu.
Click Check my progress to verify the objective.
Click Run.
When the operation is complete, click Overview under Database in the left menu. Then scroll down to Tables and click Customer to see the schema details:
Click Check my progress to verify the objective.
The Cloud Console provides an interface for inserting, editing, and deleting data.
While on the Schema page, click Data in the left menu. Then click Insert.
This takes you to the Query tab of the Spanner Studio automatically. Click Clear Query, paste the query below, and click Run:
The lower page of the screen shows the result. The Customer table now has one row.
Add a second row. Replace the previous statement with the following, and click Run:
You can execute a SQL statement on the query page of your database.
In the left pane of the Cloud Platform Console, click Spanner Studio to navigate to the Query UI window.
Click the blue + icon to open the Query page. Click Clear Query, paste the query below, and click Run:
Click Run.
The Cloud Console displays the result of your query.
The Cloud Console is very useful, but in some use cases you want to manage Spanner instances using other methods. Google Cloud services can also be managed through the command line tool named gcloud. The easiest way to use the gcloud CLI is via the Cloud Shell but it can also be installed on a wide variety of operating systems.
You can also create databases in a Spanner instance using gcloud.
In the Cloud Shell, create a new database using the command below.
Remember that it is important to provision enough nodes to keep CPU utilization and storage utilization below the recommended maximum values. However, sometimes it is necessary to reduce the number of nodes.
You are now going to reduce the number of nodes of the instance banking-instance-2 from two to one.
Use the following gcloud command to adjust the instance:
As your Spanner architectures grow and get more complex, you want to automate the deployment and management of Spanner instances. One of the tools available to deploy and manage Spanner is Terraform.
The goal of this lab is not to explain how Terraform works. If you are not familiar with Terraform, you can check the documentation.
In short, you provide Terraform with a set of files that describe the infrastructure or services that you want it to deploy in Google Cloud, which is called a configuration. Then you instruct Terraform to initialize and plan the deployment, before applying the changes.
The plan will be displayed again and Terraform will pause for approval to continue. Type yes and Terraform will create the new instance.
The apply will process and return the following output:
You now have now a solid understanding of several basic administrative actions when using a Cloud Spanner Instance.
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated February 24, 2025
Lab Last Tested February 24, 2025
Copyright 2025 Google LLC. All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one