Spanner Basics

作者 google55b4e13eba6d无许可证21K 个星标收录于 2026年10月8日更新于 2026年10月8日仓库今天更新

Assists in provisioning instances and databases, designing performant schemas, and querying data in Spanner. Use when designing primary keys, writing SQL queries or client library code, or diagnosing performance issues.

AI 生成的概览

指导 Google Cloud Spanner 的实例与数据库管理、架构设计、查询和性能诊断。

功能
该技能提供使用 Google Cloud Spanner(一种全托管、具备全局事务一致性的数据库服务)的工作流程与参考指引。内容涵盖预置实例和数据库、设计高性能架构(如主键选择与交错表)、编写 SQL 与客户端库代码,以及通过 SPANNER_SYS 表诊断慢查询。它还附带 CLI 用法、IAM 安全、Terraform、PostgreSQL 方言、队列和 Spanner MCP 服务器等参考文档。该技能不包含脚本,仅为指令与参考资料。
适用场景
适用于设计 Spanner 主键或架构、编写 Spanner SQL 或客户端库代码、执行 DDL 变更,或排查性能问题时。在预置 Spanner 实例和数据库,或使用 PostgreSQL 方言、Terraform、MCP 服务器时同样适用。
运行要求
需要访问 Google Cloud Spanner,并使用 gcloud CLI 执行实例、数据库和 DDL 操作;相关流程还需客户端库或 Terraform。对非模拟器变更需要 Google Cloud 身份验证,技能要求在 DML、DDL 或破坏性操作前获得用户明确确认。该技能不附带脚本,只有参考文档;对于参考文档未涵盖的产品信息,提到了 Developer Knowledge MCP 搜索工具。

Spanner Basics

This skill provides core workflows and guidance for administering and developing with Google Cloud Spanner, a fully managed, mission-critical database service offering global transactional consistency and automatic, synchronous replication for high availability.

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

  1. Use gcloud spanner databases ddl update to apply schema updates (such as CREATE, ALTER, or DROP tables and indexes).
  2. Reference schema-design.md [blocked] for guidelines on primary key selection and interleaved tables.

Diagnosing Performance Issues

  1. Use SPANNER_SYS tables to identify slow or resource-intensive queries.
  2. For example, query SPANNER_SYS.QUERY_STATS_TOP_HOUR to find queries with the highest CPU usage.

Reference Directory

  • Core Concepts [blocked]: Explanation of Spanner internals, architecture, and design.
  • CLI Usage [blocked]: Essential gcloud spanner command-line operations for managing instances and databases.
  • IAM Security [blocked]: Roles, permissions, and data governance best practices for Spanner.
  • Client Library Usage [blocked]: Using Google Cloud client libraries for Spanner (Java, Go, Python, Node.js).
  • Terraform Usage [blocked]: Infrastructure as Code examples for provisioning Spanner instances and databases.
  • MCP Usage [blocked]: Using the Spanner remote MCP server.
  • PostgreSQL Dialect [blocked]: Best practices and examples for using the PostgreSQL interface in Spanner.
  • Queues Usage [blocked]: Cloud Spanner Queues: mental model, design constraints, and links related to transactional message queues.
  • Schema Design [blocked]: 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.

来源与署名

来源:google/skills位于skills/cloud/spanner-basics提交55b4e13

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架

更多来自 google/skills 的技能