# Manage Maintenance Windows

Maintenance windows are used to perform necessary updates
and upgrades regarding security and management layers of your
Exoscale DBaaS services. They are not used to perform major
service version upgrades, refer to the section [upgrades](#upgrades)
on how to upgrade versions.

> [!NOTE]
Urgent upgrades including vulnerability updates will happen before the maintenance window 
in order to keep the services safe.


By default, an arbitrary slot will be assigned when creating
your service. You can control the weekly maintenance window of
each service to ensure maintenance occurs during a window with lower traffic levels.

### Changing the Maintenance Window of a Service

To adapt the maintenance window of a service, you need to pass
a new day of week and associated time with the `update` command

```bash
exo dbaas update -z de-fra-1 test-pg --maintenance-dow=tuesday --maintenance-time=10:10:10
```

```bash
Updating Database Service "test-pg"...
┼───────────────────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼
│   DATABASE SERVICE    │                                                                                                                                │
┼───────────────────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼
│ Zone                  │ de-fra-1                                                                                                                       │
│ Name                  │ test-pg                                                                                                                        │
│ Type                  │ pg                                                                                                                             │
│ Plan                  │ hobbyist-1                                                                                                                     │
│ Disk Size             │ 8.0 GiB                                                                                                                        │
│ State                 │ running                                                                                                                        │
│ Creation Date         │ 2021-10-21 08:42:40 +0000 UTC                                                                                                  │
│ Update Date           │ 2021-11-01 09:25:27 +0000 UTC                                                                                                  │
│ Nodes                 │ 1                                                                                                                              │
│ Node CPUs             │ 2                                                                                                                              │
│ Node Memory           │ 2.0 GiB                                                                                                                        │
│ Termination Protected │ true                                                                                                                           │
│ Maintenance           │ tuesday (10:10:10)                                                                                                             │
│ Backup Schedule       │ 20:28                                                                                                                          │
│ URI                   │ postgres://avnadmin:xxxxx@test-pg-exoscale-08b0165e-ef03-47ec-926f-f01163d557ed.aivencloud.com:21699/defaultdb?sslmode=require │
│ IP Filter             │ 0.0.0.0/0                                                                                                                      │
│ Components            │                                                                                                                                │
│                       │   pg          test-pg-exoscale-08b0165e-ef03-47ec-926f-f01163d557ed.aivencloud.com:21699   route:dynamic   usage:primary       │
│                       │   pgbouncer   test-pg-exoscale-08b0165e-ef03-47ec-926f-f01163d557ed.aivencloud.com:21700   route:dynamic   usage:primary       │
│                       │                                                                                                                                │
│ Users                 │ avnadmin (primary)                                                                                                             │
┼───────────────────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼
```

The maintenance window can also be specified at creation time
with the same parameters.

This parameter can also be checked and adjusted within the Portal
under the `maintenance` tab of a service. The same tab also lists
the upcoming updates to be applied at the next scheduled maintenance
or manually within the page.

### How Maintenance and Upgrades Work

Upgrades are performed as rolling upgrades where completely
new instances are built alongside the old ones. After
the new instances are running and synced with the
old instances, a controlled automatic failover is performed
to switch the service to use the new upgraded instances.
The old servers are retired automatically after the new
instances have taken over for providing the service.

The controlled failover is very quick and safe - it takes
less than a minute to get clients connected
again. Typically, we see a 5-10 second period during which
the clients are unable to re-establish the connection.
Single node plans will however see a longer downtime.

Best practices for client configuration:

- Do not cache IP addresses of services.
- Make sure your client can automatically reconnect
  to a service.
- Make sure the DNS name of a service stays the same after the
  upgrade.
