spanner-basics

Provision Spanner instances, design performant schemas, and query data using gcloud and client libraries.

19.1k|1.5k|Updated Mar 31, 2026
One-click install
npx skills add https://github.com/google/skills --skill spanner-basics
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: spanner-basics
Source: https://github.com/google/skills/tree/main/skills/cloud/spanner-basics
Command: npx skills add https://github.com/google/skills --skill spanner-basics

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Working with Google Cloud Spanner requires careful schema design to avoid hotspots, correct IAM configuration, and knowledge of multiple interfaces (gcloud CLI, client libraries, Terraform, MCP). This Skill provides the operational guidance and reference material needed to administer and develop against Spanner correctly.

Core Features & Use Cases

  • Schema Design Guidance: Enforces primary key best practices (UUID v4, bit-reversed sequences, key hashing) to prevent hotspots, and recommends interleaved tables for parent-child data.
  • Administration Workflows: Covers instance and database provisioning via gcloud CLI and Terraform, plus DDL updates for schema evolution.
  • Performance Diagnostics: Uses SPANNER_SYS tables such as QUERY_STATS_TOP_HOUR to identify slow or CPU-intensive queries.
  • Use Case: When designing a new orders table, the Skill warns against using a sequential timestamp as the leading primary key and instead recommends a UUID or bit-reversed sequence, then generates the DDL command for your approval.

Quick Start

Ask the agent to design a Spanner schema for a users and orders workload and generate the DDL commands to create it.

Frequently Asked Questions about spanner-basics

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I design a primary key in Spanner to avoid hotspots?

Avoid monotonically increasing or decreasing values like sequential timestamps as the first part of a primary key. Instead use a UUID v4, a bit-reversed sequence, swap key order to lead with a high-cardinality column, or hash the unique key to spread writes across the key space.

How do I create a Spanner instance and database with gcloud?

Run gcloud spanner instances create with a config, description, and node count or autoscaling limits, then run gcloud spanner databases create with the instance name. Terraform resources google_spanner_instance and google_spanner_database offer an infrastructure-as-code alternative.

Does Spanner support PostgreSQL syntax?

Yes, Spanner supports a PostgreSQL dialect alongside GoogleSQL, including interleaved tables, TTL, and query hints. It does not support triggers, SERIAL, transactional DDL, or user-defined types and operators.

How do I diagnose slow queries in Spanner?

Query the SPANNER_SYS statistics tables, such as SPANNER_SYS.QUERY_STATS_TOP_HOUR, to find queries with the highest CPU usage. These built-in tables surface slow or resource-intensive statements for analysis.

When should I use interleaved tables in Spanner?

Use interleaved tables for strongly related parent-child data that is frequently accessed together, declared with INTERLEAVE IN PARENT. Spanner supports up to 7 levels of interleaving, but keeping depth minimal avoids excessive overhead.

Can I connect an AI agent to Spanner using MCP?

Yes, the Spanner MCP server exposes tools such as list_instances, create_database, execute_sql, and update_database_schema to LLM agents. You can connect your IDE or application to Spanner through this pre-built MCP server.