What is RDS right sizing, and who should do it?
RDS right sizing means choosing the smallest instance class that still covers your database's observed peak demand. For Postgres, "demand" has four parts: CPU, memory, I/O and connections. An instance that idles at low CPU can still be correctly sized if its working set barely fits in RAM or its connection count is close to the limit derived from instance memory. A downsize is justified only when all four show headroom at peak, not on average.
Treat it as a reversible change that you base on evidence. Changing the instance class on RDS is a modify operation, not a migration, so you can scale back up if the data shows you were wrong. Plan for the restart, the short outage or failover, and the time it takes for the buffer cache to warm up again.
Overprovisioning usually comes from one of three places:
- Launch sizing. Teams pick a large class before they have traffic data and never revisit it.
- Incident responses. Someone scales up during an outage, and the larger class stays after the real cause, often a bad query or a missing index, is fixed.
- Cautious defaults. Teams size for growth that never arrives.
Backend and platform engineers own this work. They need access to CloudWatch, Performance Insights and the DB parameter group, because memory-related settings like shared_buffers and max_connections often scale with instance memory and change along with the class.
Right sizing fits stable workloads with several months of metric history. That window should include month-end jobs, seasonal peaks and batch windows, and still show clear unused capacity. If the history is short or the workload is still changing quickly, collect more data before you change anything.
How does a smaller instance class change Postgres behavior?
Postgres doesn't care what an instance costs. It cares about how many processes can run at once, how much data stays in memory, and how fast pages arrive from storage. Changing the instance class changes all three.
vCPUs versus active sessions. In Performance Insights, average active sessions (AAS) is the number of backends doing work or waiting at a given moment. If CPU-bound AAS regularly exceeds the vCPU count of the target class, queries will queue for CPU. Compare peak AAS, not the daily average, against the smaller class's vCPUs. Check how much of that load is CPU wait versus I/O or lock waits.
Memory-derived defaults. RDS default parameter groups calculate several settings from DBInstanceClassMemory. shared_buffers defaults to roughly a quarter of instance memory, effective_cache_size to about half, and max_connections also scales with memory. Halving the class silently halves the cache and lowers the connection ceiling. A custom parameter group with hard-coded values has the opposite problem: settings sized for the old instance can exceed what the new one has.
EBS bandwidth. Provisioned IOPS and throughput belong to the volume, but each instance class has its own maximum EBS bandwidth. Smaller sizes often have only a burstable allowance. If the new class's limit is below your volume's throughput, the instance becomes the bottleneck even though storage is unchanged.
Burstable classes. T-family instances earn CPU credits while running below a baseline and spend them above it. Sustained load drains the credits. The instance then either throttles to baseline or, in unlimited mode, bills you for the surplus.
| Limit | Set by instance class | Set by storage |
|---|---|---|
| vCPUs / CPU credits | ✅ moves | — |
RAM → shared_buffers, effective_cache_size, max_connections |
✅ moves | — |
| Max EBS bandwidth and burst allowance | ✅ moves | — |
| Network bandwidth | ✅ moves | — |
| Provisioned IOPS and throughput | — | stays fixed |
| Allocated size, volume type | — | stays fixed |
+--------------------------------------------------------------------------+
| INSTANCE CLASS: everything in this box moves when the class changes |
| |
| +--------------+ +--------------------+ +--------------------------+ |
| | vCPUs | | RAM | | Max EBS bandwidth | |
| | | | DBInstanceClass- | | | |
| | T-class: | | Memory sets: | | small sizes: burstable | |
| | CPU credits | | shared_buffers | | allowance only | |
| | + baseline | | effective_cache_ | | | |
| | | | size | | | |
| | | | max_connections | | | |
| +--------------+ +--------------------+ +--------------------------+ |
| |
+--------------------------------------------------------------------------+
| | |
v v v
peak AAS vs cache hit ratio, caps volume IOPS and
vCPU count connection limit throughput below their
provisioned values
|
v
+--------------------------------------------------------------------------+
| STORAGE: unchanged when only the class changes |
| allocated size, provisioned IOPS, provisioned throughput |
| effective I/O = min(volume limits, instance EBS bandwidth) |
+--------------------------------------------------------------------------+
Resizing changes vCPUs and CPU credits, memory-derived parameter defaults, and the EBS bandwidth ceiling. Storage settings stay the same, but the instance's EBS bandwidth can still cap them.
Which CloudWatch and Performance Insights metrics prove you have headroom?
Pull at least 30 days of data, and longer if month-end closes or seasonal peaks fall outside that range. Judge on Maximum and p95/p99, not Average. A one-hour batch spike disappears into a daily mean, and that spike is the load the smaller class must survive. Use aws cloudwatch get-metric-statistics with --statistics Maximum or --extended-statistics p99 and a --period of 300 or less. Longer periods smooth out short bursts.
On the instance, check the current baseline with SHOW shared_buffers; and SHOW max_connections;. On RDS, both defaults scale with instance memory through the parameter group, so they will drop on a smaller class unless you set them explicitly. For cache hit ratio, compute sum(blks_hit) / sum(blks_hit + blks_read) from pg_stat_database.
| Resource | Metric | Headroom signal | Risk signal |
|---|---|---|---|
| CPU | CPUUtilization, Performance Insights DBLoad |
Peak CPU and peak DB load both fit within the target's vCPU count | DB load at peak already exceeds the target's vCPU count |
| Memory | FreeableMemory, SwapUsage |
Free memory at peak exceeds the RAM you are removing | Any sustained swap, or free memory near zero |
| Cache | Buffer cache hit ratio | Stays high while the hot working set fits in the target's RAM | Ratio falls during peaks, so reads are already going to disk |
| I/O | ReadIOPS, WriteIOPS, ReadLatency, WriteLatency, ReadThroughput, WriteThroughput, DiskQueueDepth |
Peak IOPS and throughput sit well under the target's EBS limits | Queue depth or latency climbs when throughput is at its peak |
| Connections | DatabaseConnections |
Peak count is far below the target's max_connections |
Peak count approaches the target's lower default max_connections |
#!/usr/bin/env bash
# Pull 30-day peaks for an RDS Postgres instance, then check the settings that shrink with the class.
set -euo pipefail
DB_ID="orders-prod-db" # placeholder instance identifier
DAYS=30
PERIOD=300 # 5-minute buckets keep short batch spikes visible
# get-metric-statistics returns at most 1,440 datapoints per call.
# At 300s that is 5 days, so query in 5-day windows and keep the extreme value.
# Usage: extreme <metric> <stat-flag> <stat> <query> <sort: max|min>
extreme() {
local metric=$1 flag=$2 stat=$3 query=$4 mode=$5
for ((d=DAYS; d>0; d-=5)); do
aws cloudwatch get-metric-statistics \
--namespace AWS/RDS --metric-name "$metric" \
--dimensions Name=DBInstanceIdentifier,Value="$DB_ID" \
--start-time "$(date -u -d "-${d} days" +%Y-%m-%dT%H:%M:%SZ)" \
--end-time "$(date -u -d "-$((d-5)) days" +%Y-%m-%dT%H:%M:%SZ)" \
--period "$PERIOD" "$flag" "$stat" \
--query "$query" --output text
done | tr '\t' '\n' | grep -v '^$' | sort -g | { [ "$mode" = max ] && tail -1 || head -1; }
}
echo "CPUUtilization max: $(extreme CPUUtilization --statistics Maximum 'Datapoints[].Maximum' max)"
echo "CPUUtilization p99: $(extreme CPUUtilization --extended-statistics p99 'Datapoints[].ExtendedStatistics.p99' max)"
echo "DBLoad max (vs vCPUs): $(extreme DBLoad --statistics Maximum 'Datapoints[].Maximum' max)"
echo "FreeableMemory min: $(extreme FreeableMemory --statistics Minimum 'Datapoints[].Minimum' min)"
echo "SwapUsage max: $(extreme SwapUsage --statistics Maximum 'Datapoints[].Maximum' max)"
echo "ReadIOPS max: $(extreme ReadIOPS --statistics Maximum 'Datapoints[].Maximum' max)"
echo "WriteIOPS max: $(extreme WriteIOPS --statistics Maximum 'Datapoints[].Maximum' max)"
echo "DiskQueueDepth max: $(extreme DiskQueueDepth --statistics Maximum 'Datapoints[].Maximum' max)"
echo "DatabaseConnections max: $(extreme DatabaseConnections --statistics Maximum 'Datapoints[].Maximum' max)"
# Current baselines; on RDS both default to formulas based on instance memory.
psql "host=orders-prod-db.example.internal dbname=postgres user=readonly_admin" <<'SQL'
SHOW shared_buffers;
SHOW max_connections;
SELECT round(sum(blks_hit)::numeric / nullif(sum(blks_hit + blks_read), 0), 4) AS cache_hit_ratio
FROM pg_stat_database;
SQL
A shell script that gets 30-day peak and p99 values from CloudWatch at 5-minute resolution, querying in 5-day windows to stay under the 1,440-datapoint limit per call, and then reads shared_buffers, max_connections and the buffer cache hit ratio from Postgres.
When should you avoid downsizing an RDS instance?
Treat each condition below as a blocker until you've investigated it. Any one of them can turn a cost saving into an incident.
-
Your metric window misses rare peaks. Two weeks of CloudWatch data won't show quarter-end reporting, annual backfills, or the catch-up load after an outage, when queues drain all at once. Check at least one full business cycle. Ask the teams that own scheduled jobs what runs only occasionally. A smaller instance class leaves less margin for exactly these events.
-
DB load is already near the vCPU line. If Performance Insights shows average active sessions approaching or crossing the Max vCPU line at peak, sessions are already queuing for CPU. Halving vCPUs makes that queue longer, and latency rises faster than load does.
-
The working set won't fit in the smaller cache. Less memory means a smaller
shared_buffersand OS page cache. If hot tables and indexes stop fitting, reads go to storage, and IOPS and latency climb. This hurts most right after a failover or reboot, when the cache starts cold. -
The target is burstable and the load is sustained. Burstable classes depend on CPU credits. Under steady load you either run out of credits and get throttled, or you pay for surplus credits, which can cancel the savings.
-
Replicas would end up sized inconsistently. In a Multi-AZ instance deployment, the standby gets the same class as the primary automatically. Read replicas are sized separately. A replica smaller than its primary can fall behind during heavy write periods. A replica you plan to promote also needs enough capacity to take over the full workload.
-
Connection counts are hard-coded. On RDS, the default
max_connectionsis derived from instance memory, so it drops on a smaller class. Application pools or poolers configured with fixed sizes can exceed the new limit and start getting connection errors.
Is the instance actually busy, or is it wasting capacity on bad queries?
Performance Insights shows database load as average active sessions, broken down by wait event. Compare that load to the vCPU line before reading CPUUtilization as demand, because the wait mix tells you what kind of busy you have:
- CPU dominant, with top SQL spread across many statements: likely real demand.
- IO:DataFileRead concentrated in a few statements: often sequential scans or missing indexes pulling data that a smaller cache would make worse.
- Lock:transactionid or Lock:tuple: sessions waiting on each other. More vCPUs won't help.
- Client:ClientRead with many short calls: chatty application round trips, not database work.
Check these patterns directly. In pg_stat_statements, sort by total execution time and look at calls, rows and the ratio of shared_blks_read to shared_blks_hit. A single query with millions of calls, or high block reads per returned row, points to an N+1 pattern or a missing index. In pg_stat_activity, group by state, wait_event_type and wait_event. Large counts of idle in transaction sessions hold locks and connections without doing useful work.
If one or two statements account for most of the load, fix them first and re-measure over a full business cycle. The instance may then be oversized by a wider margin than it first appeared. Tuning has costs of its own. It takes engineering time to find, test and deploy each fix, and the gains erode as new features add queries and data volumes grow. Treat the fixes as a baseline you will need to recheck, not a permanent saving, and size the instance with that drift in mind.
-- 1. Top statements by total execution time (PG 13+ column names).
-- Few rows dominating total time = tuning target, not capacity demand.
SELECT
left(query, 60) AS query_start,
calls,
round(total_exec_time::numeric / 1000, 1) AS total_sec,
round(mean_exec_time::numeric, 2) AS mean_ms,
rows,
-- High block reads per returned row suggests a missing index or seq scan
round(shared_blks_read::numeric / nullif(rows, 0), 1) AS blks_read_per_row,
-- Low hit ratio means the query depends on disk; a smaller cache hurts more
round(100.0 * shared_blks_hit
/ nullif(shared_blks_hit + shared_blks_read, 0), 1) AS hit_pct
FROM pg_stat_statements
ORDER BY total_exec_time DESC
LIMIT 10;
-- 2. What sessions are doing right now; compare with the PI wait mix.
SELECT state, wait_event_type, wait_event, count(*) AS sessions
FROM pg_stat_activity
WHERE backend_type = 'client backend'
GROUP BY state, wait_event_type, wait_event
ORDER BY sessions DESC;
-- 3. Long-lived 'idle in transaction' sessions hold locks and connections.
SELECT pid, usename, application_name,
now() - xact_start AS xact_age,
left(query, 60) AS last_query
FROM pg_stat_activity
WHERE state = 'idle in transaction'
ORDER BY xact_start
LIMIT 20;
Queries against pg_stat_statements and pg_stat_activity that confirm whether Performance Insights load comes from a few inefficient statements, lock waits or idle-in-transaction sessions.
How do you downsize safely and roll back if it goes wrong?
- Agree the rollback threshold first. Write down the numbers that trigger a revert, such as p95/p99 query latency, application error rate, DB load relative to vCPU count, and any sustained swap usage. Set them before the change so a bad result leads to a revert instead of a debate.
- Check replicas and Multi-AZ. A read replica sized smaller than its primary can fall behind on replay. A Multi-AZ standby always matches the primary's class, so it shrinks too.
- Pin derived parameters. RDS calculates defaults like
max_connectionsandshared_buffersfrom instance memory, so both drop on a smaller class. If your connection pool relies on the current limit, setmax_connectionsexplicitly in the parameter group before you resize. - Step down one size at a time. Use
aws rds modify-db-instancewith--db-instance-class. Add--apply-immediatelyto run the change now, during a low-traffic period you choose. Without it, the change is deferred to the next maintenance window. Either way, expect a brief interruption. Single-AZ instances restart, and Multi-AZ instances modify the standby and then fail over. - Plan for rollback cost. Reverting is another modify call and another interruption. Keep the team on hand until you are confident in the result.
- Compare against the baseline for a full cycle. A failover starts with a cold buffer cache and a cold OS page cache. The first hours run slower than steady state, and a short test can mislead in either direction. Compare the same metrics, plus application latency and error rates, across at least one full daily or weekly cycle, including batch jobs and peak traffic.
#!/usr/bin/env bash
set -euo pipefail
DB=orders-prod-pg # placeholder instance identifier
PG=orders-prod-pg16-params # custom parameter group (defaults cannot be edited)
CURRENT=db.r6g.2xlarge
TARGET=db.r6g.xlarge # one size down, not two
# 1. Record the starting state so a rollback has a known target.
aws rds describe-db-instances --db-instance-identifier "$DB" \
--query 'DBInstances[0].[DBInstanceClass,MultiAZ,DBParameterGroups[0].DBParameterGroupName]' \
--output text
# 2. Pin max_connections so it no longer derives from (smaller) instance memory.
# It is a static parameter, so it applies on the next restart.
aws rds modify-db-parameter-group --db-parameter-group-name "$PG" \
--parameters "ParameterName=max_connections,ParameterValue=400,ApplyMethod=pending-reboot"
# 3a. Resize now, in a low-traffic window you have chosen and staffed.
aws rds modify-db-instance --db-instance-identifier "$DB" \
--db-instance-class "$TARGET" --apply-immediately
# 3b. Or defer to the next maintenance window by omitting --apply-immediately:
# aws rds modify-db-instance --db-instance-identifier "$DB" --db-instance-class "$TARGET"
# Expect a restart (Single-AZ) or a failover (Multi-AZ) during the change.
aws rds wait db-instance-available --db-instance-identifier "$DB"
# 4. Confirm the parameter took effect; restart manually if it is still pending.
# psql "host=... dbname=app" -c 'SHOW max_connections;'
# 5. Rollback if an agreed threshold is breached. This is another
# modify call and another brief interruption.
# aws rds modify-db-instance --db-instance-identifier "$DB" \
# --db-instance-class "$CURRENT" --apply-immediately
A one-step RDS for PostgreSQL downsize that records the current class, pins max_connections, and applies the resize either immediately or in the maintenance window, then waits for availability and keeps the rollback command ready.
What are the alternatives to downsizing, and how do they affect cost?
Downsizing is one option among several, and the others can be cheaper or safer depending on what the metrics showed.
| Option | Effort | Risk | Reversibility | Cost impact |
|---|---|---|---|---|
| Query and index tuning | Medium | Low | High | Indirect; often what makes a smaller class viable |
| Connection pooling | Low–medium | Low | High | Lowers per-connection memory, may permit a smaller class |
| Read replicas | Medium | Medium (replica lag) | High | Adds instances; saves only if the primary then shrinks |
| Burstable class | Low | High for sustained load | High | Lower base price; credit exhaustion throttles CPU or adds surplus charges |
| Different instance family | Low–medium | Medium (new CPU architecture or memory ratio) | High | Can lower price per vCPU or per GiB |
| Leave as is | None | None | n/a | Keeps paying for idle headroom |
Illustrative estimate (assumed numbers, not a benchmark). Assume the current class costs $1.00/hour and the next size down costs $0.50/hour. You run 3 instances, all Multi-AZ, so each costs twice the single-AZ price. A month is 730 hours.
Monthly savings = (current price − new price) × Multi-AZ factor × instance count × 730 = (1.00 − 0.50) × 2 × 3 × 730 = $2,190/month
Engineering cost = hours × loaded rate. At an assumed 24 hours for analysis, change and observation, and $100/hour, that is $2,400, so the change pays for itself in about 1.1 months.
The second review costs less. If you reuse the same metric checklist and agree on rollback thresholds before the change, such as p95 latency or sustained CPU above an agreed level, you skip the debate about what counts as failure. With an assumed 6 hours, the engineering cost drops to $600, and smaller savings become worth pursuing.
How OneEnv can help
Disclosure: OneEnv is the product behind this blog.
OneEnv (oneenv.io) is a workspace-based governance platform for the things services share — environment variables, database structure, API routes and validation rules. A change to a shared value is staged on a branch, reviewed once, and then every affected service explicitly approves or rejects it before it goes live, so you can see who a change touches before it ships instead of finding out in production.
Applied to rds right sizing, this is where it helps:
Saves time
- Every service that inherits a shared value is listed in one place, so nobody searches repos and chats to find out who is affected.
- One review per branch replaces coordinating each team separately; each service still keeps its own approve/reject.
- Adding or removing a column goes through one review with the inheriting services listed, instead of ad-hoc messages to each team.
Saves cost
- Fewer production incidents and rollbacks caused by a shared value, route or column changing under a consumer unannounced.
- Less duplicated configuration to maintain: one shared definition inherited by many services.
- Services that depend on a column get the chance to object before it disappears, avoiding emergency fixes.
- OneEnv has a free plan (1 workspace, unlimited services and members, full governance), so trying it costs nothing.
These are qualitative benefits, not measured results — how much you save depends on how many services share the value.
Want to try it? Start at oneenv.io.