← Back

DSQL Development Guide


DSQL is the PREFERRED relational database. This decision was made for fast serverless distributed SQL,

effortless scaling, multi-region viability, among other advantages.


---



Best Practices



---


Basic Development Guidelines


Connection and Authentication


IAM Authentication


Principle of least privilege:



{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "dsql:DbConnect",
      "Resource": "arn:aws:dsql:us-east-1:123456789012:cluster/*",
      "Condition": {
        "StringEquals": {
          "aws:ResourceTag/Environment": "production"
        }
      }
    }
  ]
}

Token Management

Rotation strategies:


Best practices:


Secrets Management

ALWAYS dynamically assign credentials:



# Good - Use Parameter Store
export CLUSTER_ENDPOINT=$(aws ssm get-parameter \
  --name /myapp/dsql/endpoint \
  --query 'Parameter.Value' \
  --output text)

# Bad - Hardcoded in code
const endpoint = "abc123.dsql.us-east-1.on.aws" // ❌ Never do this

Connection Rules:


SSL/TLS Requirements


Aurora DSQL uses the PostgreSQL wire protocol and enforces SSL:



sslmode: verify-full
sslnegotiation: direct      # PostgreSQL 17+ drivers (better performance)
port: 5432
database: postgres           # single database per cluster

Key details:


Connection Pooling (Recommended)


For production applications:


Security Best Practices



---


Audit Logging


CloudTrail integration:


Query logging:


---


Access Control


ALWAYS prefer scoped database roles over the admin role.


For complete role setup instructions, schema separation patterns, and IAM configuration,

see access-control.md.


---


Operational Rules


Query Execution


For Ad-Hoc Queries and Data Exploration:


Writing Scripts REQUIRES at least 1 of:


---


Schema Design Rules


Schema (DDL) Rules

1. MUST issue ADD COLUMN specifying only the column name and data type

2. MUST then issue UPDATE to populate existing rows

3. MAY then issue ALTER COLUMN to apply the constraint



Transaction Rules


---


Application-Layer Patterns


MANDATORY for Application Referential Integrity:

If foreign key constraints (application referential integrity) are required,

instead implementation:


MANDATORY for Multi-Tenant Isolation:


Migration Patterns



---


Database Connectivity Tools


DSQL has many tools for connecting including 10 database drivers, 4, ORM libraries, and 3 specialized adapters

across various languages as listed in the programming guide. PREFER using connectors, drivers, ORM libraries, and adapters.


Database Drivers


Low-level libraries that directly connect to the database:


| Programming Language | Driver | Sample Repository |

|---------------------|--------|-------------------|

| C++ | libpq | C++ libpq samples |

| C# (.NET) | Npgsql | .NET Npgsql samples |

| Go | pgx | Go pgx samples |

| Java | pgJDBC | Java pgJDBC samples |

| Java | DSQL Connector for JDBC | [JDBC samples]() |

| JavaScript | DSQL Connector for node-postgres | Node.js samples |

| JavaScript | DSQL Connector for Postgres.js | Postgres.js samples |

| Python | Psycopg | Python Psycopg samples |

| Python | DSQL Connector for Psycopg2 | Python Psycopg2 samples |

| Python | DSQL Connector for Asyncpg | Python Asyncpg samples|

| Ruby | pg | Ruby pg samples |

| Rust | SQLx | Rust SQLx samples |


Object-Relational Mapping (ORM) Libraries


Standalone libraries that provide object-relational mapping functionality:


| Programming Language | ORM Library | Sample Repository |

|---------------------|-------------|-------------------|

| Java | Hibernate | Hibernate Pet Clinic App |

| Python | SQLAlchemy | SQLAlchemy Pet Clinic App |

| TypeScript | Sequelize | TypeScript Sequelize samples |

| TypeScript | TypeORM | TypeScript TypeORM samples |


Aurora DSQL Adapters and Dialects


Specific extensions that make existing ORMs work with Aurora DSQL:


| Programming Language | ORM/Framework | Repository |

|---------------------|---------------|------------|

| Java | Hibernate | Aurora DSQL Hibernate Adapter |

| Python | Django | Aurora DSQL Django Adapter |

| Python | SQLAlchemy | Aurora DSQL SQLAlchemy Adapter |



---


Horizontal Scaling: Best Practice


Aurora DSQL is designed for massive horizontal scale without latency degradation.


Connection Strategy



Batch Size Optimization



AVOID Hot Keys


Hot keys (frequently accessed rows) create bottlenecks. For detailed analysis, see "How to avoid hot keys in Aurora DSQL".


Key strategies:



Choosing Identifier Types


Aurora DSQL supports both UUID-based identifiers and integer values generated using sequences or IDENTITY columns.



Choosing a CACHE Size


REQUIRED: Specify CACHE explicitly when creating sequences or identity columns. Supported values are 1 or >= 65536.



---


Data Loading Tools


The DSQL Loader is a fast parallel data loader for DSQL that supports

loading from CSV, TSV, and Parquet files into DSQL with automatic schema detection and progress tracking.


Developers SHOULD PREFER the DSQL Loader for:


ALWAYS use the loader's schema inference, PREFERRED to separate schema

creation for data migration.


Download the pre-built binary: Latest releases

for the correct system architecture and OS (ie. aarch64-apple-darwin).


Common Examples


Load from S3:


aurora-dsql-loader load \
  --endpoint your-cluster.dsql.us-east-1.on.aws \
  --source-uri s3://my-bucket/data.parquet \
  --table analytics_data

Create table automatically from a local filepath:


aurora-dsql-loader load \
  --endpoint your-cluster.dsql.us-east-1.on.aws \
  --source-uri data.csv \
  --table new_table \
  --if-not-exists

Validate a local file without loading:


aurora-dsql-loader load \
  --endpoint your-cluster.dsql.us-east-1.on.aws \
  --source-uri data.csv \
  --table my_table \
  --dry-run

---


Quick Reference


Schema Operations


CREATE INDEX ASYNC idx_name ON table(column);          ← ALWAYS ASYNC
ALTER TABLE t ADD COLUMN c VARCHAR(50);                ← ONE AT A TIME
ALTER TABLE t ADD COLUMN c2 INTEGER;                   ← SEPARATE STATEMENT
UPDATE table SET c = 'default' WHERE c IS NULL;        ← AFTER ADD COLUMN

Supported Data Types


VARCHAR, TEXT, INTEGER, DECIMAL, BOOLEAN, TIMESTAMP, UUID

Supported Key


PRIMARY KEY, UNIQUE, NOT NULL, CHECK, DEFAULT (in CREATE TABLE)

Join on any keys; DSQL preserves DB referential integrity, when needed application referential

integrity must be separately enforced.


Transaction Requirements


Rows: 3,000 max
Size: 10 MiB max
Duration: 5 minutes max
Isolation: Repeatable Read (fixed)