# Set the maintenance window

Choose when minor upgrades and OS patch reboots happen, and whether minor upgrades are applied automatically.

The window is `ddd:hh24:mi-ddd:hh24:mi` in UTC, between one hour and one day long,
`sun:05:00-sun:06:00` by default. Replace _ewdb-0123456789ab_ with your database's id.

## Prerequisites

- Permission for `rds:ModifyDBInstance`.
- In the console, also `rds:DescribeDBInstances` to open the database's page (without it the page is
  not found).

## Set the window

**Console**
1. Open the database, then choose **Maintenance**.
2. Under **Maintenance window**, choose the start and end.
3. Choose **Save window**. The section shows when the window next opens.
4. (Optional) Select or clear **Apply new minor versions automatically in the window**. The
   change is saved as soon as you select or clear the check box.

**CLI**
```sh
dcloud rds instances modify-maintenance ewdb-0123456789ab \
  --maintenance-window tue:02:00-tue:03:00 --auto-minor-version-upgrade
```

Use `--no-auto-minor-version-upgrade` to turn automatic minor upgrades off.

**API**
```http
PATCH /rds/api/instances/ewdb-0123456789ab/maintenance
{ "maintenanceWindow": "tue:02:00-tue:03:00", "autoMinorVersionUpgrade": true }
```

**Terraform:** not available. The maintenance window is not an argument of `dcloud_db_instance`.

## Result

With `autoMinorVersionUpgrade` on (the default), a pending minor is applied in the next window. An
upgrade starts only with enough of the window left to finish, and a running one is never cut off.
With it off, upgrades happen only when you ask. A new database is left alone for its first day: its
first window is the first one that opens a day after it was created.

The window also takes OS patch reboots, one node at a time; see
[Versions and maintenance](versions-and-maintenance.md). `rds.instances.describe-maintenance`
returns the versions per node, the pending minor, the window and when it next opens.

## Related

- [Upgrade the minor version](upgrade-the-minor-version.md)
- `rds.instances.modify-maintenance` · `dcloud rds instances modify-maintenance`
