Failing Over Databases Across Multiple Accounts

This topic describes the steps necessary to fail over your replicated databases across multiple accounts in different regions for disaster recovery.

Note

Only account administrators (users with the ACCOUNTADMIN role) can enable and manage failover for a database.

In this Topic:

Prerequisite Requirements

  1. Enable replication for a primary database in a set of accounts.

  2. Create at least one secondary database (i.e. replica) of the primary database in one or more of the accounts specified in Step 1, and regularly refresh (i.e. synchronize) the replica with the latest updates to the primary database.

For instructions, see Replicating Databases Across Multiple Accounts.

Step 1: Viewing All Accounts in Your Organization

Retrieve the list of accounts in your organization to determine which accounts have been linked for database replication and failover.

To view the list of accounts in your organization, query SHOW GLOBAL ACCOUNTS.

SHOW GLOBAL ACCOUNTS;

+------------------+---------------------------------+---------------+------------+
| snowflake_region | created_on                      | name          | comment    |
|------------------+---------------------------------+---------------+------------|
| AWS_US_WEST_2    | 2018-11-19 16:11:12.720 -0700   | MYACCOUNT1    |            |
| AWS_US_EAST_1    | 2019-06-02 14:12:23.192 -0700   | MYACCOUNT2    |            |
+------------------+---------------------------------+---------------+------------+

The following table displays the complete list of Snowflake Region IDs:

Snowflake Region IDs

Region

Region ID

Snowflake Region ID

Notes

Amazon Web Services (AWS)

US West (Oregon)

us-west-2

aws_us_west_2

US East (N. Virginia)

us-east-1

aws_us_east_1

Canada (Central)

ca-central-1

aws_ca_central_1

EU (Ireland)

eu-west-1

aws_eu_west_1

EU (Frankfurt)

eu-central-1

aws_eu_central_1

Asia Pacific (Singapore)

ap-southeast-1

aws_ap_southeast_1

Asia Pacific (Sydney)

ap-southeast-2

aws_ap_southeast_2

Microsoft Azure

East US 2

east-us-2.azure

azure_eastus2

Canada Central

canada-central.azure

azure_canadacentral

West Europe

west-europe.azure

azure_westeurope

Australia East

australia-east.azure

azure_australiaeast

Southeast Asia

southeast-asia.azure

azure_southeastasia

Step 2: Enabling Failover for a Primary Database

Enable failover for a primary database to one or more accounts in your organization using an ALTER DATABASE … ENABLE FAILOVER TO ACCOUNTS statement. The replica of this primary database in any one of these accounts (i.e. a secondary database) can be promoted to serve as the primary database.

Note that enabling failover for a primary database can be done either before or after a replica of the primary database has been created in a specified account.

Example

Enable failover for primary database mydb1 (in region aws_us_west_2) to accounts myaccount2 and myaccount3 (in regions aws_us_east_1 (AWS) and azure_westeurope (Azure), respectively). In this example, suppose the primary database is stored in the myaccount1 account. The ALTER DATABASE command must be executed in that account:

ALTER DATABASE mydb1 ENABLE FAILOVER TO ACCOUNTS aws_us_east_1.myaccount2, azure_westeurope.myaccount3;

Step 3: Promoting a Replica Database to Serve as the Primary Database

Any replica of a primary database can be promoted to serve as the primary database by executing an ALTER DATABASE … PRIMARY statement. When promoted, the database becomes writeable. At the same time, the previous primary database becomes a read-only replica database.

Execute the ALTER DATABASE statement in the account containing the secondary database that you are promoting.

Note

To promote a secondary database, the role used to perform the operation must have the OWNERSHIP privilege on the database.

Example

-- Promote a secondary database to serve as the primary database.
ALTER DATABASE mydb1 PRIMARY;

-- Verify that the former secondary database was promoted successfully.
SHOW DATABASES;