Sharing Data Securely Across Regions and Cloud Platforms

Global Snowflake utilizes database replication to allow data providers to securely share data with data consumers across different regions and cloud platforms. Cross region data sharing is supported for Snowflake accounts hosted on either the AWS or Azure cloud platform.

Important

If you are replicating a database to a geographic region or country that is different from that in which your source Snowflake account is located, you should confirm that your organization does not have any legal or regulatory restrictions as to where your data can be transferred or hosted.

In this Topic:

Data Sharing Considerations

Diagram of data replcation and sharing between regions and clouds

Sharing Data With Data Consumers in a Different Region and Cloud Platform

Snowflake data providers can share data with data consumers in a different region in a few simple steps.

Step 1: Set up Data Replication

Note

Before configuring data replication, you must create an account in a region where you wish to share data and link it to your local account. At this time, this requires assistance from Snowflake Support. Please contact Snowflake Support to link your accounts for replication.

Setting up data replication involves the following tasks:

  1. Promote an existing database in your local account as primary.

  2. Replicate your existing database to the other region.

For detailed instructions, see Replicating Databases Across Multiple Accounts.

Step 2. Share Data with Data Consumers

Sharing data with data consumer in the same region involves the following tasks:

  1. Create a share.

  2. Add objects to the share.

  3. Add one or more consumer accounts to the share.

For detailed instructions, see Getting Started with Secure Data Sharing.

Example 1

A data provider, Acme, wants to share data with data consumers in a different region.

Diagram of a basic example on how to share data between regions

Sample Code

use role sysadmin;

-- Promote an existing database in your local account as primary
alter database PrimaryDB enable replication to accounts AZURE_EASTUS2.AcmeProviderAccount2;

-- Replicate your existing database to another region
create database SecondaryDB
as replica of AWS_US_WEST_2.AcmeProviderAccount1.PrimaryDB;

-- Schedule refresh of the replica database
create procedure refresh_SecondaryDB_proc ()
  returns string
  language javascript
  AS $$
  var stmt = snowflake.createStatement(

  {sqlText:`alter database SecondaryDB refresh;`}
  );
  stmt.execute();
  $$;

create task refresh_SecondaryDB_task
  warehouse = mywh
  schedule = '10 minute'
as
  call refresh_SecondaryDB_proc();

alter task refresh_SecondaryDB_task resume;

-- Create a share
create share share1;

-- Add objects to the share
grant usage on database SecondaryDB to share share1;
grant usage on schema SecondaryDB.sch to share share1;

grant select on view SecondaryDB.sch.view1 to share share1;

-- Add one or more consumer accounts to the share
alter share share1 add accounts=ConsumerAccount;

Example 2

A data provider, Acme, wants to share a subset of data with data consumers in a different region. To reduce replication costs, they would like to only replicate the relevant rows from their master table. Since replication is done at the database level, this example describes how Acme can leverage Streams and Tasks to copy the desired rows from the main database to a new database and replicate the new database. In this scenario the new database is designated as a primary database for data replication.

Diagram of an advanced example on how to share data between regions

Sample Code

use role sysadmin;

-- In your local account, create a database with a subset of data
create database PrimaryDB;
create schema PrimaryDB.sch;
create table PrimaryDB.sch.tableB as select CUSTOMERID, USER_ORDER_COUNT, TOTAL_SPENT, TAGS from SourceDB.sch.tableA where REGION=’azure_eastus2’;
create secure view PrimaryDB.sch.view1 as select USER_ID, USER_ORDER_COUNT, TOTAL_SPENT, TAGS from PrimaryDB.sch.tableB;

-- Set up a stream to record changes made to the source table
create stream mystream on table tableA;

-- Set up a task to lift the changes from the source database and insert them to the PrimaryDB database
CREATE OR REPLACE TASK mytask1
  WAREHOUSE = mywh
  SCHEDULE = '5 minute'
WHEN
  SYSTEM$STREAM_HAS_DATA('mystream')
AS
  INSERT INTO tableB(CUSTOMERID, USER_ORDER_COUNT, TOTAL_SPENT, TAGS) select CUSTOMERID, USER_ORDER_COUNT, TOTAL_SPENT, TAGS FROM mystream WHERE METADATA$ACTION = 'INSERT';

-- Promote the new database as primary
alter database PrimaryDB enable replication to accounts AZURE_EASTUS2.AcmeProviderAccount2;

-- Replicate your existing database to another region
create database SecondaryDB
  as replica of AWS_US_WEST_2.AcmeProviderAccount1.PrimaryDB;

-- Schedule refresh of the replicated database
create procedure refresh_SecondaryDB_proc ()
  returns string
  language javascript
  AS $$
  var stmt = snowflake.createStatement(

  {sqlText:`alter database SecondaryDB refresh;`}
  );
  stmt.execute();
  $$;

create task refresh_SecondaryDB_task
  warehouse = mywh
  schedule = '10 minute'
as
  call refresh_SecondaryDB_proc();

alter task refresh_SecondaryDB_task resume;

-- Create a share
create share share1;

-- Add objects to the share:
grant usage on database SecondaryDB to share share1;
grant usage on schema SecondaryDB.sch to share share1;

grant select on view SecondaryDB.sch.view1 to share share1;

-- Add one or more consumer accounts to the share
alter share share1 add accounts=ConsumerAccount;