Amazon DocumentDB Failover

    For failover to function, your cluster must have at least two instances — a primary and at least one replica instance.

    Amazon DocumentDB provides you with failover tiers as a means to control which replica instance is promoted to primary when a failover occurs.

    Failover Tiers

    Each replica instance is associated with a failover tier (0–15). When a failover occurs due to maintenance or an unlikely hardware failure, the primary instance fails over to a replica with the lowest numbered priority tier. If multiple replicas have the same priority tier, the primary fails over to that tier’s replica that is the closest in size to the primary.

    By setting the failover tier for a group of select replicas to (the highest priority), you can ensure that a failover will promote one of the replicas in that group. You can effectively prevent specific replicas from being promoted to primary in case of a failover by assigning a low-priority tier (high number) to these replicas. This is useful in cases where specific replicas are receiving heavy use by an application and failing over to one of them would negatively impact a critical application.

    You can set the failover tier of an instance when you create it or later by modifying it. Setting an instance failover tier by modifying the instance does not trigger a failover. For more information see the following topics:

    --target-db-instance-identifier

    For testing, you can force a failover event using the failover-db-cluster operation. You can use the parameter to specify which replica to promote to primary. Using the --target-db-instance-identifier parameter supersedes the failover priority tier. If you do not specify the --target-db-instance-identifier parameter, the primary failover is in accordance with the failover priority tier.

    Failover is automatically handled by Amazon DocumentDB so that your applications can resume database operations as quickly as possible without administrative intervention.

    • If you don’t have an Amazon DocumentDB replica instance (for example, a single instance cluster): Amazon DocumentDB will attempt to create a new instance in the same Availability Zone as the original instance. This replacement of the original instance is done on a best-effort basis and may not succeed if, for example, there is an issue that is broadly affecting the Availability Zone.

    Your application should retry database connections in the event of a connection loss.

    A failover for a cluster promotes one of the Amazon DocumentDB replicas (read-only instances) in the cluster to be the primary instance (the cluster writer).

    When the primary instance fails, Amazon DocumentDB automatically fails over to an Amazon DocumentDB replica, if one exists. You can force a failover when you want to simulate a failure of a primary instance for testing. Each instance in a cluster has its own endpoint address. Therefore, you need to clean up and re-establish any existing connections that use those endpoint addresses when the failover is complete.

    • —Required. The name of the cluster to fail over.

    The following operation forces a failover of the sample-cluster cluster. It does not specify which instance to make the new primary instance, so Amazon DocumentDB chooses the instance according to failover tier priority.

    For Linux, macOS, or Unix:

    For Windows:

    The following operation forces a failover of the sample-cluster cluster, specifying that is to be promoted to the primary role. (Notice "IsClusterWriter": true in the output.)

    For Linux, macOS, or Unix:

    For Windows: