Amazon Aurora DSQL Skill
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-loader.
Reference 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 |
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 dsql_lint or processing external SQL |
Tool reference, fix statuses, unfixable error resolution |
DDL Migrations:
| 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 |
MySQL Migrations:
| 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 |
PostgreSQL Migrations:
| 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 |
ORM Guides:
| Reference |
When to Load |
Contains |
| orm-guides/overview.md |
Migrating any ORM to DSQL |
Adapter names, key gotchas for Django/Hibernate/Rails/SQLAlchemy |
Data Loading:
| Reference |
When to Load |
Contains |
| data-loading.md |
Planning or running bulk loads with aurora-dsql-loader |
Fresh-vs-warm partitions, resume/retry, --on-conflict semantics, throughput diagnostics |
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 |
pg_class/pg_stats/pg_indexes SQL, correlated-predicate verification |
| 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 |
MCP Tools Available
The aurora-dsql MCP server provides these tools:
Database 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 list_tables tool. Use readonly_query with information_schema.
See mcp-setup.md for detailed setup instructions.
See mcp-tools.md for detailed usage and examples.
AWS Knowledge MCP (awsknowledge)
Consult 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 |
aurora dsql transaction limits |
| Max data size per transaction |
10 MiB |
aurora dsql transaction limits |
| Max transaction duration |
5 minutes |
aurora dsql transaction limits |
| Max connections per cluster |
10,000 |
aurora dsql connection limits |
| Auth token expiry |
15 minutes |
aurora dsql authentication token |
| Max connection duration |
60 minutes |
aurora dsql connection limits |
| Max indexes per table |
24 |
aurora dsql index limits |
| Max columns per index |
8 |
aurora dsql index limits |
| IDENTITY/SEQUENCE CACHE values |
1 or >= 65536 |
aurora dsql sequence cache |
| Supported column data types |
See docs |
aurora dsql supported data types |
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 awsknowledge is unavailable, use the defaults above and flag that limits should be verified against DSQL documentation.
CLI Tools
Use the AWS CLI, psql, and aurora-dsql-loader 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.
Quick Start
- Explore: Use
readonly_query with information_schema to list tables. Use get_schema for table structure.
- Query: Use
readonly_query for SELECT queries. MUST include tenant_id in WHERE for multi-tenant apps. MUST build SQL with safe_query.build().
- Schema changes: Use
transact with one DDL per transaction. MUST batch DML under 3,000 rows. MUST use CREATE INDEX ASYNC in a separate call. Use dsql_lint to validate first.
- Bulk load data: Use
aurora-dsql-loader for CSV/TSV/Parquet. Load data-loading.md for details. Use --dry-run first.
Common Workflows
Workflow 1: Create Multi-Tenant Schema
- 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
CREATE INDEX ASYNC exclusively
- 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)
Workflow 2: Safe Data Migration
MUST validate every DDL with dsql_lint(fix=true) before executing. DML does not require linting.
- Validate DDL with
dsql_lint(sql=..., fix=true) — handle diagnostics per dsql-lint.md
- 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
ALTER TABLE in its own transact call — DSQL rejects multi-DDL transactions with multiple 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.
Workflow 3: Bulk Data Loading
Use aurora-dsql-loader for CSV, TSV, or Parquet loads. MUST load data-loading.md before advising on throughput or diagnosing slow loads.
- Validate with
--dry-run first
- Run with
--manifest-dir on persistent storage (not /tmp — tmpfs on AL2023, lost on crash) and --header if file has a header row
- On failure: resume with
--resume-job-id; for duplicates use --on-conflict do-nothing
- For large tables: create secondary indexes after load using
CREATE INDEX ASYNC
Workflow 4: Application-Layer Referential Integrity
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.
Workflow 5: Query with Tenant Isolation
- MUST authorize the caller against the tenant — format validation does not establish authorization
- MUST build SQL with
safe_query.build() — use allow()/regex() for
values (emits 'v'), ident() for table/column names (emits "v").
See input-validation.md
- MUST include
tenant_id in the WHERE clause; reject cross-tenant access at the application layer
Workflow 6: Set Up Scoped Database Roles
MUST load access-control.md for role setup, IAM mapping, and schema permissions.
Workflow 7: Table Recreation DDL Migration
Use the Table Recreation Pattern for ALTER COLUMN TYPE, DROP COLUMN, DROP CONSTRAINT, or MODIFY PRIMARY KEY. 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 dsql_lint(sql=..., fix=true) before execution.
MUST load ddl-migrations/overview.md before attempting any of these operations.
Workflow 8: Validate and Migrate to DSQL
MUST load dsql-lint.md before running dsql_lint. Run dsql_lint(sql=source_sql, fix=true) to validate and auto-convert. For MySQL-origin SQL, MUST cross-check against mysql-migrations/type-mapping.md even when lint returns clean. On parse_error, fall back to manual conversion then re-lint.
Workflow 9: Query Plan Explainability
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 readonly_query exclusively. Rewrite DML to SELECT for plan capture. MUST NOT use transact --allow-writes for plan capture.
Workflow 10: Full PostgreSQL → DSQL Schema Migration
MUST load pg-migrations/type-mapping.md and pg-migrations/schema-objects.md. Run dsql_lint(fix=true) 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.
Workflow 11: ORM Migration (Django/Hibernate/Rails)
Load orm-guides/overview.md for adapter names and framework-specific gotchas.
Error Scenarios
awsknowledge returns no results: Use the default limits in the table above and note that limits should be verified against DSQL documentation.
dsql_lint 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.
- 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.
Additional Resources
1---
2name: dsql
3description: "Build with Aurora DSQL — manage schemas, execute queries, handle migrations, diagnose query plans, load data, and develop applications with a serverless, distributed SQL database. Covers IAM auth, multi-tenant patterns, MySQL-to-DSQL and PostgreSQL-to-DSQL schema conversion, FK replacement code generation, OCC retry patterns, ORM migration (Django/Hibernate/Rails), DDL operations, query plan explainability, SQL compatibility validation, and bulk data loading. Triggers on phrases like: DSQL, Aurora DSQL, distributed SQL database, serverless PostgreSQL-compatible database, migrate to DSQL, DSQL query plan, DSQL EXPLAIN ANALYZE, DSQL ENUM, DSQL foreign key, DSQL OCC retry, DSQL multi-region, DSQL JSONB, DSQL GIN index, load into DSQL, load CSV into DSQL, bulk load DSQL, aurora-dsql-loader."
4license: Apache-2.0
5metadata:
6 tags: aws, aurora, dsql, distributed-sql, distributed, distributed-database, database, serverless, serverless-database, postgresql, postgres, sql, schema, migration, multi-tenant, iam-auth, aurora-dsql, mcp, orm, enum, foreign-key, occ-retry, django, hibernate, rails, multi-region, schema-conversion, type-mapping, data-loading
7---
8
9# Amazon Aurora DSQL Skill
10
11Aurora 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-loader`.
12
13---
14
15## Reference Files
16
17Load these files as needed for detailed guidance:
18
19### Core:
20
21| Reference | When to Load | Contains |
22| --------------------------------------------------------- | --------------------------------------------------- | ------------------------------------------------------------------------------------------ |
23| [development-guide.md](references/development-guide.md) | ALWAYS before schema changes or DB operations | Best practices, DDL rules, transaction limits, app-layer referential integrity |
24| [language.md](references/language.md) | MUST load for language-specific choices | Driver selection, DSQL Connectors, connection code |
25| [access-control.md](references/access-control.md) | MUST load for roles, grants, or sensitive data | Scoped role setup, IAM-to-database role mapping |
26| [troubleshooting.md](references/troubleshooting.md) | SHOULD load for errors or unexpected behavior | OCC errors, connection failures, cluster state errors, token expiry, DDL rejection causes |
27| [dsql-examples.md](references/dsql-examples.md) | Load for implementation examples | Multi-tenant schema examples, batch operations, FK validation patterns, connection pooling |
28| [onboarding.md](references/onboarding.md) | User requests "Get started with DSQL" | Interactive step-by-step guide |
29| [occ-retry-patterns.md](references/occ-retry-patterns.md) | MUST load for OCC retry code or conflict mitigation | DSQL Connectors, manual retry pattern, idempotent design |
30
31### MCP:
32
33| Reference | When to Load | Contains |
34| --------------------------------------- | --------------------------------------------------------------- | ------------------------------------------------------------------ |
35| [mcp-setup.md](mcp/mcp-setup.md) | Always for MCP server guidance | Setup instructions, 2 configuration options |
36| [mcp-tools.md](mcp/mcp-tools.md) | For MCP tool syntax and examples | Tool parameters, [input validation](mcp/tools/input-validation.md) |
37| [dsql-lint.md](references/dsql-lint.md) | MUST load before running `dsql_lint` or processing external SQL | Tool reference, fix statuses, unfixable error resolution |
38
39### DDL Migrations:
40
41| Reference | When to Load | Contains |
42| --------------------------------------------------------------------------------------------- | ------------------------------------------------------ | --------------------------------------- |
43| [ddl-migrations/overview.md](references/ddl-migrations/overview.md) | MUST load for DROP COLUMN, ALTER TYPE, DROP CONSTRAINT | Table recreation pattern, verify & swap |
44| [ddl-migrations/column-operations.md](references/ddl-migrations/column-operations.md) | DROP COLUMN, ALTER TYPE, SET/DROP NOT NULL/DEFAULT | Column-level migration patterns |
45| [ddl-migrations/constraint-operations.md](references/ddl-migrations/constraint-operations.md) | ADD/DROP CONSTRAINT, MODIFY PRIMARY KEY | Constraint and structural changes |
46| [ddl-migrations/batched-migration.md](references/ddl-migrations/batched-migration.md) | Tables exceeding 3,000 rows | Batching patterns, progress tracking |
47
48### MySQL Migrations:
49
50| Reference | When to Load | Contains |
51| ----------------------------------------------------------------------------------- | ------------------------------------ | ---------------------------------------- |
52| [mysql-migrations/type-mapping.md](references/mysql-migrations/type-mapping.md) | MUST load for MySQL → DSQL migration | Data type mappings, feature alternatives |
53| [mysql-migrations/ddl-operations.md](references/mysql-migrations/ddl-operations.md) | Translating MySQL DDL to DSQL | AUTO_INCREMENT, ENUM, SET, FK patterns |
54| [mysql-migrations/full-example.md](references/mysql-migrations/full-example.md) | Complete MySQL table migration | End-to-end example with decision summary |
55
56### PostgreSQL Migrations:
57
58| Reference | When to Load | Contains |
59| --------------------------------------------------------------------------------- | ---------------------------------------------------------------- | -------------------------------------------------- |
60| [pg-migrations/type-mapping.md](references/pg-migrations/type-mapping.md) | MUST load for PG → DSQL type questions | C collation rules, NUMERIC precision, JSON/JSONB |
61| [pg-migrations/fk-replacement.md](references/pg-migrations/fk-replacement.md) | MUST load for FK validation code generation | Tenant-scoped validate_fk_*() template, cascade |
62| [pg-migrations/index-conversion.md](references/pg-migrations/index-conversion.md) | MUST load for unfixable index diagnostics | GIN/GiST/BRIN → btree, partial, expression indexes |
63| [pg-migrations/schema-objects.md](references/pg-migrations/schema-objects.md) | MUST load for ENUM, materialized views, extensions, multi-schema | ENUM → CHECK, views, role/IAM mapping |
64| [pg-migrations/multi-region.md](references/pg-migrations/multi-region.md) | Multi-region, active-active, or HA questions | Architecture, geographic partitioning |
65
66### ORM Guides:
67
68| Reference | When to Load | Contains |
69| ----------------------------------------------------------- | ------------------------- | ---------------------------------------------------------------- |
70| [orm-guides/overview.md](references/orm-guides/overview.md) | Migrating any ORM to DSQL | Adapter names, key gotchas for Django/Hibernate/Rails/SQLAlchemy |
71
72### Data Loading:
73
74| Reference | When to Load | Contains |
75| --------------------------------------------- | -------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
76| [data-loading.md](references/data-loading.md) | Planning or running bulk loads with `aurora-dsql-loader` | Fresh-vs-warm partitions, resume/retry, `--on-conflict` semantics, throughput diagnostics |
77
78### Query Plan Explainability:
79
80| Reference | When to Load | Contains |
81| --------------------------------------------------------------------------------- | ------------------------------- | ------------------------------------------------------------------------- |
82| [query-plan/plan-interpretation.md](references/query-plan/plan-interpretation.md) | MUST load at Workflow 9 Phase 0 | DSQL node types, Node Duration math, estimation-error bands |
83| [query-plan/catalog-queries.md](references/query-plan/catalog-queries.md) | MUST load at Workflow 9 Phase 0 | `pg_class`/`pg_stats`/`pg_indexes` SQL, correlated-predicate verification |
84| [query-plan/guc-experiments.md](references/query-plan/guc-experiments.md) | MUST load at Workflow 9 Phase 0 | GUC experiment procedures, 30-second skip protocol |
85| [query-plan/report-format.md](references/query-plan/report-format.md) | MUST load at Workflow 9 Phase 0 | Required report structure, element checklist, support request template |
86
87---
88
89## MCP Tools Available
90
91The `aurora-dsql` MCP server provides these tools:
92
93**Database Operations:**
94
951. **readonly_query** - Execute SELECT queries (returns list of dicts)
962. **transact** - Execute DDL/DML statements in transaction (takes list of SQL statements)
973. **get_schema** - Get table structure for a specific table
98
99**SQL Validation:**
100
1011. **dsql_lint** - Validate SQL for DSQL compatibility and optionally auto-fix issues. Use before executing externally-sourced SQL.
102
103**Documentation & Knowledge:**
104
1051. **dsql_search_documentation** - Search Aurora DSQL documentation
1062. **dsql_read_documentation** - Read specific documentation pages
1073. **dsql_recommend** - Get DSQL best practice recommendations
108
109**Note:** There is no `list_tables` tool. Use `readonly_query` with information_schema.
110
111See [mcp-setup.md](mcp/mcp-setup.md) for detailed setup instructions.
112See [mcp-tools.md](mcp/mcp-tools.md) for detailed usage and examples.
113
114### AWS Knowledge MCP (`awsknowledge`)
115
116Consult for verifying DSQL service limits before advising users. The numeric limits below are
117defaults that may change — when a user's decision depends on an exact limit, verify it first:
118
119| Limit | Default | Verify query |
120| ------------------------------ | ------------- | ---------------------------------- |
121| Max rows per transaction | 3,000 | `aurora dsql transaction limits` |
122| Max data size per transaction | 10 MiB | `aurora dsql transaction limits` |
123| Max transaction duration | 5 minutes | `aurora dsql transaction limits` |
124| Max connections per cluster | 10,000 | `aurora dsql connection limits` |
125| Auth token expiry | 15 minutes | `aurora dsql authentication token` |
126| Max connection duration | 60 minutes | `aurora dsql connection limits` |
127| Max indexes per table | 24 | `aurora dsql index limits` |
128| Max columns per index | 8 | `aurora dsql index limits` |
129| IDENTITY/SEQUENCE CACHE values | 1 or >= 65536 | `aurora dsql sequence cache` |
130| Supported column data types | See docs | `aurora dsql supported data types` |
131
132**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.
133
134**Fallback:** If `awsknowledge` is unavailable, use the defaults above and flag that limits should be verified against [DSQL documentation](https://docs.aws.amazon.com/aurora-dsql/latest/userguide/).
135
136## CLI Tools
137
138Use the AWS CLI, `psql`, and `aurora-dsql-loader` directly for cluster management, SQL connections, and bulk data loading from local or S3 CSV/TSV/Parquet files. Load [data-loading.md](references/data-loading.md) for loader guidance.
139
140---
141
142## Quick Start
143
1441. **Explore:** Use `readonly_query` with `information_schema` to list tables. Use `get_schema` for table structure.
1452. **Query:** Use `readonly_query` for SELECT queries. **MUST** include `tenant_id` in WHERE for multi-tenant apps. **MUST** build SQL with `safe_query.build()`.
1463. **Schema changes:** Use `transact` with one DDL per transaction. **MUST** batch DML under 3,000 rows. **MUST** use `CREATE INDEX ASYNC` in a separate call. Use `dsql_lint` to validate first.
1474. **Bulk load data:** Use `aurora-dsql-loader` for CSV/TSV/Parquet. Load [data-loading.md](references/data-loading.md) for details. Use `--dry-run` first.
148
149---
150
151## Common Workflows
152
153### Workflow 1: Create Multi-Tenant Schema
154
1551. Create main table with tenant_id column using transact
1562. Create async index on tenant_id in separate transact call
1573. Create composite indexes for common query patterns (separate transact calls)
1584. Verify schema with get_schema
159
160- MUST include tenant_id in all tables
161- MUST use `CREATE INDEX ASYNC` exclusively
162- MUST issue each DDL in its own transact call: `transact(["CREATE TABLE ..."])`
163- MUST serialize arrays as JSONB; expand at query time with `jsonb_array_elements_text(data)`
164
165### Workflow 2: Safe Data Migration
166
167MUST validate every DDL with `dsql_lint(fix=true)` before executing. DML does not require linting.
168
1691. Validate DDL with `dsql_lint(sql=..., fix=true)` — handle diagnostics per [dsql-lint.md](references/dsql-lint.md)
1702. Add column: `transact(["ALTER TABLE ... ADD COLUMN ..."])`
1713. Populate existing rows with UPDATE (batched under 3,000 rows)
1724. Verify with readonly_query COUNT
1735. Create index if needed: validate then `transact(["CREATE INDEX ASYNC ..."])`
174
175- MUST issue each `ALTER TABLE` in its own `transact` call — DSQL rejects multi-DDL transactions with `multiple ddl statements not supported in a transaction`
176- MUST add column with only name and type; apply DEFAULT via separate UPDATE
177- MUST batch updates under 3,000 rows in separate transact calls
178
179**Recovery:** Resume failed batches by filtering `WHERE new_column IS NULL`.
180
181### Workflow 3: Bulk Data Loading
182
183Use `aurora-dsql-loader` for CSV, TSV, or Parquet loads. MUST load [data-loading.md](references/data-loading.md) before advising on throughput or diagnosing slow loads.
184
1851. Validate with `--dry-run` first
1862. Run with `--manifest-dir` on persistent storage (not `/tmp` — tmpfs on AL2023, lost on crash) and `--header` if file has a header row
1873. On failure: resume with `--resume-job-id`; for duplicates use `--on-conflict do-nothing`
1884. For large tables: create secondary indexes after load using `CREATE INDEX ASYNC`
189
190### Workflow 4: Application-Layer Referential Integrity
191
192**INSERT:** MUST validate parent exists with readonly_query → throw error if not found → insert child with transact.
193
194**DELETE:** MUST check dependents with readonly_query COUNT → return error if dependents exist → delete with transact if safe.
195
196### Workflow 5: Query with Tenant Isolation
197
1981. **MUST** authorize the caller against the tenant — format validation does not establish authorization
1992. **MUST** build SQL with [`safe_query.build()`](mcp/tools/safe_query.py) — use `allow()`/`regex()` for
200 values (emits `'v'`), `ident()` for table/column names (emits `"v"`).
201 See [input-validation.md](mcp/tools/input-validation.md)
2023. **MUST** include `tenant_id` in the WHERE clause; reject cross-tenant access at the application layer
203
204### Workflow 6: Set Up Scoped Database Roles
205
206MUST load [access-control.md](references/access-control.md) for role setup, IAM mapping, and schema permissions.
207
208### Workflow 7: Table Recreation DDL Migration
209
210Use the **Table Recreation Pattern** for `ALTER COLUMN TYPE`, `DROP COLUMN`, `DROP CONSTRAINT`, or `MODIFY PRIMARY KEY`. 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 `dsql_lint(sql=..., fix=true)` before execution.
211
212MUST load [ddl-migrations/overview.md](references/ddl-migrations/overview.md) before attempting any of these operations.
213
214### Workflow 8: Validate and Migrate to DSQL
215
216MUST load [dsql-lint.md](references/dsql-lint.md) before running `dsql_lint`. Run `dsql_lint(sql=source_sql, fix=true)` to validate and auto-convert. For MySQL-origin SQL, MUST cross-check against [mysql-migrations/type-mapping.md](references/mysql-migrations/type-mapping.md) even when lint returns clean. On `parse_error`, fall back to manual conversion then re-lint.
217
218### Workflow 9: Query Plan Explainability
219
220Explains 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.**
221
222MUST load all four reference files at Phase 0: [query-plan/plan-interpretation.md](references/query-plan/plan-interpretation.md), [query-plan/catalog-queries.md](references/query-plan/catalog-queries.md), [query-plan/guc-experiments.md](references/query-plan/guc-experiments.md), [query-plan/report-format.md](references/query-plan/report-format.md). The phase procedures (capture plan, gather evidence, experiment, produce report) are defined in those files.
223
224**Safety.** Plan capture uses `readonly_query` exclusively. Rewrite DML to SELECT for plan capture. **MUST NOT** use `transact --allow-writes` for plan capture.
225
226### Workflow 10: Full PostgreSQL → DSQL Schema Migration
227
228MUST load [pg-migrations/type-mapping.md](references/pg-migrations/type-mapping.md) and [pg-migrations/schema-objects.md](references/pg-migrations/schema-objects.md). Run `dsql_lint(fix=true)` 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.
229
230### Workflow 11: ORM Migration (Django/Hibernate/Rails)
231
232Load [orm-guides/overview.md](references/orm-guides/overview.md) for adapter names and framework-specific gotchas.
233
234## Error Scenarios
235
236- **`awsknowledge` returns no results:** Use the default limits in the table above and note that limits should be verified against [DSQL documentation](https://docs.aws.amazon.com/aurora-dsql/latest/userguide/).
237- **`dsql_lint` unavailable or timing out:** See the Error Handling section of [dsql-lint.md](references/dsql-lint.md). Do not silently skip validation — inform the user and require explicit confirmation before proceeding with manual rules from [development-guide.md](references/development-guide.md).
238- **OCC serialization error:** Retry the transaction. If persistent, check for hot-key contention — see [troubleshooting.md](references/troubleshooting.md).
239- **Transaction exceeds limits:** Split into batches under 3,000 rows — see [batched-migration.md](references/ddl-migrations/batched-migration.md).
240- **Token expiration mid-operation:** Generate a fresh IAM token — see [authentication-guide.md](references/auth/authentication-guide.md). See [troubleshooting.md](references/troubleshooting.md) for other issues.
241
242## Additional Resources
243
244- [Aurora DSQL Documentation](https://docs.aws.amazon.com/aurora-dsql/latest/userguide/)
245- [Code Samples Repository](https://github.com/aws-samples/aurora-dsql-samples)