Oracle雙向同步測試方案

1.    測試目標
2.    測試環境
2.1    測試數據庫
2.2    創建測試表 
2.3    開啓數據庫歸檔 
2.4    s3建立同步用戶 
2.5    配置同步任務
2.5.1    安裝BeeDI 
2.5.2    全量任務 
2.5.3    增量任務  
3.    測試步驟  
3.1    全量同步  
3.2    實時同步 
3.2.1    增刪改合併 
3.2.2    增刪改分發
3.2.3    批量插入
3.2.4    大事務插入
3.2.5    順序更新 
3.2.6    斷網
3.2.7    併發更新
3.2.8    批量更新
3.2.9    大事務更新 

 

1.    測試目標
多地分公司數據實時同步到集團中心數據庫中,然後在集團中心庫對指定數據進行修改,修改後的數據可以實時推回到對應分公司數據庫中。


2.    測試環境


2.1    測試數據庫
3臺Oracle服務器s1、s2和s3,其中s1和s2代表分庫,s3代表中心庫。 


2.2    創建測試表
在服務器s1創建測試表t_share_pool_s1
create table scott.t_share_pool_s1(ID NUMBER(15) NOT NULL, COMPANY_CODE VARCHAR2(10) NOT NULL,WORK_F1 VARCHAR2(10),WORK_F2 VARCHAR2(10),LAST_TIME DATE,PRIMARY KEY(ID,COMPANY_CODE))
插入測試數據
      declare 
      count2 int := 1;
      begin
      while count2<=1000 loop
            insert into scott.t_share_pool_s1 (ID, COMPANY_CODE, WORK_F1, WORK_F2, LAST_TIME) values(count2,'S1','w1_0','w2_0',sysdate);
           count2 := count2+1;
       end loop;
commit;
       end;
在服務器s2創建測試表t_share_pool_s2
create table scott.t_share_pool_s2(ID NUMBER(15) NOT NULL, COMPANY_CODE VARCHAR2(10) NOT NULL,WORK_F1 VARCHAR2(10),WORK_F2 VARCHAR2(10),LAST_TIME DATE,PRIMARY KEY(ID,COMPANY_CODE))
插入測試數據
      declare 
      count2 int := 1;
      begin
      while count2<=1000 loop
insert into scott.t_share_pool_s2 (ID, COMPANY_CODE, WORK_F1, WORK_F2, LAST_TIME) values(count2,'S2','w1_0','w2_0',sysdate);
           count2 := count2+1;
       end loop;
commit;
       end;

在服務器s3創建測試表t_share_pool
create table scott.t_share_pool(ID NUMBER(15) NOT NULL, COMPANY_CODE VARCHAR2(10) NOT NULL,WORK_F1 VARCHAR2(10),WORK_F2 VARCHAR2(10),LAST_TIME DATE,PRIMARY KEY(ID,COMPANY_CODE))


2.3    開啓數據庫歸檔
依次在s1、s2、s3數據庫執行以下SQL
sqlplus / as sysdba
shutdown immediate;
startup mount;
alter database archivelog;
alter database open;
alter database add supplemental log data (primary key ,unique index) columns;


2.4    s3建立同步用戶
-- Create the user 
create user BEEDI identified by BEEDI default tablespace USERS  temporary tablespace TEMP;
-- Grant/Revoke role privileges 
grant connect to BEEDI;
grant resource to BEEDI;
-- Grant/Revoke system privileges 
grant delete any table to BEEDI;
grant insert any table to BEEDI;
grant select any table to BEEDI;
grant unlimited tablespace to BEEDI;
grant update any table to BEEDI;


2.5    配置同步任務


2.5.1    安裝BeeDI
運行BeeDI SE安裝程序,依次選擇【下一步】按鈕,直到彈出軟件註冊窗口,如下圖示:
 
點擊窗口中的 按鈕,彈出軟件註冊對話框,如下圖示:
 
點擊【查找】按鈕,導入BeeDI授權文件,然後選擇【確認】按鈕關閉【軟件註冊】對話框,安裝嚮導彈出界面如下圖示:
 
選擇軟件安裝目錄後,點擊【下一步】按鈕,安裝程序開始拷貝文件到安裝目錄,之後出現完成安裝窗口,如下圖示:
 
啓動BeeDI後,彈出登錄對話框,如下圖所示。
 
提示:BeeDI 安裝後,默認創建兩個用戶admin和guest,其密碼均爲空。
輸入正確的用戶和密碼後,點擊[確定],進入BeeDI


2.5.2    全量任務
全量同步任務用於將s1和s2中現有數據同步合併到數據庫s3,操作如下:
選擇工具欄[新建文件]按鈕,在[新建作業]對話框的[作業名稱]輸入sync_full,[類型]選擇ETL模板,點擊[確定]按鈕創建作業文件。
依次建立到s1、s2、s3的數據庫連接,,其中s1和s2可使用sys連接,s3使用beedi連接。從s1拖拽表節點scott.t_share_pool_s1到s3的表節點scott.t_share_pool上釋放鼠標,再從s2拖拽表節點scott.t_share_pool_s2到s3的表節點scott.t_share_pool上釋放鼠標,結果如下:
 
選擇工具欄[啓動]按鈕執行作業sync_full,結果如下:
 
 


2.5.3    增量任務
增量同步任務用於實時同步分庫數據變化到中心庫,同時對於中心庫的數據變化,根據數據來源推回到對應分庫。
選擇工具欄[新建文件]按鈕,在[新建作業]對話框的[作業名稱]輸入sync_log_up,[類型]選擇ETL模板,點擊[確定]按鈕創建分庫到中心庫的增量同步作業文件。
依次建立到s1、s2、s3的數據庫連接,其中s1和s2可使用sys連接,s3使用beedi連接。從s1拖拽表節點scott.t_share_pool_s1到s3的表節點scott.t_share_pool上釋放鼠標,再從s2拖拽表節點scott.t_share_pool_s2到s3的表節點scott.t_share_pool上釋放鼠標,結果如下:
 
點擊scott.t_share_pool_s1對應抽取組件窗口的[選項]按鈕,彈出[選項]對話框,點擊[增量抽取]複選框,彈出[增量抽取設置]對話框,操作如下圖:
 
 
 
選擇[日誌]按鈕,拖拽主鍵列ID和COMPANY_CODE到邏輯主鍵窗口,[解析點]使用默認時間,取消[分解UPDATE]複選,完成後的界面配置如下:
 
點擊[返回]按鈕關閉[增量抽取設置]對話框,顯示界面如下:
 
點擊[確定]按鈕關閉抽取組件[選項]對話框。
點擊scott.t_share_pool_s2抽取組件窗口的[選項]按鈕,重複以上步驟,完成基於日誌的增量設置。
選擇工具欄[啓動]按鈕執行作業sync_log_up,結果如下:
 
選擇工具欄[新建文件]按鈕,在[新建作業]對話框的[作業名稱]輸入sync_log_down,[類型]選擇ETL模板,點擊[確定]按鈕創建中心庫到分庫的增量同步作業文件。
依次建立到s3、s1、s2的數據庫連接,其中s3、s1和s2可使用sys連接。從s3拖拽表節點scott.t_share_pool到模板建立抽取組件,操作如下:
 
右鍵點擊s1表結點scott.t_share_pool_s1,從快捷菜單選擇[裝載]命令在模板建立裝載組件,操作如下:
 
 
右鍵點擊s2表結點scott.t_share_pool_s2,從快捷菜單選擇[裝載]命令在模板建立裝載組件,操作結果如下:
 
拖拽scott.t_share_pool對應抽取組件的映射拖拽點到scott.t_share_pool_s1對應的裝載組件窗口,彈出[全表映射模式設置]對話框,選擇[列名匹配映射],點擊[確定]按鈕完成抽取組件到裝載組件的列映射,操作結果如下:
 
 
 
再次拖拽scott.t_share_pool對應抽取組件的映射拖拽點到scott.t_share_pool_s2對應的裝載組件窗口,選擇[列名匹配映射],建立scott.t_share_pool抽取組件到scott.t_share_pool_s2裝載組件的列映射,完成後界面如下:
 
點擊scott.t_share_pool對應抽取組件窗口的[選項]按鈕,彈出[選項]對話框,點擊[增量抽取]複選框,彈出[增量抽取設置]對話框,操作如下圖:
 
 
 
選擇[日誌]按鈕,拖拽主鍵列ID和COMPANY_CODE到邏輯主鍵窗口,[解析點]使用默認時間,取消[分解UPDATE]複選,[忽略用戶]輸入beedi,完成後的界面配置如下:
 
點擊[返回]按鈕關閉[增量抽取設置]對話框,顯示界面如下:
 
點擊[確定]按鈕關閉抽取組件[選項]對話框。
點擊scott.t_share_pool_s1對應裝載組件窗口的[選項]按鈕,彈出[選項]對話框,點擊[過濾表達式]輸入按鈕,彈出[過濾表達式腳本設置]對話框,在其中輸入過濾腳本equals(query_15.COMPANY_CODE,"S1"),操作如下圖:
(注:此處query_15表示抽取組件名,可用實際組件名替換)
 
 
 
點擊[確定]按鈕關閉[過濾表達式腳本設置]對話框,顯示界面如下:
 
點擊[確定]按鈕關閉裝載組件[選項]對話框。
點擊scott.t_share_pool_s2裝載組件窗口的[選項]按鈕,重複以上操作設置過濾表達式equals(query_15.COMPANY_CODE,"S2"),結果如下。
(注:此處query_15表示抽取組件名,可用實際組件名替換)
 
選擇工具欄[啓動]按鈕執行作業sync_log_down,結果如下:
 
右鍵點擊調度窗口的作業sync_full,在快捷菜單中選擇[刪除]命令將該作業從調度窗口刪除。
 
 
使用CTRL鍵,選中調度窗口的作業sync_log_up和sync_log_down,  


選擇 [定時]按鈕,彈出[作業定時設置]對話框,點擊[確定]按鈕,操作結果如下圖:
 
 
 


3.    測試步驟


3.1    全量同步
依次將s1和s2表數據同步到s3,查詢觀察中心庫數據是否一致。
作業sync_full執行成功後,s1和s2分庫數據與中心庫數據一致


3.2    實時同步


3.2.1    增刪改合併
分別對s1和s2的表進行5次增刪改操作,查詢觀察中心庫數據是否一致。
declare 
count2 int := 1001;
begin
while count2<=1005 loop
insert into scott.t_share_pool_s1 (ID, COMPANY_CODE, WORK_F1, WORK_F2, LAST_TIME) values(count2,'S1','w1_0','w2_0',sysdate);
update scott.t_share_pool_s1 set work_f1 = 'w1_88',work_f2='w2_88' where ID = count2 and COMPANY_CODE = 'S1';
delete from scott.t_share_pool_s1  where ID = count2 and COMPANY_CODE = 'S1';
count2 := count2+1;
end loop;
commit;
end;

declare 
count2 int := 1001;
begin
while count2<=1005 loop
insert into scott.t_share_pool_s2 (ID, COMPANY_CODE, WORK_F1, WORK_F2, LAST_TIME) values(count2,'S2','w1_0','w2_0',sysdate);
update scott.t_share_pool_s2 set work_f1 = 'w1_88',work_f2='w2_88' where ID = count2 and COMPANY_CODE = 'S2';
delete from scott.t_share_pool_s2  where ID = count2 and COMPANY_CODE = 'S2';
count2 := count2+1;
end loop;
commit;
end;


3.2.2    增刪改分發
分別修改中心庫對應s1和s2的5條數據,查詢觀察s1和s2數據是否一致。
declare 
count2 int := 1;
begin
while count2<=5 loop
update scott.t_share_pool set work_f1 = 'w1_99',work_f2='w2_99' where ID = count2 and COMPANY_CODE = 'S1';
count2 := count2+1;
end loop;
commit;
end;

declare 
count2 int := 1;
begin
while count2<=5 loop
update scott.t_share_pool set work_f1 = 'w1_77',work_f2='w2_77' where ID = count2 and COMPANY_CODE = 'S2';
count2 := count2+1;
end loop;
commit;
end;


3.2.3    批量插入
分別在s1和s2批量插入10000條數據,每500條提交一次,查詢觀察中心庫數據是否一致。
declare 
count2 int := 1001;
begin
while count2<=11000 loop
insert into scott.t_share_pool_s1 (ID, COMPANY_CODE, WORK_F1, WORK_F2, LAST_TIME) 
               values(count2,'S1','w1_0','w2_0',sysdate);
count2 := count2+1;
if mod(count2-1001,500)=0 then
commit;
end if;
end loop;
commit;
end;

declare 
count2 int := 1001;
begin
while count2<=11000 loop
insert into scott.t_share_pool_s2 (ID, COMPANY_CODE, WORK_F1, WORK_F2, LAST_TIME) 
               values(count2,'S2','w1_0','w2_0',sysdate);
count2 := count2+1;
if mod(count2-1001,500)=0 then
commit;
end if;
end loop;
commit;
end;


3.2.4    大事務插入
在s1批量插入100000條數據,10000條提交一次,查詢觀察中心庫數據是否一致。
declare 
count2 int := 11001;
begin
while count2<=111000 loop
insert into scott.t_share_pool_s1 (ID, COMPANY_CODE, WORK_F1, WORK_F2, LAST_TIME) 
               values(count2,'S1','w1_0','w2_0',sysdate);
count2 := count2+1;
if mod(count2-11001,10000)=0 then
commit;
end if;
end loop;
commit;
end;


3.2.5    順序更新
在s1修改某一記錄,然後在中心庫修改對應記錄,查詢觀察s1和中心庫數據是否一致。
update scott.t_share_pool_s1 set work_f1 = 'w1_99',work_f2='w2_99' where ID = 1001;
commit;

update scott.t_share_pool set work_f1 = 'w1_11',work_f2='w2_11' where ID = 1001 and COMPANY_CODE = 'S1';
commit;

3.2.6    斷網
斷網修改s1某一記錄,恢復網絡後查詢比較中心庫是否一致,斷網修改中心庫某一記錄,恢復網絡後查詢比較s1是否一致。
update scott.t_share_pool_s1 set work_f1 = 'w1_99',work_f2='w2_99' where ID = 1002;
commit;

update scott.t_share_pool set work_f1 = 'w1_11',work_f2='w2_11' where ID = 1002 and COMPANY_CODE = 'S1';
commit;


3.2.7    併發更新
同時重複5次修改s1和中心庫的同一記錄,查詢觀察s1和中心庫數據是否一致。
declare 
count2 int := 1;
begin
while count2<=5 loop
update scott.t_share_pool_s1 set work_f1 = 'w1_99_'||count2,work_f2='w2_99_'||count2 where ID = 1003;
commit;
count2 := count2+1;
end loop;
end;

declare 
count2 int := 1;
begin
while count2<=5 loop
update scott.t_share_pool set work_f1 = 'w1_11_'||count2,work_f2='w2_11_'||count2 where ID = 1003 and company_code = 'S1';
commit;
count2 := count2+1;
end loop;
end;


3.2.8    批量更新
修改中心庫500條記錄,每條提交一次,查詢觀察s1和中心庫數據是否一致。
declare 
count2 int := 1;
begin
while count2<=500 loop
update scott.t_share_pool set work_f1 = 'w1_99_'||count2,work_f2='w2_99_'||count2 where ID = count2 and company_code = 'S1';
commit;
count2 := count2+1;
end loop;
end;


3.2.9    大事務更新
修改中心庫20000條記錄後一次提交,查詢觀察s1和中心庫數據是否一致。
declare 
count2 int := 1;
begin
while count2<=20000 loop
update scott.t_share_pool set work_f1 = 'w1_7_'||count2,work_f2='w2_7_'||count2 where ID = count2 and company_code = 'S1';
count2 := count2+1;
end loop;
commit;
end;

 

 

發佈了11 篇原創文章 · 獲贊 1 · 訪問量 4052
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章