Creating an RDS Instance (CLI)
Bash
# Create a PostgreSQL instance
aws rds create-db-instance \
--db-instance-identifier my-postgres \
--db-instance-class db.t3.medium \
--engine postgres \
--engine-version 16.2 \
--master-username admin \
--master-user-password "SecurePass123!" \
--allocated-storage 100 \
--storage-type gp3 \
--storage-encrypted \
--vpc-security-group-ids sg-xxxxxxxx \
--db-subnet-group-name my-subnet-group \
--backup-retention-period 7 \
--no-publicly-accessible \
--multi-az \
--deletion-protection
# Check creation status
aws rds describe-db-instances \
--db-instance-identifier my-postgres \
--query 'DBInstances[0].DBInstanceStatus'Security Group Configuration
RDS should block public access and allow connections only from the application server security group.
Bash
# RDS security group — allow port 5432 only from the app server SG
aws ec2 authorize-security-group-ingress \
--group-id sg-rds-xxxxxx \
--protocol tcp \
--port 5432 \
--source-group sg-app-xxxxxx
# Verify public accessibility
aws rds describe-db-instances \
--query 'DBInstances[0].PubliclyAccessible'Parameter Group Tuning
Bash
# Create a parameter group
aws rds create-db-parameter-group \
--db-parameter-group-name my-postgres16 \
--db-parameter-group-family postgres16 \
--description "Custom PostgreSQL 16 params"
# Modify parameters
aws rds modify-db-parameter-group \
--db-parameter-group-name my-postgres16 \
--parameters \
"ParameterName=shared_buffers,ParameterValue={DBInstanceClassMemory/4},ApplyMethod=pending-reboot" \
"ParameterName=log_min_duration_statement,ParameterValue=1000,ApplyMethod=immediate" \
"ParameterName=max_connections,ParameterValue=200,ApplyMethod=pending-reboot"
# Apply the parameter group to the instance
aws rds modify-db-instance \
--db-instance-identifier my-postgres \
--db-parameter-group-name my-postgres16 \
--apply-immediatelyBackups and Snapshots
Bash
# Check automated backup settings
aws rds describe-db-instances \
--db-instance-identifier my-postgres \
--query 'DBInstances[0].{Backup:BackupRetentionPeriod,Window:PreferredBackupWindow}'
# Create a manual snapshot
aws rds create-db-snapshot \
--db-instance-identifier my-postgres \
--db-snapshot-identifier my-postgres-snap-$(date +%Y%m%d)
# List snapshots
aws rds describe-db-snapshots \
--db-instance-identifier my-postgres \
--query 'DBSnapshots[*].[DBSnapshotIdentifier,SnapshotCreateTime,Status]' \
--output table
# Restore from a snapshot
aws rds restore-db-instance-from-db-snapshot \
--db-instance-identifier my-postgres-restored \
--db-snapshot-identifier my-postgres-snap-20250527Read Replica
Bash
# Create a read replica
aws rds create-db-instance-read-replica \
--db-instance-identifier my-postgres-reader \
--source-db-instance-identifier my-postgres \
--db-instance-class db.t3.small
# Check the replica endpoint
aws rds describe-db-instances \
--db-instance-identifier my-postgres-reader \
--query 'DBInstances[0].Endpoint'Endpoint Lookup and Connection
Bash
# Look up the endpoint
aws rds describe-db-instances \
--db-instance-identifier my-postgres \
--query 'DBInstances[0].Endpoint.Address' \
--output text
# Connection test from EC2
psql -h my-postgres.xxxxxxxx.ap-northeast-2.rds.amazonaws.com \
-U admin -d postgres -p 5432Cost Optimization Tips
- Use db.t3.micro with a single AZ for development
- Use gp3 storage (cheaper than gp2, with independent performance)
- Stop the RDS instance when unused (up to 7 days)
- Aurora Serverless v2 is a good fit for irregular traffic patterns
Editorial note
AI tools may assist drafting. Check the evidence in each guide for whether commands were run and which environment was used. Confirm the current docs for your version before applying instructions, and email us about errors. email us
Topic-related official docs (auto-linked · not per-claim sources)PostgreSQL documentation ↗MySQL manual ↗AWS documentation ↗
Questions & answers
Ask a question about this guide. We'll review and reply.