How do I minimize downtime during a Heroku Postgres maintenance?

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().

Ask on Stack Overflow

Engage with a community of passionate experts to get the answers you need

Ask on Stack Overflow

Heroku Support

Create a support ticket and our support experts will get back to you

Contact Heroku Support