Sub topic 13
Maintenance windows and engine upgrades
This chapter assumes you can already create and modify a DB instance with the AWS CLI. It also assumes you know what a parameter group is and how Multi-AZ failover behaves. It covers how RDS schedules patching, how minor and major engine upgrades differ, and how to upgrade with the least risk.
What the maintenance window controls
RDS patches the operating system and the database engine for you. It applies most of those changes inside the preferred maintenance window, a weekly time slot in UTC. The format is ddd:hh24:mi-ddd:hh24:mi, and the slot must be at least 30 minutes long.
If you don't choose a window, RDS assigns a random 30-minute slot from an 8-hour block for the Region. Set your own so patching doesn't land in the middle of a business-hours peak.
aws rds modify-db-instance \
--db-instance-identifier demo-pg \
--preferred-maintenance-window "sun:04:00-sun:04:30"Keep the maintenance window apart from the backup window. Backups and patching both put load on the instance, and a patch that runs during a backup can be delayed or can slow the backup down.
Not every change waits for the window. Three kinds of change are handled differently:
- Maintenance actions that AWS initiates, such as OS patches, certificate updates, and minor engine upgrades. These run in the window.
- Modifications you request, such as a new instance class. These run in the next window unless you pass
--apply-immediately. - Static parameter changes. These only take effect after a reboot, whether the reboot comes from you or from maintenance. Chapter "Tuning with parameter groups" covers the dynamic and static distinction.
Pending maintenance actions
When RDS has work queued for an instance, it lists it as a pending maintenance action. Check the list regularly, because it tells you what the next window will do.
aws rds describe-pending-maintenance-actions \
--filters Name=db-instance-id,Values=demo-pgEach entry has these fields:
| Field | Meaning |
|---|---|
| `Action` | The type of work, for example `system-update` or `db-upgrade` |
| `AutoAppliedAfterDate` | RDS may apply the action in any maintenance window after this date |
| `ForcedApplyDate` | The deadline. RDS applies the action then, even if you have opted out |
| `CurrentApplyDate` | When the action is currently scheduled to run |
| `OptInStatus` | Whether you have asked for it now, for the next window, or not at all |
You can bring an action forward or push it to the next window with apply-pending-maintenance-action. The --opt-in-type value can be immediate, next-maintenance, or undo-opt-in.
aws rds apply-pending-maintenance-action \
--resource-identifier arn:aws:rds:us-east-1:111122223333:db:demo-pg \
--apply-action system-update \
--opt-in-type next-maintenanceThe same check works from a script, for example in a weekly report:
import boto3
rds = boto3.client("rds")
response = rds.describe_pending_maintenance_actions(
Filters=[{"Name": "db-instance-id", "Values": ["demo-pg"]}]
)
for resource in response["PendingMaintenanceActions"]:
for detail in resource["PendingMaintenanceActionDetails"]:
print(
resource["ResourceIdentifier"],
detail["Action"],
detail.get("AutoAppliedAfterDate"),
detail.get("ForcedApplyDate"),
)An empty list means nothing is queued.
What patching does to availability
On a single-AZ instance, a patch that needs a restart takes the database offline for the duration of the restart. The outage is usually a few minutes, but it depends on the engine and on recovery time after the restart.
On a Multi-AZ instance deployment, OS patching is gentler. RDS patches the standby, fails over to it, and then patches the former primary. Applications see roughly one failover, typically 60 to 120 seconds, and they must reconnect. Engine upgrades are more disruptive than OS patches, so plan for an outage during them even with Multi-AZ. Test the behavior with your engine and version before you rely on it.
Connection pooling helps here. Applications with retry logic, or a proxy in front of the database, recover from the restart faster than applications that hold connections open indefinitely.
Minor versus major engine upgrades
An engine version has a major part and a minor part. For PostgreSQL 16.4, the major version is 16 and the minor is 4. (PostgreSQL 10 and later use a single number for the minor.) MySQL uses forms like 8.0.36.
| Row | Minor upgrade | Major upgrade |
|---|---|---|
| Example | 16.4 to 16.6 | 15 to 16 |
| Content | Bug fixes and security patches | New features, changed behavior |
| Compatibility | Designed to be backward compatible | Can break queries, extensions, and apps |
| Automatic | Yes, if `auto-minor-version-upgrade` is on | Never |
| Flag required | None | `--allow-major-version-upgrade` |
| Parameter group | Same family | Must move to the new family |
Minor upgrades
The AutoMinorVersionUpgrade setting lets RDS apply minor versions in the maintenance window. It is on by default. Leave it on for most workloads, because skipped minor versions are how instances end up on unpatched engines. Turn it off only if you validate each minor version in a test environment first. In that case, you take on the job of upgrading before the version reaches end of support.
aws rds modify-db-instance \
--db-instance-identifier demo-pg \
--no-auto-minor-version-upgradeTo upgrade by hand, first list the valid targets for your current version. Not every version can upgrade directly to every other.
aws rds describe-db-engine-versions \
--engine postgres \
--engine-version 16.4 \
--query "DBEngineVersions[].ValidUpgradeTarget[].[EngineVersion,IsMajorVersionUpgrade]" \
--output tableThen request the version. Without --apply-immediately, the change waits for the maintenance window.
aws rds modify-db-instance \
--db-instance-identifier demo-pg \
--engine-version 16.6 \
--apply-immediatelyThe versions above are examples. Use values returned by the previous command, because available versions change.
Major upgrades
A major upgrade changes the on-disk format, the query planner, and sometimes the defaults. Treat it as a project, not a maintenance task.
- Read the engine's release notes for removed features and changed defaults.
- Check your extensions, drivers, and ORM versions against the target version.
- Create a custom parameter group in the target family, such as
postgres17, and copy over your settings. A group from the old family cannot be used with the new engine. - Restore a recent snapshot to a test instance and upgrade that first. Time it and run your application's test suite against it.
- Upgrade production, starting with a manual snapshot.
RDS takes a pre-upgrade snapshot when automated backups are on, but a manual snapshot you name yourself is easier to find if you need to roll back.
If the instance has read replicas, the order matters. For some engines RDS upgrades replicas along with the source. For others you upgrade the replicas yourself. Check the engine's upgrade documentation before you start.
Upgrading with Blue/Green deployments
A Blue/Green deployment builds a staging copy of your production instance, the green environment. RDS keeps it in sync with production, the blue environment, through replication. You upgrade the green side, test it, and then switch over. This moves the risky work off the production instance, and the switchover usually takes under a minute.
aws rds create-blue-green-deployment \
--blue-green-deployment-name demo-pg-upgrade \
--source arn:aws:rds:us-east-1:111122223333:db:demo-pg \
--target-engine-version 17.2 \
--target-db-parameter-group-name demo-pg17Once the green environment is available and your tests pass, switch over:
aws rds switchover-blue-green-deployment \
--blue-green-deployment-identifier bgd-0123456789abcdef \
--switchover-timeout 300RDS renames the instances so that your existing endpoint now points to the green environment. The old blue instance stays until you delete it, which gives you a reference copy.
Some limits apply:
- You pay for the green environment from creation until you delete it.
- Some engine, version, and configuration combinations are not supported. Check the current documentation.
- Writes to the green side before switchover can break replication, so keep it read-only.
- Logical replication slots and some extensions need extra care.
Engine end of support
Every engine version has an end-of-support date. After that date, RDS may enroll the instance in Extended Support, which charges an hourly fee per vCPU, or it may force an upgrade. Look up the dates for your engine and put them on a calendar well before they arrive. Extended Support is a way to buy time for a migration, not a place to stay.
Common mistakes
- Leaving the default window. The random slot can fall in your busiest hour. Set it explicitly.
- Ignoring pending actions. A
ForcedApplyDateturns an optional patch into a scheduled outage you did not plan. - Forgetting the parameter group family. A major upgrade fails or falls back to defaults if the target family has no matching custom group.
- Testing only on an empty database. Upgrade time and planner behavior depend on data size and statistics. Restore real data.
- Skipping post-upgrade steps. PostgreSQL major upgrades need fresh planner statistics, so run
ANALYZEafterward. Update extensions withALTER EXTENSION ... UPDATE.
Exercise
An instance runs PostgreSQL 15 with a custom parameter group in the postgres15 family. You want to move to PostgreSQL 16 with under a minute of downtime. Which steps do you take, and why can't you just run modify-db-instance --engine-version 16.x?
Show answer
A major upgrade needs --allow-major-version-upgrade, and the instance must use a parameter group from the postgres16 family, so you first create a custom postgres16 group and copy your settings into it. To keep downtime short, create a Blue/Green deployment with the target version and the new parameter group, test the green environment, then run switchover-blue-green-deployment. An in-place upgrade would take the instance offline for the whole upgrade, and the only rollback would be a snapshot restore.
Exercise
describe-pending-maintenance-actions shows a system-update with a ForcedApplyDate three days away. Your next maintenance window is after that date. What can you do?
Show answer
Apply it earlier with apply-pending-maintenance-action --opt-in-type immediate at a quiet time, or change the preferred maintenance window with modify-db-instance so a window falls before the forced date. Do not wait, because RDS applies the action on the forced date whether or not it suits you.