dsql
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAmazon Aurora DSQL Skill
Amazon Aurora DSQL 技能文档
Aurora DSQL is a serverless, PostgreSQL-compatible distributed SQL database. This skill covers direct query execution via MCP tools, schema management, migrations, multi-tenant isolation, IAM auth, and bulk data loading via .
aurora-dsql-loaderAurora DSQL是一款兼容PostgreSQL的无服务器分布式SQL数据库。本技能文档涵盖通过MCP工具执行直接查询、模式管理、迁移、多租户隔离、IAM认证,以及通过进行批量数据加载。
aurora-dsql-loaderReference Files
参考文档
Load these files as needed for detailed guidance:
根据需要加载以下文件获取详细指导:
Core:
核心类:
| Reference | When to Load | Contains |
|---|---|---|
| development-guide.md | ALWAYS before schema changes or DB operations | Best practices, DDL rules, transaction limits, app-layer referential integrity |
| language.md | MUST load for language-specific choices | Driver selection, DSQL Connectors, connection code |
| access-control.md | MUST load for roles, grants, or sensitive data | Scoped role setup, IAM-to-database role mapping |
| troubleshooting.md | SHOULD load for errors or unexpected behavior | OCC errors, connection failures, cluster state errors, token expiry, DDL rejection causes |
| dsql-examples.md | Load for implementation examples | Multi-tenant schema examples, batch operations, FK validation patterns, connection pooling |
| onboarding.md | User requests "Get started with DSQL" | Interactive step-by-step guide |
| occ-retry-patterns.md | MUST load for OCC retry code or conflict mitigation | DSQL Connectors, manual retry pattern, idempotent design |
| 参考文档 | 加载时机 | 包含内容 |
|---|---|---|
| development-guide.md | 进行模式变更或数据库操作前必须加载 | 最佳实践、DDL规则、事务限制、应用层参照完整性 |
| language.md | 进行语言相关选型时必须加载 | 驱动选择、DSQL连接器、连接代码 |
| access-control.md | 处理角色、权限或敏感数据时必须加载 | 限定范围角色配置、IAM到数据库角色的映射 |
| troubleshooting.md | 遇到错误或异常行为时建议加载 | OCC错误、连接失败、集群状态错误、令牌过期、DDL拒绝原因 |
| dsql-examples.md | 需要实现示例时加载 | 多租户模式示例、批量操作、FK验证模式、连接池 |
| onboarding.md | 用户请求“开始使用DSQL”时加载 | 交互式分步指南 |
| occ-retry-patterns.md | 需要OCC重试代码或冲突缓解方案时必须加载 | DSQL连接器、手动重试模式、幂等设计 |
MCP:
MCP类:
| Reference | When to Load | Contains |
|---|---|---|
| mcp-setup.md | Always for MCP server guidance | Setup instructions, 2 configuration options |
| mcp-tools.md | For MCP tool syntax and examples | Tool parameters, input validation |
| dsql-lint.md | MUST load before running | Tool reference, fix statuses, unfixable error resolution |
| 参考文档 | 加载时机 | 包含内容 |
|---|---|---|
| mcp-setup.md | 进行MCP服务器指导时始终加载 | 配置说明、2种配置选项 |
| mcp-tools.md | 需要MCP工具语法及示例时加载 | 工具参数、输入验证 |
| dsql-lint.md | 运行 | 工具参考、修复状态、无法修复错误的解决方案 |
DDL Migrations:
DDL迁移类:
| Reference | When to Load | Contains |
|---|---|---|
| ddl-migrations/overview.md | MUST load for DROP COLUMN, ALTER TYPE, DROP CONSTRAINT | Table recreation pattern, verify & swap |
| ddl-migrations/column-operations.md | DROP COLUMN, ALTER TYPE, SET/DROP NOT NULL/DEFAULT | Column-level migration patterns |
| ddl-migrations/constraint-operations.md | ADD/DROP CONSTRAINT, MODIFY PRIMARY KEY | Constraint and structural changes |
| ddl-migrations/batched-migration.md | Tables exceeding 3,000 rows | Batching patterns, progress tracking |
| 参考文档 | 加载时机 | 包含内容 |
|---|---|---|
| ddl-migrations/overview.md | 执行DROP COLUMN、ALTER TYPE、DROP CONSTRAINT时必须加载 | 表重建模式、验证与替换 |
| ddl-migrations/column-operations.md | 执行DROP COLUMN、ALTER TYPE、SET/DROP NOT NULL/DEFAULT时 | 列级迁移模式 |
| ddl-migrations/constraint-operations.md | 执行ADD/DROP CONSTRAINT、MODIFY PRIMARY KEY时 | 约束与结构变更 |
| ddl-migrations/batched-migration.md | 处理超过3000行的表时 | 批处理模式、进度跟踪 |
MySQL Migrations:
MySQL迁移类:
| Reference | When to Load | Contains |
|---|---|---|
| mysql-migrations/type-mapping.md | MUST load for MySQL → DSQL migration | Data type mappings, feature alternatives |
| mysql-migrations/ddl-operations.md | Translating MySQL DDL to DSQL | AUTO_INCREMENT, ENUM, SET, FK patterns |
| mysql-migrations/full-example.md | Complete MySQL table migration | End-to-end example with decision summary |
| 参考文档 | 加载时机 | 包含内容 |
|---|---|---|
| mysql-migrations/type-mapping.md | 进行MySQL → DSQL迁移时必须加载 | 数据类型映射、特性替代方案 |
| mysql-migrations/ddl-operations.md | 将MySQL DSQL转换为DSQL时 | AUTO_INCREMENT、ENUM、SET、FK模式 |
| mysql-migrations/full-example.md | 进行完整MySQL表迁移时 | 端到端示例及决策总结 |
PostgreSQL Migrations:
PostgreSQL迁移类:
| Reference | When to Load | Contains |
|---|---|---|
| pg-migrations/type-mapping.md | MUST load for PG → DSQL type questions | C collation rules, NUMERIC precision, JSON/JSONB |
| pg-migrations/fk-replacement.md | MUST load for FK validation code generation | Tenant-scoped validate_fk_*() template, cascade |
| pg-migrations/index-conversion.md | MUST load for unfixable index diagnostics | GIN/GiST/BRIN → btree, partial, expression indexes |
| pg-migrations/schema-objects.md | MUST load for ENUM, materialized views, extensions, multi-schema | ENUM → CHECK, views, role/IAM mapping |
| pg-migrations/multi-region.md | Multi-region, active-active, or HA questions | Architecture, geographic partitioning |
| 参考文档 | 加载时机 | 包含内容 |
|---|---|---|
| pg-migrations/type-mapping.md | 遇到PG → DSQL类型相关问题时必须加载 | C排序规则、NUMERIC精度、JSON/JSONB |
| pg-migrations/fk-replacement.md | 需要生成FK验证代码时必须加载 | 租户范围的validate_fk_*()模板、级联 |
| pg-migrations/index-conversion.md | 遇到无法修复的索引诊断问题时必须加载 | GIN/GiST/BRIN → btree、部分索引、表达式索引 |
| pg-migrations/schema-objects.md | 处理ENUM、物化视图、扩展、多模式时必须加载 | ENUM → CHECK、视图、角色/IAM映射 |
| pg-migrations/multi-region.md | 涉及多区域、双活或高可用问题时 | 架构设计、地理分区 |
ORM Guides:
ORM指南类:
| Reference | When to Load | Contains |
|---|---|---|
| orm-guides/overview.md | Migrating any ORM to DSQL | Adapter names, key gotchas for Django/Hibernate/Rails/SQLAlchemy |
| 参考文档 | 加载时机 | 包含内容 |
|---|---|---|
| orm-guides/overview.md | 将任意ORM迁移到DSQL时 | 适配器名称、Django/Hibernate/Rails/SQLAlchemy的关键注意事项 |
Data Loading:
数据加载类:
| Reference | When to Load | Contains |
|---|---|---|
| data-loading.md | Planning or running bulk loads with | Fresh-vs-warm partitions, resume/retry, |
| 参考文档 | 加载时机 | 包含内容 |
|---|---|---|
| data-loading.md | 使用 | 冷/热分区、恢复/重试、 |
Query Plan Explainability:
查询计划可解释性:
| Reference | When to Load | Contains |
|---|---|---|
| query-plan/plan-interpretation.md | MUST load at Workflow 9 Phase 0 | DSQL node types, Node Duration math, estimation-error bands |
| query-plan/catalog-queries.md | MUST load at Workflow 9 Phase 0 | |
| query-plan/guc-experiments.md | MUST load at Workflow 9 Phase 0 | GUC experiment procedures, 30-second skip protocol |
| query-plan/report-format.md | MUST load at Workflow 9 Phase 0 | Required report structure, element checklist, support request template |
| 参考文档 | 加载时机 | 包含内容 |
|---|---|---|
| query-plan/plan-interpretation.md | 工作流9阶段0时必须加载 | DSQL节点类型、节点时长计算、估算误差范围 |
| query-plan/catalog-queries.md | 工作流9阶段0时必须加载 | |
| query-plan/guc-experiments.md | 工作流9阶段0时必须加载 | GUC实验流程、30秒跳过协议 |
| query-plan/report-format.md | 工作流9阶段0时必须加载 | 要求的报告结构、元素检查清单、支持请求模板 |
MCP Tools Available
可用的MCP工具
The MCP server provides these tools:
aurora-dsqlDatabase Operations:
- readonly_query - Execute SELECT queries (returns list of dicts)
- transact - Execute DDL/DML statements in transaction (takes list of SQL statements)
- get_schema - Get table structure for a specific table
SQL Validation:
- dsql_lint - Validate SQL for DSQL compatibility and optionally auto-fix issues. Use before executing externally-sourced SQL.
Documentation & Knowledge:
- dsql_search_documentation - Search Aurora DSQL documentation
- dsql_read_documentation - Read specific documentation pages
- dsql_recommend - Get DSQL best practice recommendations
Note: There is no tool. Use with information_schema.
list_tablesreadonly_querySee mcp-setup.md for detailed setup instructions.
See mcp-tools.md for detailed usage and examples.
aurora-dsql数据库操作:
- readonly_query - 执行SELECT查询(返回字典列表)
- transact - 在事务中执行DDL/DML语句(接收SQL语句列表)
- get_schema - 获取指定表的结构
SQL验证:
- dsql_lint - 验证SQL的DSQL兼容性并可选自动修复问题。执行外部来源的SQL前请使用该工具。
文档与知识:
- dsql_search_documentation - 搜索Aurora DSQL文档
- dsql_read_documentation - 读取特定文档页面
- dsql_recommend - 获取DSQL最佳实践建议
注意: 没有工具。请使用查询information_schema。
list_tablesreadonly_query详细配置说明请查看mcp-setup.md。
详细用法及示例请查看mcp-tools.md。
AWS Knowledge MCP (awsknowledge
)
awsknowledgeAWS知识MCP(awsknowledge
)
awsknowledgeConsult for verifying DSQL service limits before advising users. The numeric limits below are
defaults that may change — when a user's decision depends on an exact limit, verify it first:
| Limit | Default | Verify query |
|---|---|---|
| Max rows per transaction | 3,000 | |
| Max data size per transaction | 10 MiB | |
| Max transaction duration | 5 minutes | |
| Max connections per cluster | 10,000 | |
| Auth token expiry | 15 minutes | |
| Max connection duration | 60 minutes | |
| Max indexes per table | 24 | |
| Max columns per index | 8 | |
| IDENTITY/SEQUENCE CACHE values | 1 or >= 65536 | |
| Supported column data types | See docs | |
When to verify: Before recommending batch sizes, connection pool settings, or schema designs where hitting a limit would cause failures; any time the exact number can affect user decision.
Fallback: If is unavailable, use the defaults above and flag that limits should be verified against DSQL documentation.
awsknowledge在为用户提供建议前,可通过该工具验证DSQL服务限制。以下数值限制为默认值,可能会变更——当用户的决策依赖精确限制时,请先进行验证:
| 限制项 | 默认值 | 验证查询语句 |
|---|---|---|
| 单事务最大行数 | 3,000 | |
| 单事务最大数据量 | 10 MiB | |
| 最大事务时长 | 5分钟 | |
| 单集群最大连接数 | 10,000 | |
| 认证令牌过期时间 | 15分钟 | |
| 最大连接时长 | 60分钟 | |
| 单表最大索引数 | 24 | |
| 单索引最大列数 | 8 | |
| IDENTITY/SEQUENCE缓存值 | 1或>=65536 | |
| 支持的列数据类型 | 查看文档 | |
验证时机: 在推荐批处理大小、连接池配置或可能触发限制的模式设计前;任何精确数值会影响用户决策的场景。
备选方案: 如果不可用,请使用上述默认值,并提示用户应参考DSQL官方文档验证限制。
awsknowledgeCLI Tools
CLI工具
Use the AWS CLI, , and directly for cluster management, SQL connections, and bulk data loading from local or S3 CSV/TSV/Parquet files. Load data-loading.md for loader guidance.
psqlaurora-dsql-loader可直接使用AWS CLI、和进行集群管理、SQL连接,以及从本地或S3加载CSV/TSV/Parquet格式的批量数据。加载data-loading.md获取加载器相关指导。
psqlaurora-dsql-loaderQuick Start
快速入门
- Explore: Use with
readonly_queryto list tables. Useinformation_schemafor table structure.get_schema - Query: Use for SELECT queries. MUST include
readonly_queryin WHERE for multi-tenant apps. MUST build SQL withtenant_id.safe_query.build() - Schema changes: Use with one DDL per transaction. MUST batch DML under 3,000 rows. MUST use
transactin a separate call. UseCREATE INDEX ASYNCto validate first.dsql_lint - Bulk load data: Use for CSV/TSV/Parquet. Load data-loading.md for details. Use
aurora-dsql-loaderfirst.--dry-run
- 探索: 使用查询
readonly_query列出表。使用information_schema获取表结构。get_schema - 查询: 使用执行SELECT查询。必须在WHERE子句中包含
readonly_query以支持多租户应用。必须使用tenant_id构建SQL。safe_query.build() - 模式变更: 使用执行单条DDL语句。必须将DML操作分批为不超过3000行。必须在单独调用中使用
transact。执行前请使用CREATE INDEX ASYNC验证。dsql_lint - 批量加载数据: 使用加载CSV/TSV/Parquet数据。详情请查看data-loading.md。请先使用
aurora-dsql-loader进行预验证。--dry-run
Common Workflows
常见工作流
Workflow 1: Create Multi-Tenant Schema
工作流1:创建多租户模式
- Create main table with tenant_id column using transact
- Create async index on tenant_id in separate transact call
- Create composite indexes for common query patterns (separate transact calls)
- Verify schema with get_schema
- MUST include tenant_id in all tables
- MUST use exclusively
CREATE INDEX ASYNC - MUST issue each DDL in its own transact call:
transact(["CREATE TABLE ..."]) - MUST serialize arrays as JSONB; expand at query time with
jsonb_array_elements_text(data)
- 使用transact创建包含tenant_id列的主表
- 在单独的transact调用中创建tenant_id的异步索引
- 为常见查询模式创建复合索引(单独的transact调用)
- 使用get_schema验证模式
- 必须在所有表中包含tenant_id
- 必须仅使用
CREATE INDEX ASYNC - 必须在单独的transact调用中执行每条DDL:
transact(["CREATE TABLE ..."]) - 必须将数组序列化为JSONB;查询时使用展开
jsonb_array_elements_text(data)
Workflow 2: Safe Data Migration
工作流2:安全数据迁移
MUST validate every DDL with before executing. DML does not require linting.
dsql_lint(fix=true)- Validate DDL with — handle diagnostics per dsql-lint.md
dsql_lint(sql=..., fix=true) - Add column:
transact(["ALTER TABLE ... ADD COLUMN ..."]) - Populate existing rows with UPDATE (batched under 3,000 rows)
- Verify with readonly_query COUNT
- Create index if needed: validate then
transact(["CREATE INDEX ASYNC ..."])
- MUST issue each in its own
ALTER TABLEcall — DSQL rejects multi-DDL transactions withtransactmultiple ddl statements not supported in a transaction - MUST add column with only name and type; apply DEFAULT via separate UPDATE
- MUST batch updates under 3,000 rows in separate transact calls
Recovery: Resume failed batches by filtering .
WHERE new_column IS NULL执行前必须使用验证每条DDL。DML无需验证。
dsql_lint(fix=true)- 使用验证DDL——根据dsql-lint.md处理诊断结果
dsql_lint(sql=..., fix=true) - 添加列:
transact(["ALTER TABLE ... ADD COLUMN ..."]) - 使用UPDATE填充现有行(分批为不超过3000行)
- 使用readonly_query COUNT验证
- 如需创建索引:先验证再执行
transact(["CREATE INDEX ASYNC ..."])
- 必须在单独的调用中执行每条
transact——DSQL会拒绝包含多条DDL的事务,提示ALTER TABLEmultiple ddl statements not supported in a transaction - 必须仅指定列名和类型来添加列;通过单独的UPDATE设置DEFAULT
- 必须将更新操作分批为不超过3000行,在单独的transact调用中执行
恢复: 通过过滤恢复失败的批处理。
WHERE new_column IS NULLWorkflow 3: Bulk Data Loading
工作流3:批量数据加载
Use for CSV, TSV, or Parquet loads. MUST load data-loading.md before advising on throughput or diagnosing slow loads.
aurora-dsql-loader- Validate with first
--dry-run - Run with on persistent storage (not
--manifest-dir— tmpfs on AL2023, lost on crash) and/tmpif file has a header row--header - On failure: resume with ; for duplicates use
--resume-job-id--on-conflict do-nothing - For large tables: create secondary indexes after load using
CREATE INDEX ASYNC
使用加载CSV、TSV或Parquet数据。提供吞吐量建议或诊断慢加载问题前必须加载data-loading.md。
aurora-dsql-loader- 先使用验证
--dry-run - 使用指定持久化存储(不要使用
--manifest-dir——AL2023的tmpfs会在崩溃后丢失数据),如果文件包含表头则添加/tmp参数--header - 加载失败时:使用恢复;遇到重复数据时使用
--resume-job-id--on-conflict do-nothing - 处理大表时:加载完成后使用创建二级索引
CREATE INDEX ASYNC
Workflow 4: Application-Layer Referential Integrity
工作流4:应用层参照完整性
INSERT: MUST validate parent exists with readonly_query → throw error if not found → insert child with transact.
DELETE: MUST check dependents with readonly_query COUNT → return error if dependents exist → delete with transact if safe.
插入: 必须使用readonly_query验证父记录存在→如果未找到则抛出错误→使用transact插入子记录。
删除: 必须使用readonly_query COUNT检查依赖记录→如果存在则返回错误→安全情况下使用transact删除。
Workflow 5: Query with Tenant Isolation
工作流5:租户隔离查询
- MUST authorize the caller against the tenant — format validation does not establish authorization
- MUST build SQL with — use
safe_query.build()/allow()for values (emitsregex()),'v'for table/column names (emitsident()). See input-validation.md"v" - MUST include in the WHERE clause; reject cross-tenant access at the application layer
tenant_id
- 必须针对租户对调用者进行授权——格式验证不代表已完成授权
- 必须使用构建SQL——对值使用
safe_query.build()/allow()(生成regex()),对表/列名使用'v'(生成ident())。详情请查看input-validation.md"v" - 必须在WHERE子句中包含;在应用层拒绝跨租户访问
tenant_id
Workflow 6: Set Up Scoped Database Roles
工作流6:配置限定范围数据库角色
MUST load access-control.md for role setup, IAM mapping, and schema permissions.
配置角色、IAM映射及模式权限前必须加载access-control.md。
Workflow 7: Table Recreation DDL Migration
工作流7:表重建式DDL迁移
Use the Table Recreation Pattern for , , , or . This is a destructive workflow that requires user confirmation at each step. Every generated DDL in the pattern (CREATE new, INSERT ... SELECT, DROP old, RENAME) MUST be validated with before execution.
ALTER COLUMN TYPEDROP COLUMNDROP CONSTRAINTMODIFY PRIMARY KEYdsql_lint(sql=..., fix=true)MUST load ddl-migrations/overview.md before attempting any of these operations.
针对、、或操作,使用表重建模式。这是一个破坏性工作流,每一步都需要用户确认。模式中生成的每条DDL(创建新表、INSERT ... SELECT、删除旧表、重命名)执行前必须使用验证。
ALTER COLUMN TYPEDROP COLUMNDROP CONSTRAINTMODIFY PRIMARY KEYdsql_lint(sql=..., fix=true)执行任何此类操作前必须加载ddl-migrations/overview.md。
Workflow 8: Validate and Migrate to DSQL
工作流8:验证并迁移到DSQL
MUST load dsql-lint.md before running . Run to validate and auto-convert. For MySQL-origin SQL, MUST cross-check against mysql-migrations/type-mapping.md even when lint returns clean. On , fall back to manual conversion then re-lint.
dsql_lintdsql_lint(sql=source_sql, fix=true)parse_error运行前必须加载dsql-lint.md。运行进行验证并自动转换。对于源自MySQL的SQL,即使lint结果正常,必须对照mysql-migrations/type-mapping.md进行交叉检查。遇到时,先手动转换再重新lint。
dsql_lintdsql_lint(sql=source_sql, fix=true)parse_errorWorkflow 9: Query Plan Explainability
工作流9:查询计划可解释性
Explains why the DSQL optimizer chose a particular plan. Triggered by slow queries, high DPU, unexpected Full Scans, or plans the user doesn't understand. REQUIRES a structured Markdown diagnostic report as the deliverable.
MUST load all four reference files at Phase 0: query-plan/plan-interpretation.md, query-plan/catalog-queries.md, query-plan/guc-experiments.md, query-plan/report-format.md. The phase procedures (capture plan, gather evidence, experiment, produce report) are defined in those files.
Safety. Plan capture uses exclusively. Rewrite DML to SELECT for plan capture. MUST NOT use for plan capture.
readonly_querytransact --allow-writes解释DSQL优化器选择特定计划的原因。当遇到慢查询、高DPU、意外全表扫描或用户无法理解的计划时触发。必须交付结构化Markdown诊断报告作为成果。
阶段0时必须加载所有四个参考文档:query-plan/plan-interpretation.md、query-plan/catalog-queries.md、query-plan/guc-experiments.md、query-plan/report-format.md。阶段流程(捕获计划、收集证据、实验、生成报告)在这些文档中定义。
安全注意事项。 计划捕获仅使用。将DML重写为SELECT进行计划捕获。禁止使用进行计划捕获。
readonly_querytransact --allow-writesWorkflow 10: Full PostgreSQL → DSQL Schema Migration
工作流10:完整PostgreSQL → DSQL模式迁移
MUST load pg-migrations/type-mapping.md and pg-migrations/schema-objects.md. Run first for mechanical fixes, then apply semantic conversions from the pg-migrations references for unfixable diagnostics and patterns the linter cannot handle. Re-lint the final output before deploying.
dsql_lint(fix=true)必须加载pg-migrations/type-mapping.md和pg-migrations/schema-objects.md。先运行进行机械修复,然后根据pg-migrations参考文档进行语义转换,处理无法修复的诊断结果和linter无法处理的模式。部署前重新lint最终输出。
dsql_lint(fix=true)Workflow 11: ORM Migration (Django/Hibernate/Rails)
工作流11:ORM迁移(Django/Hibernate/Rails)
Load orm-guides/overview.md for adapter names and framework-specific gotchas.
加载orm-guides/overview.md获取适配器名称及框架特定注意事项。
Error Scenarios
错误场景
- returns no results: Use the default limits in the table above and note that limits should be verified against DSQL documentation.
awsknowledge - unavailable or timing out: See the Error Handling section of dsql-lint.md. Do not silently skip validation — inform the user and require explicit confirmation before proceeding with manual rules from development-guide.md.
dsql_lint - OCC serialization error: Retry the transaction. If persistent, check for hot-key contention — see troubleshooting.md.
- Transaction exceeds limits: Split into batches under 3,000 rows — see batched-migration.md.
- Token expiration mid-operation: Generate a fresh IAM token — see authentication-guide.md. See troubleshooting.md for other issues.
- 无返回结果: 使用上表中的默认限制,并提示用户应参考DSQL官方文档验证限制。
awsknowledge - 不可用或超时: 查看dsql-lint.md的错误处理部分。请勿跳过验证——告知用户并要求明确确认后,再根据development-guide.md的手动规则进行操作。
dsql_lint - OCC序列化错误: 重试事务。如果持续出现,请检查热键冲突——查看troubleshooting.md。
- 事务超出限制: 拆分为不超过3000行的批处理——查看batched-migration.md。
- 操作中令牌过期: 生成新的IAM令牌——查看authentication-guide.md。其他问题请查看troubleshooting.md。