리전 및 클라우드 플랫폼 전체에서 안전하게 데이터 공유하기¶
이 항목에서는 데이터베이스 복제 를 사용하여 데이터 공급자가 다양한 리전 및 클라우드 플랫폼에 걸쳐 데이터를 데이터 컨슈머와 안전하게 공유할 수 있도록 하는 지침을 제공합니다. 데이터베이스 복제는 이제 계정 복제의 일부입니다. 계정 복제를 사용한 공유 복제에 대한 지침은 리전 및 클라우드 플랫폼 간 공유 복제 섹션을 참조하십시오.
리전 간 데이터 공유는 다음과 같은 클라우드 플랫폼에서 호스팅되는 Snowflake 계정에서 지원됩니다.
Amazon Web Services(AWS)
Google Cloud Platform
Microsoft Azure
중요
현재, 데이터베이스 역할은 기본 데이터베이스의 복제 에 포함되지 않습니다. 결과적으로, 데이터베이스 역할을 통해 오브젝트에 공유에 대한 권한이 부여될 때는 리전 간 데이터 공유가 지원되지 않습니다.
원본 Snowflake 계정이 있는 위치와 다른 지리적 리전 또는 국가의 계정으로 기본 데이터베이스를 복제하는 경우 조직에 데이터를 전송하거나 호스팅할 수 있는 위치에 대한 법적 또는 규제적 제한이 없는지 확인해야 합니다.
이 항목의 내용:
데이터 공유 고려 사항¶
리전 간 데이터 공유에서는 Snowflake 데이터 복제 기능을 사용하므로 계획 프로세스의 일부로 Snowflake에서 데이터베이스 복제가 작동하는 방식을 이해해야 합니다. 자세한 내용은 다음을 참조하십시오.
데이터 공급자는 컨슈머당 복사본이 아닌 리전당 데이터 세트의 복사본을 1개만 생성하면 됩니다.
여러 데이터베이스의 오브젝트를 참조하는 뷰를 공유하는 경우(지침은 여러 데이터베이스에서 데이터 공유 참조), 이러한 다른 데이터베이스 각각을 복제해야 합니다.
데이터 공급자는 모든 공용 다중 tenant 배포에서 컨슈머와 데이터를 공유할 수 있습니다. 그러나 현재 Virtual Private Snowflake(VPS) 와의 공유는 지원되지 않습니다.
다른 리전 및 클라우드 플랫폼의 데이터 컨슈머와 데이터 공유하기¶
Snowflake 데이터 공급자는 몇 가지 간단한 단계를 통해 다른 리전의 데이터 컨슈머와 데이터를 공유할 수 있습니다.
1단계: 데이터 복제 설정¶
참고
데이터 복제를 구성하기 전, 데이터를 공유할 리전에서 계정을 생성한 후 이를 로컬 계정에 연결해야 합니다. 자세한 내용은 Snowflake 조직 관리 섹션을 참조하십시오.
데이터 복제 설정에 포함되는 작업은 다음과 같습니다.
계정 중 1개에서 ORGADMIN 역할을 생성하고 복제를 위해 계정을 연결합니다. 자세한 내용은 조직 시작하기 섹션을 참조하십시오.
로컬 계정의 기존 데이터베이스를 기본 데이터베이스로 승격합니다.
기존 데이터베이스를 다른 리전에 복제합니다.
자세한 지침음 여러 계정에서 데이터베이스 복제하기 를 참조하십시오.
예 1¶
데이터 공급자인 Acme는 다른 리전의 데이터 컨슈머와 데이터를 공유하려고 합니다.
소스 계정에서 실행¶
다음 SQL 명령을 실행하여 기본 데이터베이스의 복제를 활성화합니다.
use role accountadmin;
-- Promote an existing database in your local account as primary
alter database PrimaryDB enable replication to accounts AZURE_EASTUS2.AcmeProviderAccount2;
대상 계정에서 실행하기¶
다른 리전의 대상 계정에서 다음 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;
예 2¶
데이터 공급자인 Acme는 다른 리전의 데이터 컨슈머와 데이터의 하위 세트를 공유하려고 합니다. 복제 비용을 줄이기 위해 Acme는 마스터 테이블에서 관련 행만 복제하려고 합니다. 복제는 데이터베이스 수준에서 수행되므로 이 예에서는 Acme가 스트림과 작업을 사용하여 원하는 행을 기본 데이터베이스에서 새 데이터베이스로 복사하고 새 데이터베이스를 복제하는 방법에 대해 설명합니다. 이 시나리오에서 새 데이터베이스는 데이터 복제를 위한 기본 데이터베이스로 지정됩니다.
소스 계정에서 실행¶
다음 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;
대상 계정에서 실행하기¶
다른 리전의 대상 계정에서 다음 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;