GaussDB(DWS)跨集群互联互通使用介绍
1. 背景介绍
多个局点均部署多套集群,集群间存在大量基础数据同步和访问,实现跨集群同步有两种方式,基于EC和协同分析,高并发时会使源端数据再CN实例产生较高负载,因此需要提供一种高效便捷的跨集群互联互通方法,可以支持大批量、多任务的互访需求,减少数据物理搬迁,充分利用集群算力,提高效率。
通过gds外表结合管道实现此需求,且近在招行局点受限商用,满足客户全量数据同步、过滤条件数据同步。
2. 使用介绍
2.1 前置准备
环境互通要求:HCS环境,目标集群、源集群、gds服务器在同一个vpc下面
I1.在源端集群同步库中创建互联互通用户,此用户对库中同步的表有访问权限,有schema的create权限和外表的创建权限
drop user if exists connector_user;
create user connector_user password "Gauss_234";
alter user connector_user with USEFT ;
I2.管理员用户登录源端数据库,创建schema "20210930_dws_connector"并赋权,目的是存放互联互通过程创建的gds外表;
drop schema if exists "20210930_dws_connector";
create schema "20210930_dws_connector";
grant all on schema "20210930_dws_connector" to public;
I3.connector_user用户登录源数据库,创建schema和源表,并插入数据
drop schema if exists dws_connector_schema cascade;
create schema dws_connector_schema;
set search_path to dws_connector_schema;
drop table if exists connector_sourcetb;
create table connector_sourcetb
(
L_ORDERKEY BIGINT
, L_PARTKEY BIGINT
, L_SUPPKEY BIGINT
, L_LINENUMBER BIGINT
, L_QUANTITY DECIMAL(15,2)
, L_EXTENDEDPRICE DECIMAL(15,2)
, L_DISCOUNT DECIMAL(15,2)
, L_TAX DECIMAL(15,2)
, L_RETURNFLAG CHAR(1)
, L_LINESTATUS CHAR(1)
, L_SHIPDATE DATE
, L_COMMITDATE DATE
, L_RECEIPTDATE DATE
, L_SHIPINSTRUCT CHAR(25)
, L_SHIPMODE CHAR(10)
, L_COMMENT VARCHAR(44)
)
with(orientation=column)
distribute by hash(L_ORDERKEY)
;
insert into connector_sourcetb values (generate_series(1,1000),18352138,602157,generate_series(1,10),24.00,28541.28,.03,.07,'N','O','1998-05-20 00:00:00','1998-03-22 00:00:00',sysdate,'TAKE BACK RETURN','TRUCK','accounts. forges in');
I4.登录gds服务器启动gds
gds -p xx.xx.xx.xx1:10081 -H xx.xx.xx.xx/24 -d /data1/datatmp/ -D -t 100 -l /home/gds_user/gdslog/10081.log --pipe-size 1M
gds -p xx.xx.xx.xx2:10081 -H xx.xx.xx.xx/24 -d /data1/datatmp/ -D -t 100 -l /home/gds_user/gdslog/10081.log --pipe-size 1M
I5.目标集群端创建普通用户,普通用户有创建或者访问目标表的权限,有创建外表的权限,有create schema的权限;
drop user if exists connector_suser;
create user connector_suser password "Gauss_234";
grant USAGE on FOREIGN DATA WRAPPER GC_FDW to connector_suser;
alter user connector_suser with USEFT ;
I6.管理员用户登录目标集群数据库,创建互联互通过程中gds外表所需的schema,并赋权
drop schema if exists "20210930_dws_connector";
create schema "20210930_dws_connector";
grant all on schema "20210930_dws_connector" to public;
I7.普通用户connector_tuser登录目标数据库,创建目标表存在的schema(如果已存在赋予普通用户写的权限)
drop schema if exists dws_connector_schema cascade;
create schema dws_connector_schema;
I8.普通用户connector_tuser登录目标数据库,创建互联互通server
drop SERVER if exists server_remote cascade;
CREATE SERVER server_remote FOREIGN DATA WRAPPER GC_FDW OPTIONS
(address 'xx.xx.xx.xx:port' , --源集群cn的IP:port,或者elb的ip:port
dbname 'connector_db1', --源集群同步数据的库
username 'connector_user', --源集群互联互通的用户
password 'Gauss_234', --源集群互联互通用户的密码
syncsrv 'gsfs:// xx.xx.xx.xx1:10081|gsfs:// xx.xx.xx.xx2:10081' --gds服务地址,多个用|分割
2.2 全量数据同步
I1.普通用户connector_tuser登录目标集群数据库,创建目标表
set search_path to dws_connector_schema;
drop table if exists connector_targettb;
create table connector_targettb
(
L_ORDERKEY BIGINT
, L_PARTKEY BIGINT
, L_SUPPKEY BIGINT
, L_LINENUMBER BIGINT
, L_QUANTITY DECIMAL(15,2)
, L_EXTENDEDPRICE DECIMAL(15,2)
, L_DISCOUNT DECIMAL(15,2)
, L_TAX DECIMAL(15,2)
, L_RETURNFLAG CHAR(1)
, L_LINESTATUS CHAR(1)
, L_SHIPDATE DATE
, L_COMMITDATE DATE
, L_RECEIPTDATE DATE
, L_SHIPINSTRUCT CHAR(25)
, L_SHIPMODE CHAR(10)
, L_COMMENT VARCHAR(44)
)
with(orientation=column)
distribute by hash(L_ORDERKEY)
;
I2.普通用户connector_tuser登录目标集群数据库,创建互联外表
DROP FOREIGN TABLE if exists ft_connector_sourcetb;
CREATE FOREIGN TABLE ft_connector_sourcetb
(
like connector_targettb
)
SERVER
server_remote
OPTIONS
(
schema_name 'dws_connector_schema',
table_name 'connector_sourcetb',
encoding 'utf8'
);
I3.普通用户connector_tuser登录目标集群数据库,全量同步所有列数据,并查看数据
insert into connector_targettb select * from ft_connector_sourcetb;
select count(*) from connector_targettb;
select * from connector_targettb limit 10;
I4.普通用户connector_tuser登录目标集群数据库,全量同步部分列数据,并查看数据
truncate connector_targettb;
insert into connector_targettb (L_ORDERKEY,L_LINENUMBER,L_SHIPDATE,L_SHIPMODE) select L_ORDERKEY,L_LINENUMBER,L_SHIPDATE,L_SHIPMODE from ft_connector_sourcetb;
select count(*) from connector_targettb;
select L_ORDERKEY,L_LINENUMBER,L_SHIPDATE,L_SHIPMODE from connector_targettb limit 10;
2.3 带过滤条件的数据同步
I1.普通用户connector_tuser登录目标集群数据库,创建目标表
set search_path to dws_connector_schema;
drop table if exists connector_targettb;
create table connector_targettb
(
L_ORDERKEY BIGINT
, L_PARTKEY BIGINT
, L_SUPPKEY BIGINT
, L_LINENUMBER BIGINT
, L_QUANTITY DECIMAL(15,2)
, L_EXTENDEDPRICE DECIMAL(15,2)
, L_DISCOUNT DECIMAL(15,2)
, L_TAX DECIMAL(15,2)
, L_RETURNFLAG CHAR(1)
, L_LINESTATUS CHAR(1)
, L_SHIPDATE DATE
, L_COMMITDATE DATE
, L_RECEIPTDATE DATE
, L_SHIPINSTRUCT CHAR(25)
, L_SHIPMODE CHAR(10)
, L_COMMENT VARCHAR(44)
)
with(orientation=column)
distribute by hash(L_ORDERKEY)
;
I2.普通用户connector_tuser登录目标集群数据库,创建互联外表
DROP FOREIGN TABLE if exists ft_connector_sourcetb;
CREATE FOREIGN TABLE ft_connector_sourcetb
(
like connector_targettb
)
SERVER
server_remote
OPTIONS
(
schema_name 'dws_connector_schema',
table_name 'connector_sourcetb',
encoding 'utf8'
);
I3.普通用户connector_tuser登录目标集群数据库,同步所有列数据且带过滤条件,并查看数据
insert into connector_targettb select * from ft_connector_sourcetb where L_LINENUMBER<=6 and L_RETURNFLAG='N';
select count(*) from connector_targettb;
select * from connector_targettb limit 10;
I4.普通用户connector_tuser登录目标集群数据库,同步部分列数据且带过滤条件,并查看数据
truncate connector_targettb;
insert into connector_targettb (L_ORDERKEY,L_LINENUMBER,L_SHIPDATE,L_SHIPMODE) select L_ORDERKEY,L_LINENUMBER,L_SHIPDATE,L_SHIPMODE from ft_connector_sourcetb where L_LINENUMBER<=6 and L_RETURNFLAG='N';
select count(*) from connector_targettb;
select L_ORDERKEY,L_LINENUMBER,L_SHIPDATE,L_SHIPMODE from connector_targettb limit 10;
- 点赞
- 收藏
- 关注作者
评论(0)