地域とクラウドプラットフォーム間で安全にデータを共有する

このトピックでは、 データベース複製 を使用して、データプロバイダーが異なる リージョン およびクラウドプラットフォーム間でデータコンシューマーとデータを安全に共有するための手順を提供します。データベース複製は、アカウント複製の一部になりました。アカウント複製を使用した共有複製の手順については、 リージョン間およびクラウドプラットフォーム間での共有の複製 をご参照ください。

注釈

特定のコンシューマーに提供されるリストを使用して、または Snowflake Marketplace で、他のアカウントとデータを共有する場合は、 クロスクラウド自動複製 を使用してデータ製品を他のリージョンで自動的に提供することができます。データ交換で共有されているリストでは、自動複製はサポートされていません。

クロスリージョンのデータ共有は、次のクラウドプラットフォームのいずれかでホストされているSnowflakeアカウントでサポートされています。

  • Amazon Web Services(AWS)

  • Google Cloud Platform

  • Microsoft Azure

重要

元となるSnowflakeアカウントとは異なる地理的リージョンまたは国にプライマリデータベースを複製する場合は、データの転送またはホストに関する法的または規制上の制限がないことを確認する必要があります。

このトピックの内容:

データ共有に関する考慮事項

Diagram of data replication and sharing between regions and clouds

異なる地域およびクラウドプラットフォームのデータコンシューマーとのデータ共有

Snowflakeデータプロバイダーは、いくつかの簡単な手順で、異なる地域のデータコンシューマーとデータを共有できます。

ステップ1: データ複製を設定する

注釈

データ複製を構成する前に、データを共有するリージョンにアカウントを作成し、ローカルアカウントにリンクする必要があります。詳細については、 組織およびアカウントの使用 をご参照ください。

データ複製の設定には、次のタスクが含まれます。

  1. アカウントの1つにORGADMINロールを作成し、アカウントをレプリケーション用にリンクします。詳細については、 組織を使い始める をご参照ください。

  2. ローカルアカウントの既存のデータベースをプライマリとして昇格します。

  3. 既存のデータベースを他の地域に複製します。

詳細な手順については、 複数のアカウント間でのデータベースの複製 をご参照ください。

ステップ2:データコンシューマーとデータを共有する

同じ地域のデータコンシューマーとデータを共有するには、次のタスクが必要です。

  1. 共有の作成。

  2. 共有にオブジェクトを追加します。

  3. 1つ以上のコンシューマーアカウントを共有に追加します。

詳細な手順については、 安全なデータ共有の開始 をご参照ください。

例1

データプロバイダーのAcmeは、異なる地域のデータコンシューマーとのデータ共有を望んでいます。

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

ソースアカウントからの実行

次の SQL コマンドを実行して、プライマリデータベースの複製を有効にします。

use role accountadmin;

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

ターゲットアカウントからの実行

他のリージョンのターゲットアカウントから次の SQL コマンドを実行します。

use role accountadmin;

-- Replicate the existing database to a secondary database in the other region
create database SecondaryDB
as replica of AWS_US_WEST_2.AcmeProviderAccount1.PrimaryDB;

-- Create a database for stored procedures
create database SecondaryDB_SP;
use database SecondaryDB_SP;

-- Schedule refresh of the secondary database

create task refresh_SecondaryDB_task
  warehouse = mywh
  schedule = '10 minute'
as
  alter database SecondaryDB refresh;

alter task refresh_SecondaryDB_task resume;

-- Refresh the secondary database now (as an alternative to the scheduled refresh)

alter database SecondaryDB refresh;

-- 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;
Copy

例2

データプロバイダーのAcmeは、データのサブセットを別の地域のデータコンシューマーと共有することを望んでいます。複製のコストを削減するために、マスターテーブルから関連する行のみを複製したいと考えています。複製はデータベースレベルで行われるため、この例では、Acmeがストリームとタスクを活用して、メインデータベースから新しいデータベースに目的の行をコピーし、新しいデータベースを複製する方法について説明します。このシナリオでは、新しいデータベースがデータ複製のプライマリデータベースとして指定されます。

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

ソースアカウントからの実行

次の SQL コマンドを使用して、ソースアカウントに新しいデータベースを作成し、複製を有効にします。

use role accountadmin;

-- 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 CUSTOMERID, 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 SourceDB.sch.tableA append_only = true;

-- Set up a task to lift the changes from the source database and insert them to the PrimaryDB database
CREATE 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 REGION='azure_eastus2' AND METADATA$ACTION = 'INSERT';

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

ターゲットアカウントからの実行

他のリージョンのターゲットアカウントから次の SQL コマンドを実行します。

use role accountadmin;

-- Replicate the existing database to a secondary database in the other region
create database SecondaryDB
  as replica of AWS_US_WEST_2.AcmeProviderAccount1.PrimaryDB;

-- Schedule refresh of the secondary database

create task refresh_SecondaryDB_task
  warehouse = mywh
  schedule = '10 minute'
as
  alter database SecondaryDB refresh;

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;
Copy