Spanner Basics
GoogleOfficialPublished by Google
- Skill
- Tool integration
- Cloud and DevOps
- Apache-2.0
- Low risk
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
Spanner Basics provides guidance and workflows for interacting with Google Cloud Spanner. It covers administrative tasks like provisioning instances and databases, as well as development tasks such as designing schemas, writing SQL queries, and utilizing client libraries. The skill includes specific instructions for performance-oriented schema design, such as primary key selection and table interleaving, and provides reference material for IAM security, Terraform, and PostgreSQL dialect usage.
What it does
- Provides commands for provisioning and managing Spanner instances and databases.
- Offers guidance on designing performant database schemas.
- Assists in writing SQL queries and client library code for Spanner.
- Helps diagnose performance issues using system tables.
- Includes reference documentation for IAM, Terraform, and PostgreSQL compatibility.
- Requires explicit user confirmation for all DDL and DML operations.
When to use it
- When setting up or managing Cloud Spanner instances and databases via CLI.
- When designing database schemas, including primary keys and interleaved tables.
- When writing or debugging SQL queries and application code for Spanner.
- When investigating performance metrics using system tables.
- When implementing infrastructure as code using Terraform for Spanner resources.
Advantages
- Centralizes access to Spanner-specific CLI commands and best practices.
- Ensures safe execution by requiring user approval for destructive operations.
- Provides structured guidance on complex topics like schema evolution.
- Includes standardized attribution for command execution.
Usage examples
- “Create a new Spanner instance named my-app-db with 1 node in us-central1.”
- The agent will generate the appropriate gcloud spanner instances create command with the specified configuration.
- “How should I design my primary key to avoid hotspots?”
- The agent will provide guidance on avoiding monotonically increasing or decreasing values as the first part of a primary key.
- “Show me how to list all databases in my instance.”
- The agent will provide the gcloud spanner databases list command for the specified instance.
- “Help me find the most resource-intensive queries in my database.”
- The agent will suggest querying SPANNER_SYS.QUERY_STATS_TOP_HOUR to identify high CPU usage queries.
Install
Download the skill as a ZIP:
https://autogineer.com/agent-skills/google/spanner-basics/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip spanner-basics.zip -d .agents/skills
Documentation by Google
Spanner Basics
This skill provides core workflows and guidance for administering and developing with Cloud Spanner on Google Cloud, a fully managed, mission-critical database service offering global transactional consistency and automatic, synchronous replication for high availability.
Attribution
MUST READ: Before executing any gcloud, REST API, or MCP command, you
MUST read Usage Attribution. For commands executed
directly in the terminal (never in generated scripts, Terraform, or user code),
prefix gcloud with
CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:spanner-basics)"
and append agent-skills/1.0 (skill:spanner-basics) to User-Agent headers.
Core Principles
Performance First: Spanner scales horizontally. Efficiency is tied to Primary Key design. Always warn against using monotonically increasing/decreasing values (like sequential timestamps) as the first part of a primary key to avoid hotspots.
Schema Design: Prefer interleaved tables for strongly related parent-child data that is frequently accessed together.
Safety
[!CAUTION] CRITICAL INSTRUCTION: You MUST obtain explicit user confirmation before making any non-emulator database changes (DML or DDL) or destructive operations (such as dropping tables, indexes, or any other Spanner resources). Do not execute them automatically; instead, output the command (e.g.,
gcloud spanner databases ddl update) and ask for explicit user approval. When database access is unavailable or authentication fails, do not block on trying to verify the existence of the instance, database, or table. Assume the provided resources exist and directly generate the DDL commands.
Common Workflows
Schema Evolution & DDL
Use
gcloud spanner databases ddl updateto apply schema updates (such as CREATE, ALTER, or DROP tables and indexes).Reference schema-design.md for guidelines on primary key selection and interleaved tables.
Diagnosing Performance Issues
Use
SPANNER_SYStables to identify slow or resource-intensive queries.For example, query
SPANNER_SYS.QUERY_STATS_TOP_HOURto find queries with the highest CPU usage.
Reference Directory
Core Concepts: Explanation of Spanner internals, architecture, and design.
CLI Usage: Essential
gcloud spannercommand-line operations for managing instances and databases.IAM Security: Roles, permissions, and data governance best practices for Spanner.
Client Library Usage: Using Google Cloud client libraries for Spanner (Java, Go, Python, Node.js).
Terraform Usage: Infrastructure as Code examples for provisioning Spanner instances and databases.
MCP Usage: Using the Spanner remote MCP server.
PostgreSQL Dialect: Best practices and examples for using the PostgreSQL interface in Spanner.
Queues Usage: Cloud Spanner Queues: mental model, design constraints, and links related to transactional message queues.
Schema Design: Guidelines on primary key selection and interleaved tables for performance.
If you need product information that's not found in these references, use the
search_documents tool of the Developer Knowledge MCP server.
Files
- ATTRIBUTION.mdAdded by AutoGineer846 B
- LICENSELicence file added by AutoGineer11.1 KiB
- SKILL.md3.8 KiB
- references/attribution.md1.8 KiB
- references/cli-usage.md1.3 KiB
- references/client-library-usage.md3.5 KiB
- references/core-concepts.md1.1 KiB
- references/iam-security.md1.2 KiB
- references/mcp-usage.md1.5 KiB
- references/postgresql-dialect.md951 B
- references/queues-usage.md10.8 KiB
- references/schema-design.md3.4 KiB
- references/terraform-usage.md928 B
references/schema-design.md
Schema Design
Best practices for schema design in Spanner to ensure performance and scalability.
Primary Key Design
To avoid creating hotspots, carefully choose a primary key. A common cause of hotspots is using a key that monotonically increases or decreases (such as a timestamp) as the first part of the primary key. This directs all insert traffic to a single server, creating a bottleneck.
Hotspot Prevention Techniques
Use a Universally Unique Identifier (UUID)
Recommend using UUID Version 4 (uses random values).
Eliminates hotspots because they don't keep locality between related records.
Stored in a
UUIDcolumn.
Bit-reversed Sequential Values
Avoid sequentially increasing/decreasing numerical primary keys.
Bit-reverse sequential values to distribute primary key values evenly across the key space.
Spanner supports bit-reversed sequences.
Swap the Order of Keys
Spread writes over the key space more uniformly by putting a high-cardinality, non-monotonic column first.
Example: Order by
UserIdfirst, then chronologicalLastAccesstimestamp.
Hash the Unique Key
Create a column that contains the hash of the actual unique key.
Use the hash column as the primary key to spread writes across logical shards.
Descending Order for Timestamp Keys
Consider using descending order (DESC) for timestamp keys if:
You want to read the most recent history and are reading the parent row in an interleaved table.
You are reading sequential entries in reverse chronological order (e.g., most recent N events).
When to Use an Interleaved Index
Avoid creating non-interleaved indexes on columns whose values are monotonically increasing or decreasing (like non-primary key timestamps).
Use an interleaved index where last access rows are interleaved under the corresponding user row.
Data Types
GoogleSQL:
ARRAY,BOOL,BYTES,DATE,ENUM,FLOAT32,FLOAT64,INT64,JSON,NUMERIC,PROTO,STRING,STRUCT,TIMESTAMP,UUID.PostgreSQL:
array,bool,bytea,date,float4,float8,int8/bigint,jsonb,numeric,timestamptz,uuid,varchar/text.
All types except FLOAT32, ARRAY, JSON, PROTO, and STRUCT are valid for
primary keys.
Performance Checklist (Agent Verification)
When reviewing or generating schema-related code, verify the following:
[ ] Hotspot Prevention: Ensure the first part of the primary key is NOT a monotonically increasing or decreasing value (like a sequential ID or timestamp). If it is, recommend a UUID (v4), bit-reversed sequence, or hashing.
[ ] Interleaved Tables: Verify if strongly related parent-child data that is frequently accessed together is structured using interleaved tables (
INTERLEAVE IN PARENT).[ ] Interleaving Depth: Limit interleaving depth. Spanner supports up to 7 levels of interleaving, but keeping it to a minimum avoids excessive overhead.
[ ] Index Design: Ensure secondary indexes are created for frequent query patterns. If sorting by a timestamp is needed, check if the index should use descending order (
DESC).[ ] Data Types: Check that the chosen data types are optimal and valid for the column's purpose (e.g.,
FLOAT32,ARRAY,JSON, andSTRUCTcannot be used as primary keys).
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs an MCP server
Security
What our scanner noticed· Low risk
- Instructions that use the network
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Published by
- Publisher
- Google (Official)
- Source
- google/skills · skills/cloud/spanner-basics · commit 2194d3b
- Licence
- Apache License 2.0 (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by Google or Google.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download spanner-basics.zip