Sub topic 3
Instance classes and storage types
This chapter covers the two sizing decisions you make when you create a DB instance: the instance class, which sets CPU and memory, and the storage type, which sets disk performance. It assumes you know what RDS manages for you and that you can use the AWS CLI. You should also have seen the create-db-instance call from the provisioning example, which uses db.t4g.micro and gp3.
How the two choices interact
An RDS instance has two separate performance ceilings. The instance class limits CPU, memory, network bandwidth, and the maximum EBS bandwidth the instance can use. The storage type and its settings limit IOPS (read/write operations per second) and throughput (MiB/s) at the volume. The slower of the two ceilings is your real limit.
A large gp3 volume with 16,000 provisioned IOPS does nothing for you if the instance class cannot move data to EBS that quickly. A very large instance on a small gp2 volume will stall on disk. Size both together.
Instance class families
A class name has the form db.<family><generation>[attributes].<size>. In db.r6g.xlarge, r is the family, 6 is the generation, g marks AWS Graviton (Arm) processors, and xlarge is the size.
| Family | Profile | Typical use |
|---|---|---|
| `db.t` (for example `db.t4g`) | Burstable CPU with a baseline | Development, test, small or spiky workloads |
| `db.m` (for example `db.m6g`, `db.m6i`) | General purpose, balanced CPU and memory | Most production workloads |
| `db.r` (for example `db.r6g`, `db.r6i`) | Memory optimized, more RAM per vCPU | Large working sets, caching-heavy queries |
| `db.x`, `db.z` | Very high memory or high clock speed | Large Oracle or SQL Server licensing-bound workloads |
Three points matter in practice:
- Graviton classes (the
gsuffix) usually cost less than comparable Intel or AMD classes. They are available for MySQL, MariaDB, and PostgreSQL. Oracle and SQL Server need Intel or AMD classes. - Not every class is available for every engine, version, Region, and storage type. Check before you design around a class (see the CLI example below).
- Memory drives database performance more than CPU. Engines cache hot data in RAM. If the working set no longer fits, reads go to disk and latency rises. This is why
db.rclasses are the usual step up for read-heavy databases.
Burstable classes and CPU credits
db.t instances run at a baseline CPU level and accrue CPU credits while idle. They spend credits when they burst above the baseline. When the credit balance reaches zero, behavior depends on the credit mode. In unlimited mode, which RDS uses by default for new T instances, the instance keeps bursting and you pay a surcharge for the surplus credits. In standard mode, the CPU is throttled to the baseline.
If a db.t instance sits above its baseline for hours, a fixed-performance db.m class is usually cheaper and more predictable. Watch the CPUCreditBalance and CPUSurplusCreditBalance CloudWatch metrics. The Python example later in this chapter reads the first of these.
Storage types
RDS stores data on EBS volumes. For most engines you choose one of these types:
| Type | Performance model | When to use |
|---|---|---|
| `gp3` (General Purpose SSD) | Baseline IOPS and throughput that do not depend on size. You can raise IOPS and throughput on larger volumes. | Default choice for most workloads |
| `gp2` (General Purpose SSD, older) | 3 IOPS per GiB, with burst credits on small volumes | Existing instances that have not been migrated |
| `io1` / `io2` (Provisioned IOPS SSD) | You provision IOPS explicitly, with consistent low latency | Latency-sensitive, I/O-heavy production databases |
| `magnetic` | Legacy | Avoid. Not offered for new instances in most cases. |
gp3 and gp2
With gp3, performance is separate from size. For MySQL, MariaDB, and PostgreSQL, the baseline is 3,000 IOPS and 125 MiB/s on volumes below 400 GiB. From 400 GiB upward the baseline is higher, 12,000 IOPS and 500 MiB/s, and you can provision IOPS and throughput above it. The thresholds differ by engine, so check the current RDS documentation for yours.
With gp2, IOPS scale with size at 3 IOPS per GiB, with a floor of 100. A 100 GiB volume has a 300 IOPS baseline. Small volumes can burst to 3,000 IOPS using a credit bucket, and the BurstBalance metric shows how much is left. When it reaches zero, latency jumps. This is a common cause of "the database was fine for weeks and then got slow." Teams sometimes respond by buying a larger volume just to get more IOPS. gp3 removes that coupling, so migrating from gp2 to gp3 is normally the first tuning step.
Provisioned IOPS
io1 and io2 let you request a specific IOPS figure, subject to a maximum ratio of IOPS to storage size. They also have a minimum volume size. Use them when you have measured sustained I/O that gp3 cannot deliver, or when you need very consistent latency. Provisioned IOPS are billed whether or not you use them, so measure before you commit.
Storage limits and autoscaling
RDS can grow storage but cannot shrink it. For MySQL, MariaDB, and PostgreSQL the maximum is 64 TiB. If you over-allocate, the only way down is to create a new, smaller instance and migrate the data.
Storage autoscaling grows the volume automatically. You enable it by setting a maximum with --max-allocated-storage. RDS expands storage when free space drops below 10% for at least five minutes, provided at least six hours have passed since the last storage modification. The six-hour spacing applies to manual changes too, so plan large changes ahead of time. If a database is growing fast, a low maximum can run out of room before the cooldown lets it expand again.
A decision flow
Checking what is available
The following command lists the storage types that RDS offers for PostgreSQL on a db.t4g.micro. It counts the matching option rows per type.
aws rds describe-orderable-db-instance-options \
--engine postgres \
--db-instance-class db.t4g.micro \
--query "OrderableDBInstanceOptions[].StorageType" \
--output text | tr '\t' '\n' | sort | uniq -cRun it with a different --db-instance-class to see how availability changes. You can also add --engine-version to restrict the result to one version.
Changing class and storage on an existing instance
You can change both settings after creation. This example moves the instance to gp3, grows it, and enables autoscaling up to 500 GiB.
aws rds modify-db-instance \
--db-instance-identifier demo-pg \
--storage-type gp3 \
--allocated-storage 100 \
--max-allocated-storage 500 \
--apply-immediatelyWithout --apply-immediately, the change waits for the next maintenance window. Storage changes on a running instance keep the database available, but performance can drop while the volume is optimized. The instance status shows storage-optimization during this stage, and the instance cannot be modified again for storage until it finishes and the six-hour cooldown passes.
Changing the instance class is different. It restarts the database, so expect downtime. On a Multi-AZ deployment the downtime is shorter because RDS updates the standby first and then fails over. Schedule class changes in a quiet period.
Checking whether a burstable instance is running out of credits
This script reads the minimum CPU credit balance over the last three hours. A balance trending to zero means the instance needs a larger class or a switch to a non-burstable family.
from datetime import datetime, timedelta, timezone
import boto3
cloudwatch = boto3.client("cloudwatch")
now = datetime.now(timezone.utc)
response = cloudwatch.get_metric_statistics(
Namespace="AWS/RDS",
MetricName="CPUCreditBalance",
Dimensions=[{"Name": "DBInstanceIdentifier", "Value": "demo-pg"}],
StartTime=now - timedelta(hours=3),
EndTime=now,
Period=300,
Statistics=["Minimum"],
)
points = sorted(response["Datapoints"], key=lambda p: p["Timestamp"])
for point in points:
print(point["Timestamp"].isoformat(), round(point["Minimum"], 1))This metric only exists for burstable classes. On a db.m or db.r instance the list of datapoints is empty.
Common mistakes
- Choosing a class for CPU when the problem is memory. Check
FreeableMemoryand read IOPS before you add vCPUs. - Leaving a growing database on
gp2. Burst credits run out without warning, andBurstBalanceis the only advance signal. - Over-provisioning storage "to be safe." It cannot be shrunk, and you pay for it every month.
- Setting no autoscaling maximum on a database that grows quickly, or setting it so low that the cap is reached.
- Running production on a burstable class with unlimited mode and not watching the surplus-credit charges.
Exercise
A PostgreSQL database on a 200 GiB gp2 volume runs well for weeks, then queries suddenly slow down for hours at a time. CPU and memory metrics look normal. What is the likely cause, and what is the first change you would make?
Show answer
The volume baseline is 600 IOPS (3 IOPS per GiB). Heavy I/O drains the gp2 burst credits, and once the BurstBalance metric reaches zero the volume is limited to that baseline, so latency rises. Confirm by checking BurstBalance, ReadIOPS, WriteIOPS, and DiskQueueDepth in CloudWatch. The first change is to migrate to gp3 with modify-db-instance --storage-type gp3, which gives 3,000 baseline IOPS regardless of size. Move to provisioned IOPS only if gp3 limits are still exceeded.
Exercise
You want an instance that cannot run out of disk space unexpectedly but also does not waste money on unused storage. Which setting do you use, and which direction can you never change after the fact?
Show answer
Allocate a modest starting size and set --max-allocated-storage to enable storage autoscaling, so RDS grows the volume when free space is low. Allocated storage can only grow, never shrink, so an over-allocated volume can only be fixed by migrating to a new, smaller instance.