Issue
You are wondering how to minimize downtime during a maintenance.
Resolution
Make your app resilient to connection errors
Failover for a maintenance event often occurs quickly, but apps can have problems reestablishing connections, which leads to additional downtime. If this is an issue, you can proactively restart your app after maintenance on your database is complete to guard against connection-specific errors. You can also build that resiliency into the error handling of the app itself with an exponential back-off when reestablishing connections.
Use a read-only follower
You can provision a database follower to provide read-only access to your database. Your app must support a read-only
mode and be configured so that it only requires access to the follower. Depending on the use case, this can enable the app to continue to run in a degraded, read-only mode when maintenance occurs on the main database.
Verify that your database is ready before running migrations
If your app has migrations that run on boot, first confirm that you have a read-write connection to the database, and then run migrations. If you attempt to run migrations with a read-only connection, your app can crash, resulting in more downtime as it recovers.
You can verify that the app is out of read-only mode with this SQL command: SELECT pg_is_in_recovery()
.