Lesson 4 of 4 · AWS Database Administration

Managing Databases on AWS

The AWS DBA's core responsibilities across every service: provisioning, performance tuning, high availability and disaster recovery, security and compliance, and monitoring and cost control.

Beginner 7 sections 9 min read

The AWS DBA's job

Whichever AWS database service you use, AWS runs the servers, patches the engine, and takes the backups. The DBA's job moves up a level: designing the right setup, keeping it fast, making sure it survives failures, locking it down, and keeping an eye on what it costs.

This lesson covers those five core responsibilities across AWS's managed databases: Amazon RDS, Amazon Aurora, and Amazon DynamoDB. The tools differ by engine, but the job is the same, and it's the same job you saw in the Azure module.

Provisioning and architecture

Every new database starts with a set of design decisions, usually made with the application team:

  • Service and engine: which service fits the application, as covered in AWS Database Services, and for RDS, which engine, edition, and license model.
  • Size: the instance class and storage for RDS, provisioned or Serverless v2 for Aurora, or on-demand or provisioned capacity for DynamoDB. Start modestly: scaling up later takes minutes.
  • Where it lives: which account and region, with tags that follow the company's standards, such as app, env, and owner.
  • Network: a DB subnet group of private subnets in several zones, and a security group that lets in only the application, as covered under security below.

Most teams create databases with infrastructure as code, such as AWS CloudFormation or Terraform, so every environment is built the same way. Changing size is a single command:

# move kofi-ora-01 to a larger instance class now, rather than in the maintenance window
$ aws rds modify-db-instance --db-instance-identifier kofi-ora-01 \
    --db-instance-class db.m6i.xlarge --apply-immediately

Without --apply-immediately, the change waits for the next maintenance window. A new instance class means a short outage either way, or a quick failover with Multi-AZ, so schedule production changes and make sure applications retry connections.

Performance tuning and optimization

Each engine keeps its own performance tools, and AWS adds some of its own on top:

ServiceMain performance tools
Every RDS and Aurora engineCloudWatch Database Insights (database load, top SQL, and waits), Enhanced Monitoring (operating system metrics), and Amazon DevOps Guru for RDS
RDS for OracleAWR and ADDM (Enterprise Edition with the Diagnostics Pack license), Statspack (through an option group), and the V$ views
RDS for SQL ServerQuery Store and dynamic management views (DMVs)
PostgreSQL (RDS and Aurora)pg_stat_statements, EXPLAIN ANALYZE, and the PostgreSQL log
MySQL (RDS and Aurora)Slow query log and Performance Schema
DynamoDBConsumed capacity, throttled requests, and CloudWatch Contributor Insights for the busiest keys
CloudWatch Database Insights
AWS's main database monitoring view, which now includes what used to be called Performance Insights. Its key measure is database load: the average number of sessions active at once, broken down by wait event, SQL statement, user, or host. Oracle DBAs will recognize the idea from Active Session History (ASH). When load rises above the number of vCPUs, sessions are waiting, and the breakdown shows on what.
Enhanced Monitoring
Operating system metrics, such as CPU per process, memory, and disk I/O, collected as often as every second. It fills the gap left by having no operating system login.

For example, finding the statements that take longest in RDS for Oracle and in Aurora PostgreSQL:

-- RDS for Oracle: from V$SQL
SELECT sql_id, executions,
       ROUND(elapsed_time / NULLIF(executions, 0) / 1000) AS avg_ms,
       SUBSTR(sql_text, 1, 60) AS sql_text
FROM   v$sql
ORDER  BY elapsed_time DESC
FETCH FIRST 5 ROWS ONLY;

-- Aurora PostgreSQL: from the pg_stat_statements extension
SELECT query, calls, mean_exec_time
FROM   pg_stat_statements
ORDER  BY mean_exec_time DESC
LIMIT  5;

High availability and disaster recovery

Every AWS database service can keep copies in several availability zones and take automated backups. The DBA decides how much further to go:

ServiceWithin a regionAcross regionsBackups
Amazon RDSMulti-AZ DB instance (one standby) or, for PostgreSQL and MySQL, a Multi-AZ DB cluster (two readable standbys)Cross-region read replicas, promoted in a disasterPoint-in-time restore for 1 to 35 days, plus manual snapshots copied to other regions
Amazon AuroraSix storage copies across three zones, with readers as failover targetsAurora Global DatabaseContinuous, with point-in-time restore for 1 to 35 days, plus snapshots
Amazon DynamoDBBuilt in: data is always stored across three zonesGlobal tables, which accept writes in every regionPoint-in-time recovery for up to 35 days, plus on-demand backups

The DBA's job is to match these options to each database's RPO and RTO, from the Backup, Recovery, and High Availability lesson, and to test failovers and restores regularly. You can trigger a test failover on purpose:

# fail an RDS Multi-AZ instance over to its standby, to rehearse
$ aws rds reboot-db-instance --db-instance-identifier kofi-ora-01 --force-failover

# promote an Aurora reader to be the writer
$ aws rds failover-db-cluster --db-cluster-identifier kofi-aurora-pg

Security and compliance

Under the shared responsibility model, AWS secures the cloud itself, and the DBA secures what's in it. AWS database security works in layers, so getting past one doesn't give an attacker everything:

NETWORKVPC, private subnets, security groups IDENTITYIAM, database authentication, Secrets Manager DATAKMS encryption at rest, TLS in transit, TDE Your data MONITORING CloudTrail,audit logs,and AmazonGuardDuty
Network: VPCs and security groups
Put databases in private subnets, create them with public access turned off, and use a security group that allows only the database port, and only from the application's security group. Applications in other VPCs or on-premises connect privately through VPC peering, AWS Transit Gateway, or a VPN.
Identity: IAM and database logins
IAM policies control who can create, change, or delete databases in AWS. Inside the database, PostgreSQL and MySQL support IAM database authentication, which replaces passwords with short-lived tokens; Oracle, SQL Server, PostgreSQL, and MySQL can also use Kerberos with the company's Active Directory. Where passwords are still needed, AWS Secrets Manager stores and rotates them automatically.
Access: two kinds of permissions
IAM permissions and database permissions are separate. An AWS administrator who can delete a database can't necessarily read its data; that's controlled with GRANT and roles, as in the DCL lesson.
Data: encryption
AWS KMS (Key Management Service) encrypts storage, backups, snapshots, and replicas, with AWS-managed keys or keys the company controls. Connections are encrypted with TLS. RDS for Oracle and SQL Server also support their engines' own Transparent Data Encryption (TDE).
Monitoring: auditing and threat detection
AWS CloudTrail records every action taken through AWS, such as who changed a security group or deleted a snapshot. Engine audit logs, such as Oracle unified auditing or the PostgreSQL pgaudit extension, can be published to CloudWatch Logs, and Database Activity Streams send a tamper-resistant record of database activity to security teams. Amazon GuardDuty watches login activity on Aurora and RDS for suspicious patterns.

For example, letting Kofi sign in to a PostgreSQL database with IAM instead of a password:

-- in the database: a user that signs in through IAM
CREATE USER kofi;
GRANT rds_iam TO kofi;

# on Kofi's machine: get a 15-minute token and use it as the password
$ export PGPASSWORD=$(aws rds generate-db-auth-token --region us-east-1 \
    --hostname kofi-aurora-pg.cluster-c1abcd2efgh3.us-east-1.rds.amazonaws.com \
    --port 5432 --username kofi)
$ psql "host=kofi-aurora-pg.cluster-c1abcd2efgh3.us-east-1.rds.amazonaws.com dbname=postgres user=kofi sslmode=require"

Monitoring and cost control

Everything in the Cloud Cost Optimization lesson applies on AWS, using these tools for every service:

Amazon CloudWatch
Collects metrics such as CPU, free storage, connections, and replica lag, with alarms that notify the team or trigger automation when a threshold is crossed. Database logs can be published to CloudWatch Logs for searching and longer-term retention.
AWS Cost Explorer and AWS Budgets
Show what each account, service, and tagged resource costs, with budgets and alerts when spending heads over.
AWS Trusted Advisor and AWS Compute Optimizer
Recommend savings, such as idle or oversized databases.

The biggest savings, and which services they apply to:

SavingApplies toHow it works
ReservationsRDS, Aurora, ElastiCache, DynamoDB provisioned capacityCommit to capacity for one or three years for steady production databases.
License choicesRDS for Oracle and SQL ServerCompare License Included with bringing your own license, avoid paying for Enterprise Edition where Standard Edition will do, and consider moving suitable applications to PostgreSQL.
Graviton instancesRDS and Aurora for PostgreSQL, MySQL, and MariaDBThe same work for less money than comparable Intel or AMD instances.
ServerlessAurora Serverless v2, DynamoDB on-demandPay for what's used, so idle and unpredictable databases cost little.
Stop and startRDS instances and Aurora clustersStop development databases when nobody's using them. They restart automatically after seven days.
Storage choicesRDS and AuroraUse gp3 rather than Provisioned IOPS where it's fast enough, switch busy Aurora clusters to I/O-Optimized, and delete manual snapshots nobody needs.
Timely upgradesRDS and Aurora for PostgreSQL and MySQLUpgrade before a version reaches the end of standard support, to avoid Extended Support charges.
Right-sizingEvery serviceUse CloudWatch and Database Insights history to scale down where capacity sits unused.

Key takeaways

  • The five core responsibilities, provisioning, performance, availability, security, and cost, are the same on AWS as on Azure; only the tools differ.
  • CloudWatch Database Insights shows database load by wait, SQL, and user for every RDS and Aurora engine, alongside each engine's own tools such as AWR, Query Store, and pg_stat_statements. Tune before you scale up.
  • Match Multi-AZ, Aurora readers, cross-region copies, and backups to each database's RPO and RTO, test failovers and restores, and protect backups in a separate account.
  • Secure in layers: private subnets and security groups, IAM and Secrets Manager, KMS encryption chosen at creation, and auditing with CloudTrail, audit logs, and GuardDuty.
  • Watch performance and spending with CloudWatch and Cost Explorer, and use reservations, license choices, Graviton, serverless, and timely upgrades to cut costs.