Optim High Performance Unload [HPU]
一、簡介
HPU即Optim High Performance Unload,是一款快速的、高效的、靈活的、多功能的資料解除安裝和遷移工具。在大部分情況下,HPU 解除安裝資料的速度比 DB2 Export 實用工具要快,因為 HPU 可以繞過 DB2 資料庫管理器,直接訪問資料庫檔案。因此在使用它解除安裝資料時可以達到相當高的效能。不僅如此,HPU還可以以資料不落地的方式線上進行遷移,自動地將資料從一個系統中的 DB2 例項遷移到另一個系統中的 DB2 例項中,其中包括解除安裝,遷移,載入資料到目標例項的操作。
二、安裝
Mark: 通過root使用者進行安裝和解除安裝
下載好安裝介質, 例如測試的介質為V5.1 Linux x86版本
OHPU_DB2_FOR_LUW_V5.1.0.1_LNX86.tar.gz
提前安裝好xinetd
yum install xinetd -y
解壓安裝包
tar xf /tmp/OHPU_DB2_FOR_LUW_V5.1.0.1_LNX86.tar.gz
進入解壓好的安裝目錄,執行安裝程式
[root@host-170-130-106-206] [~] $ cd /tmp/HPU5101/ [root@host-170-130-106-206] [/tmp/HPU5101] $ ll 總用量 32964 -rw-r--r-- 1 root root 32184320 8月 17 2014 archive_core_linux.tar -rw-r--r-- 1 root root 378880 8月 17 2014 archive_inst_linux.tar -rw-r--r-- 1 root root 358400 8月 17 2014 archive_network_linux.tar -rw-r--r-- 1 root root 133120 8月 17 2014 archive_procedure_linux.tar -rw-r--r-- 1 root root 358400 8月 17 2014 archive_uninst_linux.tar drwxr-xr-x 2 root root 37 8月 17 2014 config -r-xr-xr-x 1 root root 59610 8月 17 2014 installer_common.sh -r-xr-xr-x 1 root root 176208 8月 17 2014 installer_setup.sh -r-xr-xr-x 1 root root 3051 8月 17 2014 install_hpu.sh -r--r--r-- 1 root root 769 8月 17 2014 InstallInstructions.txt -r--r--r-- 1 root root 10435 8月 17 2014 install_linux.ini drwxr-xr-x 24 root root 4096 8月 17 2014 license drwxr-xr-x 20 root root 283 8月 17 2014 messages -r--r--r-- 1 root root 18760 8月 17 2014 Readme.txt drwxr-xr-x 2 root root 61 8月 17 2014 support -rw-r--r-- 1 root root 0 6月 8 10:40 trace_error_install -rw-r--r-- 1 root root 40286 6月 8 10:40 trace_install -rw-r--r-- 1 root root 0 6月 8 10:40 trace_warning_install -r-xr-xr-x 1 root root 2080 8月 17 2014 uninstall_hpu.sh [root@host-170-130-106-206] [/tmp/HPU5101] $ ./install_hpu.sh 此指令碼將在計算機上安裝 Optim High Performance Unload for DB2 for Linux, UNIX and Windows ------------------------------------------------------------------------------- HPU 5.1.0.1 (Full) 完成 安裝 IBM Corp. http://www.ibm.com/software/data/db2imstools 安裝目錄: /opt/ibm/HPU/V5.1 這是要用於安裝產品的目錄。 輸入 1 進行下一步,輸入 2 取消: 1 .... .... .... L/N: L-DNAA-94TPSX D/N: L-DNAA-94TPSX P/N: L-DNAA-94TPSX 輸入 1 接受協議,輸入 2 拒絕協議 1 ........................................................................................................ 安裝已完成,但存在警告。 在檔案 /opt/ibm/HPU/V5.1/install/trace_warning_install 中可找到警告訊息。 要允許 DBA 對檔案進行更改而不要求 root 使用者許可權,您可以更改 HPU 配置目錄的所有權。要更改所有權,從命令提示符輸入: chown -R mydba:dbagroup HPU_install_directory/cfg 此外,如果 DBA 沒有將項新增到預設例項和資料庫的 db2hpu.cfg 檔案,需要所有使用者在命令列中至少使用 -i 選項,並可選擇使用 -d 選項。
預設是安裝在/opt/ibm/HPU
檢查安裝版本
$ /opt/ibm/HPU/V5.1/bin/db2hpu --version
INZM030I Optim High Performance Unload for DB2 for Linux, UNIX and Windows 版本 64 位 05.01.00.001(140816)
解除安裝軟體
$ /opt/ibm/HPU/V5.1/uninstall/uninstall_hpu.sh 此指令碼將解除安裝計算機上的 Optim High Performance Unload for DB2 for Linux, UNIX and Windows ------------------------------------------------------------------------------- HPU 5.1.0.1 (Full) 完成 安裝 IBM Corp. http://www.ibm.com/software/data/db2imstools 安裝目錄: /opt/ibm/HPU/V5.1 這是要用於除去產品的目錄。 輸入 1 進行下一步,輸入 2 取消: 1 ............................................................................................... 解除安裝已完成,但存在警告。 請檢視檔案 /tmp/trace_warning_uninstall 以獲取詳細資訊。
三、基本配置
建立db2hpu的軟連結
$ ln -sv /opt/ibm/HPU/V5.1/bin/db2hpu /bin/db2hpu
"/bin/db2hpu" -> "/opt/ibm/HPU/V5.1/bin/db2hpu"
[root@host-170-130-106-206] [/opt/ibm/HPU/V5.1/bin]
$ ls -lrt /bin/db2hpu
lrwxrwxrwx 1 root root 28 6月 8 14:02 /bin/db2hpu -> /opt/ibm/HPU/V5.1/bin/db2hpu
修改如下配置檔案,新增下面三行,增強HPU效能
cps = 5000 10
instances = 5000
per_source = 100
最終檔案內容如下:
$ cat /etc/xinetd.d/db2hpudm51
#
# @(#) db2hpudm51
#
service db2hpudm51
{
disable = no
flags = REUSE
socket_type = stream
protocol = tcp
wait = no
user = root
server = /opt/ibm/HPU/V5.1/bin/db2hpudm
server_args = --tophpu /opt/ibm/HPU/V5.1 --loglevel 3 --inetd --logfile /var/log/hpu/db2hpudm51.log
log_on_failure += USERID HOST
log_on_success += USERID PID HOST DURATION
cps = 5000 10
instances = 5000
per_source = 100
}
重啟xinetd服務
$ systemctl restart xinetd
修改/opt/ibm/HPU/V5.1/cfg/
屬組為DB2例項owner,則後續例項owner可以修改對應的HPU卸數引數
$ chown -R db2inst1.dbgrp /opt/ibm/HPU/V5.1/cfg/
修改配置檔案如下(預設的資料庫名和例項名可以按需指定,則呼叫db2hpu時不需要單獨指定例項和資料庫)
$ cat /opt/ibm/HPU/V5.1/cfg/db2hpu.cfg
# HPU default configuration
bufsize=2097152
db2dbdft=sample
db2instance=db2inst1
doubledelim=binary
netservice=db2hpudm51
allow_unlimited_memory=yes
keepalive_time=10
maxthreads=8
maxselects=10
mig_pipe_timeout=60
min_extent_per_thread=4
use_stats=true
nbcpu=8
umask=022
新建HPU憑證
$ su - db2inst1
$ mkdir .db2hpu
$ cd .db2hpu
$ touch db2hpu.creds
$ db2hpu --credentials local
INZM059I Optim High Performance Unload for DB2 for Linux, UNIX and Windows 05.01.00.001(140816)
管理“local”良好連線的憑證:
- 要建立或除去資料嗎 (1/2)?1
- 是新部分嗎 (Y/N)?y
- 提供節名稱:db2inst1
- 提供使用者名稱:db2inst1
- 提供密碼:********
要驗證資料嗎 (Y/N)?y
INZM061I 已為“db2inst1”建立了連線的憑證
四、卸數
4.1. 命令列匯出
db2hpu.cfg 中已經配置了db2inst1例項和sample資料庫,這裡就不需要單獨指定了
--匯出成del檔案
$ db2hpu --format del -t staff -o /tmp/staff.del
INZI466W 配置引數“use_stats”的值無效:將使用 NO。
INZM031I Optim High Performance Unload for DB2 for Linux, UNIX and Windows 05.01.00.001(140816) 64 位 2021年06月08日 (Linux host-170-130-106-206 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64)
INZI473I 記憶體限制:虛擬記憶體為 'unlimited' 且資料段為 'unlimited'
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----10---+----11---+----12---+----13-
000001 UNLOAD TABLESPACE
000002 PART(ALL)
000003 SELECT * FROM "STAFF";
000004 OUTFILE("/tmp/staff.del")
000005 FORMAT DEL;
INZU462I HPU 控制步驟開始: 14:23:58.213。
INZU463I HPU 控制步驟結束: 14:23:58.375。
INZU464I HPU 執行步驟開始: 14:23:58.376。
INZU410I HPU 實用程式已經卸裝 35 行(在 host-170-130-106-206 主機上,針對 DB2INST1.STAFF,在 /tmp/staff.del 中)。
INZU465I HPU 執行步驟結束: 14:23:58.543。
INZI441I HPU 成功結束:實時 -> 0m0.330008s
使用者時間 -> 0m0.025528s:父代 -> 0m0.024063s,子代 -> 0m0.001465s
系統時間 -> 0m0.060931s:父代 -> 0m0.052136s,子代 -> 0m0.008795s
$ cat /tmp/staff.del
10,"Sanders",20,"Mgr ",7,+98357.50,
20,"Pernal",20,"Sales",8,+78171.25,+00612.45
30,"Marenghi",38,"Mgr ",5,+77506.75,
40,"O'Brien",38,"Sales",6,+78006.00,+00846.55
50,"Hanes",15,"Mgr ",10,+80659.80,
60,"Quigley",38,"Sales",,+66808.30,+00650.25
70,"Rothman",15,"Sales",7,+76502.83,+01152.00
80,"James",20,"Clerk",,+43504.60,+00128.20
90,"Koonitz",42,"Sales",6,+38001.75,+01386.70
100,"Plotz",42,"Mgr ",7,+78352.80,
也可以單獨指定例項和資料庫,例如
$ db2hpu -i db2inst1 -d sample --format ixf -t emp -o /tmp/emp.ixf
INZI466W 配置引數“use_stats”的值無效:將使用 NO。
INZM031I Optim High Performance Unload for DB2 for Linux, UNIX and Windows 05.01.00.001(140816) 64 位 2021年06月08日 (Linux host-170-130-106-206 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64)
INZI473I 記憶體限制:虛擬記憶體為 'unlimited' 且資料段為 'unlimited'
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----10---+----11---+----12---+----13-
000001 GLOBAL CONNECT TO SAMPLE;
000002 UNLOAD TABLESPACE
000003 PART(ALL)
000004 SELECT * FROM "EMP";
000005 OUTFILE("/tmp/emp.ixf")
000006 FORMAT IXF;
INZU462I HPU 控制步驟開始: 14:26:55.716。
INZU463I HPU 控制步驟結束: 14:26:55.751。
INZU464I HPU 執行步驟開始: 14:26:55.752。
INZU410I HPU 實用程式已經卸裝 42 行(在 host-170-130-106-206 主機上,針對 DB2INST1.EMPLOYEE,在 /tmp/emp.ixf 中)。
INZU465I HPU 執行步驟結束: 14:26:55.973。
INZI441I HPU 成功結束:實時 -> 0m0.256954s
使用者時間 -> 0m0.036646s:父代 -> 0m0.034759s,子代 -> 0m0.001887s
系統時間 -> 0m0.052511s:父代 -> 0m0.046850s,子代 -> 0m0.005661s
4.2. 控制檔案
4.2.1. 從表空間容器卸數
有時候卸數的真實場景會更復雜些,這時候可以通過指定控制檔案來達成更復雜的場景需求,例如:
cat > sample.ctl << EOF
GLOBAL CONNECT TO SAMPLE;
unload tablespace USERSPACE1
SELECT * FROM db2inst1.staff WHERE job ='Sales';
OUTPUT("/home/db2inst1/export/staff_sales.del" REPLACE)
FORMAT DEL;
unload tablespace USERSPACE1
SELECT * FROM db2inst1.staff WHERE job ='Mgr';
OUTPUT("/home/db2inst1/export/staff_mgr.del" REPLACE)
FORMAT DEL;
unload tablespace USERSPACE1
SELECT * FROM db2inst1.EMP_PHOTO;
OUTPUT("/home/db2inst1/export/EMP_PHOTO" REPLACE)
LOB IN ("/home/db2inst1/export/lobs")
LOBFILE("EMP_PHOTO")
FORMAT DEL;
EOF
上面的控制檔案中含3段卸數邏輯
- 匯出staff表中job為Sales的資料
- 匯出staff表中job為Mrg的資料
- 匯出EMP_PHOTO表並且指定了BLOB資料匯出位置
$ db2hpu -f sample.ctl
INZI466W 配置引數“use_stats”的值無效:將使用 NO。
INZM031I Optim High Performance Unload for DB2 for Linux, UNIX and Windows 05.01.00.001(140816) 64 位 2021年06月08日 (Linux host-170-130-106-206 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64)
INZI473I 記憶體限制:虛擬記憶體為 'unlimited' 且資料段為 'unlimited'
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----10---+----11---+----12---+----13-
000001 GLOBAL CONNECT TO SAMPLE;
000002 unload tablespace USERSPACE1
000003 SELECT * FROM db2inst1.staff WHERE job ='Sales';
000004 OUTPUT("/home/db2inst1/export/staff_sales.del" REPLACE)
000005 FORMAT DEL;
000006
000007 unload tablespace USERSPACE1
000008 SELECT * FROM db2inst1.staff WHERE job ='Mgr';
000009 OUTPUT("/home/db2inst1/export/staff_mgr.del" REPLACE)
000010 FORMAT DEL;
000011
000012 unload tablespace USERSPACE1
000013 SELECT * FROM db2inst1.EMP_PHOTO;
000014 OUTPUT("/home/db2inst1/export/EMP_PHOTO" REPLACE)
000015 LOB IN ("/home/db2inst1/export/lobs")
000016 LOBFILE("EMP_PHOTO")
000017 FORMAT DEL;
INZU462I HPU 控制步驟開始: 15:09:54.683。
INZU463I HPU 控制步驟結束: 15:09:54.760。
INZU464I HPU 執行步驟開始: 15:09:54.760。
INZU410I HPU 實用程式已經卸裝 12 行(在 host-170-130-106-206 主機上,針對 DB2INST1.STAFF,在 /home/db2inst1/export/staff_sales.del 中)。
INZU410I HPU 實用程式已經卸裝 11 行(在 host-170-130-106-206 主機上,針對 DB2INST1.STAFF,在 /home/db2inst1/export/staff_mgr.del 中)。
INZU410I HPU 實用程式已經卸裝 8 行(在 host-170-130-106-206 主機上,針對 DB2INST1.EMP_PHOTO,在 /home/db2inst1/export/EMP_PHOTO 中)。
INZU465I HPU 執行步驟結束: 15:09:55.387。
INZI441I HPU 成功結束:實時 -> 0m0.704005s
使用者時間 -> 0m0.025539s:父代 -> 0m0.025539s,子代 -> 0m0.000000s
系統時間 -> 0m0.081912s:父代 -> 0m0.068758s,子代 -> 0m0.013154s
匯出結果:
[db2inst1@host-170-130-106-206] [~/export]
$ ls -lrt
總用量 16
-rw-r--r-- 1 db2inst1 dbgrp 537 6月 8 15:09 sample.ctl
-rw-r--r-- 1 db2inst1 dbgrp 554 6月 8 15:09 staff_sales.del
-rw-r--r-- 1 db2inst1 dbgrp 402 6月 8 15:09 staff_mgr.del
drwxr-xr-x 2 db2inst1 dbgrp 230 6月 8 15:09 lobs
-rw-r--r-- 1 db2inst1 dbgrp 532 6月 8 15:09 EMP_PHOTO
[db2inst1@host-170-130-106-206] [~/export]
$ ls -l lobs/
總用量 392
-rw-r--r-- 1 db2inst1 dbgrp 43690 6月 8 15:09 EMP_PHOTO.e00001.000
-rw-r--r-- 1 db2inst1 dbgrp 29540 6月 8 15:09 EMP_PHOTO.e00002.000
-rw-r--r-- 1 db2inst1 dbgrp 71798 6月 8 15:09 EMP_PHOTO.e00003.000
-rw-r--r-- 1 db2inst1 dbgrp 29143 6月 8 15:09 EMP_PHOTO.e00004.000
-rw-r--r-- 1 db2inst1 dbgrp 73438 6月 8 15:09 EMP_PHOTO.e00005.000
-rw-r--r-- 1 db2inst1 dbgrp 39795 6月 8 15:09 EMP_PHOTO.e00006.000
-rw-r--r-- 1 db2inst1 dbgrp 63542 6月 8 15:09 EMP_PHOTO.e00007.000
-rw-r--r-- 1 db2inst1 dbgrp 36088 6月 8 15:09 EMP_PHOTO.e00008.000
[db2inst1@host-170-130-106-206] [~/export]
$ cat EMP_PHOTO
"000130","bitmap","/home/db2inst1/export/lobs/EMP_PHOTO.e00001.000"
"000130","gif","/home/db2inst1/export/lobs/EMP_PHOTO.e00002.000"
"000140","bitmap","/home/db2inst1/export/lobs/EMP_PHOTO.e00003.000"
"000140","gif","/home/db2inst1/export/lobs/EMP_PHOTO.e00004.000"
"000150","bitmap","/home/db2inst1/export/lobs/EMP_PHOTO.e00005.000"
"000150","gif","/home/db2inst1/export/lobs/EMP_PHOTO.e00006.000"
"000190","bitmap","/home/db2inst1/export/lobs/EMP_PHOTO.e00007.000"
"000190","gif","/home/db2inst1/export/lobs/EMP_PHOTO.e00008.000"
4.2.2. 從備份映象中卸數
另外除了從表空間container中卸數,也可以從資料庫的備份檔案中進行卸數,這對於資料實時性要求不高的場景很適合,還避免了直接操作在執行的資料庫。
$ db2 backup db sample online to /home/db2inst1/export
Backup successful. The timestamp for this backup image is : 20210608152001
cat > sample01.ctl << EOF
GLOBAL CONNECT TO SAMPLE ;
UNLOAD TABLESPACE USERSPACE1
USING BACKUP DATABASE SAMPLE FROM "/home/db2inst1/export/" TAKEN AT 20210608152001;
SELECT * FROM db2inst1.EMPLOYEE;
OUTPUT ("/home/db2inst1/export/emp.del" REPLACE)
FORMAT DEL
;
EOF
$ db2hpu -f sample01.ctl
INZI466W 配置引數“use_stats”的值無效:將使用 NO。
INZM031I Optim High Performance Unload for DB2 for Linux, UNIX and Windows 05.01.00.001(140816) 64 位 2021年06月08日 (Linux host-170-130-106-206 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64)
INZI473I 記憶體限制:虛擬記憶體為 'unlimited' 且資料段為 'unlimited'
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----10---+----11---+----12---+----13-
000001 GLOBAL CONNECT TO SAMPLE ;
000002 UNLOAD TABLESPACE USERSPACE1
000003 USING BACKUP DATABASE SAMPLE FROM "/home/db2inst1/export/" ;
000004 SELECT * FROM db2inst1.EMPLOYEE;
000005 OUTPUT ("/home/db2inst1/export/emp.del" REPLACE)
000006 FORMAT DEL
000007 ;
INZU462I HPU 控制步驟開始: 15:22:39.126。
INZU420W DB2 YES 與從備份卸裝不相容,已轉換成 DB2 NO
INZU520W 為分割槽 0 指定的備份映像是“聯機”備份映像
INZU463I HPU 控制步驟結束: 15:22:39.211。
INZU464I HPU 執行步驟開始: 15:22:39.212。
INZU557I 卸裝中涉及分割槽 0 備份影象(獲取於 20210608152001)(型別 FULL ONLINE DATABASE,裝置 DISK)。
INZU410I HPU 實用程式已經卸裝 42 行(在 host-170-130-106-206 主機上,針對 DB2INST1.EMPLOYEE,在 /home/db2inst1/export/emp.del 中)。
INZU465I HPU 執行步驟結束: 15:22:39.514。
INZI441I HPU 成功結束:實時 -> 0m0.388620s
使用者時間 -> 0m0.023377s:父代 -> 0m0.023377s,子代 -> 0m0.000000s
系統時間 -> 0m0.320603s:父代 -> 0m0.320603s,子代 -> 0m0.000000s
4.2.3. 控制檔案語法參考
https://www.ibm.com/docs/en/iohpufdflu-and-w/6.1?topic=syntax-unload-block
4.3. 儲存過程
4.3.1. 建立儲存過程
HPU也可以以DB2 儲存過程的方式來執行
安裝完畢後,在如下目錄中可以找到建立儲存過程所需的檔案
$ ls -rlt /opt/ibm/HPU/V5.1/install/function
總用量 132
-rwxr-xr-x 1 root root 124581 8月 17 2014 db2hpuproc.so --動態庫檔案
-r-xr-xr-x 1 root root 5491 8月 17 2014 hpu_stored_proc_inst.sh --建立procedure的指令碼
通過例項使用者來執行指令碼建立HPU儲存過程:
建立語法:hpu_stored_proc_inst.sh <HPU INSTALL PATH> <Database Name>
[db2inst1@host-170-130-106-206] [/opt/ibm/HPU/V5.1/install/function]
$ ./hpu_stored_proc_inst.sh /opt/ibm/HPU/V5.1 sample
Copy file "db2hpuproc.so" to stored procedures directory
Connection to database "sample"
Creation of stored procedure in database "sample"
Disconnection from database "sample"
Ending of database use
檢視儲存過程
$ db2 "select substr(ROUTINESCHEMA,1,15) AS ROUTINESCHEMA,substr(ROUTINENAME,1,15) AS ROUTINENAME,ROUTINETYPE,VALID,CREATE_TIME,ALTER_TIME from syscat.routines where ROUTINETYPE = 'P' and ROUTINESCHEMA ='DB2INST1' and ROUTINENAME='DB2HPU'"
ROUTINESCHEMA ROUTINENAME ROUTINETYPE VALID CREATE_TIME ALTER_TIME
--------------- --------------- ----------- ----- -------------------------- --------------------------
DB2INST1 DB2HPU P 2021-06-08-15.31.01.417755 2021-06-08-15.31.01.417755
1 record(s) selected.
4.3.2. 呼叫儲存過程
--語法
db2 "call db2hpu('<HPU installation path>','<HPU command-line arguments>','<request to submit>','<HPU report>','<HPU return code>')
其中的引數官網解釋如下:
Where:
The
parameter represents the Optim High Performance Unload installation path and is expressed as a VARCHAR(512) string. The
parameter contains the Optim High Performance Unload command line arguments and is expressed as a CLOB(1024) string.
Theparameter represents the Optim High Performance Unload request and is expressed as a CLOB(64K) string. Use this parameter for what is normally included in a control file. The
parameter represents the Optim High Performance Unload report and is expressed as a CLOB(64K) string. This parameter is used for output purposes only. You need to specify it on the command line by using the question mark (?) character. The
parameter represents the Optim High Performance Unload return code and is expressed as an integer. This parameter is also used for output purposes only. You need to specify it on the command line by using the question mark (?) character.
呼叫儲存過程卸數,有兩種方式可以實現
- 觸發一個select 請求
- 觸發一個HPU unload請求
兩種方式的區別在於:如果客戶的需求可以用一個 select 語句來實現,則 select 請求只需在 <HPU command-line arguments>
中指定 -select 選項,並在<request to submit>
引數中指定這個 select 語句。否則,將需要提供一個完整的 HPU 請求。
觸發一個HPU unload請求
$ db2 connect to sample
Database Connection Information
Database server = DB2/LINUXX8664 10.1.3
SQL authorization ID = DB2INST1
Local database alias = SAMPLE
--觸發一個HPU unload請求
$ db2 "call db2hpu('/opt/ibm/HPU/V5.1', '-i db2inst1 -d sample -o /home/db2inst1/export/emp.out', 'unload tablespace db2 no select * from employee; format del;', ?, ?)"
Value of output parameters
--------------------------
Parameter Name : STDERR
Parameter Value : INZI466W 配置引數“use_stats”的值無效:將使用 NO。
INZM031I Optim High Performance Unload for DB2 for Linux, UNIX and Windows 05.01.00.001(140816) 64 位 2021年06月08日 (Linux host-170-130-106-206 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64)
INZI473I 記憶體限制:虛擬記憶體為 'unlimited' 且資料段為 'unlimited'
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----10---+----11---+----12---+----13-
000001 unload tablespace db2 no select * from employee; format del;
INZU462I HPU 控制步驟開始: 15:46:23.531。
INZU463I HPU 控制步驟結束: 15:46:23.544。
INZU464I HPU 執行步驟開始: 15:46:23.550。
INZU410I HPU 實用程式已經卸裝 42 行(在 host-170-130-106-206 主機上,針對 DB2INST1.EMPLOYEE,在 /home/db2inst1/export/emp.out 中)。
INZU465I HPU 執行步驟結束: 15:46:23.756。
INZI441I HPU 成功結束:實時 -> 0m0.225495s
使用者時間 -> 0m0.039064s:父代 -> 0m0.039064s,子代 -> 0m0.000000s
系統時間 -> 0m0.084047s:父代 -> 0m0.062503s,子代 -> 0m0.021544s
Parameter Name : RC
Parameter Value : 0
Return Status = 0
觸發一個select 請求
$ db2 "call db2hpu('/opt/ibm/HPU/V5.1', '-i db2inst1 -d sample -o /home/db2inst1/export/emp1.out -select', 'select * from employee', ?, ?)"
Value of output parameters
--------------------------
Parameter Name : STDERR
Parameter Value : INZI466W 配置引數“use_stats”的值無效:將使用 NO。
INZM031I Optim High Performance Unload for DB2 for Linux, UNIX and Windows 05.01.00.001(140816) 64 位 2021年06月08日 (Linux host-170-130-106-206 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64)
INZI473I 記憶體限制:虛擬記憶體為 'unlimited' 且資料段為 'unlimited'
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----10---+----11---+----12---+----13-
000001 select * from employee
INZU462I HPU 控制步驟開始: 16:43:45.431。
INZU463I HPU 控制步驟結束: 16:43:45.580。
INZU464I HPU 執行步驟開始: 16:43:45.581。
INZU410I HPU 實用程式已經卸裝 42 行(在 host-170-130-106-206 主機上,針對 DB2INST1.EMPLOYEE,在 /home/db2inst1/export/emp1.out 中)。
INZU465I HPU 執行步驟結束: 16:43:45.888。
INZI441I HPU 成功結束:實時 -> 0m0.457295s
使用者時間 -> 0m0.038746s:父代 -> 0m0.035555s,子代 -> 0m0.003191s
系統時間 -> 0m0.093540s:父代 -> 0m0.061630s,子代 -> 0m0.031910s
Parameter Name : RC
Parameter Value : 0
Return Status = 0
4.4. 資料遷移
DB2到DB2的資料遷移,我們通常的做法有:
表級別
- export ---> 網路傳輸介質 ---> import/load
庫級別
- db2look/db2move export --->網路傳輸介質 ---> db2move load
- backup --->網路傳輸介質 ---> restore/rollforward
HPU也可以實現將資料從一個DB2系統遷移至另一個DB2系統,包括資料庫級別、表空間級別以及表級別,且相比於以上列舉的方法,HPU的實現更為快速和高效。
使用HPU遷移的前提條件:
-
源系統和目標系統的HPU版本必須相同
-
源系統和目標系統必須能進行網路通訊
-
源系統和目標系統中 HPU 使用的網路埠必須一致
$ cat /etc/services|grep hpu db2hpudm51 54008/tcp # Optim HPU Services V5.1 [root@host-170-130-106-206] [/opt/ibm/HPU/V5.1/cfg] $ netstat -nltp|grep xinetd tcp6 0 0 :::54008 :::* LISTEN 31621/xinetd
-
目標系統上必須有和源系統上執行 HPU 的使用者相同的使用者名稱,並且此使用者能對目標系統中要操作的資料庫有 LOAD 許可權,要操作的表有 INSERT 許可權及其它相應的操作許可權
4.4.1. 實驗環境
項 | 源端 | 目標端 |
---|---|---|
IP | 170.130.106.206 | 170.130.106.214 |
例項 | db2inst1 | db2inst1 |
資料庫 | sample | target |
表 | EMPLOYEE | EMPLOYEE_T |
4.4.2. 建立目標表
預先在目標庫建立好表,這裡除了db2look,也可以使用HPU匯出DDL
$ cat > ddl.ctl << EOF
GLOBAL CONNECT TO SAMPLE ;
UNLOAD TABLESPACE
USING BACKUP DATABASE SAMPLE FROM "/home/db2inst1/export/" TAKEN AT 20210608152001;
SELECT * FROM db2inst1.EMPLOYEE;
OUTPUT ("/home/db2inst1/export/EMPLOYEE.del" REPLACE)
DDLFILE("/home/db2inst1/export/EMPLOYEE.ddl")
;
EOF
$ db2hpu -f ddl.ctl
INZI466W 配置引數“use_stats”的值無效:將使用 NO。
INZM031I Optim High Performance Unload for DB2 for Linux, UNIX and Windows 05.01.00.001(140816) 64 位 2021年06月08日 (Linux host-170-130-106-206 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64)
INZI473I 記憶體限制:虛擬記憶體為 'unlimited' 且資料段為 'unlimited'
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----10---+----11---+----12---+----13-
000001 GLOBAL CONNECT TO SAMPLE ;
000002
000003 UNLOAD TABLESPACE
000004 USING BACKUP DATABASE SAMPLE FROM "/home/db2inst1/export/" TAKEN AT 20210608152001;
000005 SELECT * FROM db2inst1.EMPLOYEE;
000006 OUTPUT ("/home/db2inst1/export/EMPLOYEE.del" REPLACE)
000007 DDLFILE("/home/db2inst1/export/EMPLOYEE.ddl")
000008 ;
INZU462I HPU 控制步驟開始: 18:20:11.777。
INZU420W DB2 YES 與從備份卸裝不相容,已轉換成 DB2 NO
INZU520W 為分割槽 0 指定的備份映像是“聯機”備份映像
INZU463I HPU 控制步驟結束: 18:20:11.822。
INZU464I HPU 執行步驟開始: 18:20:11.822。
INZU557I 卸裝中涉及分割槽 0 備份影象(獲取於 20210608152001)(型別 FULL ONLINE DATABASE,裝置 DISK)。
INZU410I HPU 實用程式已經卸裝 42 行(在 host-170-130-106-206 主機上,針對 DB2INST1.EMPLOYEE,在 /home/db2inst1/export/EMPLOYEE.del 中)。
INZU622I HPU 實用程式已經生成 DDL 檔案 /home/db2inst1/export/EMPLOYEE.ddl。
INZU465I HPU 執行步驟結束: 18:20:12.081。
INZI441I HPU 成功結束:實時 -> 0m0.304557s
使用者時間 -> 0m0.028983s:父代 -> 0m0.028983s,子代 -> 0m0.000000s
系統時間 -> 0m0.264076s:父代 -> 0m0.264076s,子代 -> 0m0.000000s
$ cat EMPLOYEE.ddl
CREATE TABLE "DB2INST1"."EMPLOYEE" (
"EMPNO" CHAR(6) NOT NULL ,
"FIRSTNME" VARCHAR(12) NOT NULL ,
"MIDINIT" CHAR(1) ,
"LASTNAME" VARCHAR(15) NOT NULL ,
"WORKDEPT" CHAR(3) ,
"PHONENO" CHAR(4) ,
"HIREDATE" DATE ,
"JOB" CHAR(8) ,
"EDLEVEL" SMALLINT NOT NULL ,
"SEX" CHAR(1) ,
"BIRTHDATE" DATE ,
"SALARY" DECIMAL(9,2) ,
"BONUS" DECIMAL(9,2) ,
"COMM" DECIMAL(9,2) )
;
--在目標資料庫中建立表
$ db2 connect to target
[db2inst1@host-170-130-106-214] [~]
$ db2 "CREATE TABLE "DB2INST1"."EMPLOYEE_T" (
> "EMPNO" CHAR(6) NOT NULL ,
> "FIRSTNME" VARCHAR(12) NOT NULL ,
> "MIDINIT" CHAR(1) ,
> "LASTNAME" VARCHAR(15) NOT NULL ,
> "WORKDEPT" CHAR(3) ,
> "PHONENO" CHAR(4) ,
> "HIREDATE" DATE ,
> "JOB" CHAR(8) ,
> "EDLEVEL" SMALLINT NOT NULL ,
> "SEX" CHAR(1) ,
> "BIRTHDATE" DATE ,
> "SALARY" DECIMAL(9,2) ,
> "BONUS" DECIMAL(9,2) ,
> "COMM" DECIMAL(9,2) )"
DB20000I The SQL command completed successfully.
$ db2 list tables;
Table/View Schema Type Creation time
------------------------------- --------------- ----- --------------------------
EMPLOYEE_T DB2INST1 T 2021-06-08-18.10.34.696381
4.4.3. 準備遷移控制檔案
這裡可以根據需要進行定製化,比如遷移多張表,或者篩選資料
cat > migrate.ctl << EOF
GLOBAL CONNECT TO SAMPLE
UMASK "022"
;
MIGRATE TABLESPACE
SELECT * FROM db2inst1.EMPLOYEE;
TARGET ENVIRONMENT(INSTANCE "db2inst1" on "170.130.106.214" IN target)
WORKING IN ("/home/db2inst1/export")
FORMAT MIGRATION into db2inst1.EMPLOYEE_T
;
EOF
4.4.4. 遷移資料
$ db2hpu -f migrate.ctl
INZI466W 配置引數“use_stats”的值無效:將使用 NO。
INZM031I Optim High Performance Unload for DB2 for Linux, UNIX and Windows 05.01.00.001(140816) 64 位 2021年06月08日 (Linux host-170-130-106-206 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64)
INZI473I 記憶體限制:虛擬記憶體為 'unlimited' 且資料段為 'unlimited'
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----10---+----11---+----12---+----13-
000001 GLOBAL CONNECT TO SAMPLE
000002 UMASK "022"
000003 ;
000004
000005 MIGRATE TABLESPACE
000006 SELECT * FROM db2inst1.EMPLOYEE;
000007 TARGET ENVIRONMENT(INSTANCE "db2inst1" on "170.130.106.214" IN target)
000008 WORKING IN ("/home/db2inst1/export")
000009 FORMAT MIGRATION into db2inst1.EMPLOYEE_T
000010 ;
INZU462I HPU 控制步驟開始: 18:26:31.474。
INZU463I HPU 控制步驟結束: 18:26:31.650。
INZU464I HPU 執行步驟開始: 18:26:31.660。
INZU398I 沒有卸裝要在 host-170-130-106-206 上完成
INZU543I HPU 實用程式將在 host-170-130-106-214 主機上執行裝入操作。
INZM031I [host-170-130-106-214] Optim High Performance Unload for DB2 for Linux, UNIX and Windows 05.01.00.001(140816) 64 位 2021年06月08日 (Linux host-170-130-106-214 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64)
INZM054I [host-170-130-106-214] HPU 實用程式將使用 umask 值 022。
INZU539I [host-170-130-106-214] HPU 實用程式已執行裝入(INSERT 方式)到 DB2INST1.EMPLOYEE_T(在資料庫 TARGET 中,此資料庫屬於例項 db2inst1)中的操作:在 /home/db2inst1/export/DB2INST1.EMPLOYEE_T.msg 中報告(已讀取 42,已跳過 0,已裝入 42,已拒絕 0,已刪除 0,已落實 42)
INZU465I HPU 執行步驟結束: 18:26:33.273。
INZI441I HPU 成功結束:實時 -> 0m1.799026s
使用者時間 -> 0m0.119623s:父代 -> 0m0.115451s,子代 -> 0m0.004172s
系統時間 -> 0m0.052782s:父代 -> 0m0.048610s,子代 -> 0m0.004172s
檢查目標環境資料
$ db2 connect to target
Database Connection Information
Database server = DB2/LINUXX8664 10.1.3
SQL authorization ID = DB2INST1
Local database alias = TARGET
$ db2 "select count(*) from employee_t"
1
-----------
42
1 record(s) selected.
4.4.5. 遇到的問題
控制檔案中指定的工作目錄WORKING IN ("/home/db2inst1/export")
必須在源端和目標端都存在,不存在則報如下錯誤
...
INZM054I [host-170-130-106-214] HPU 實用程式將使用 umask 值 022。
INZI347E [host-170-130-106-214] mkfifo 故障發生於 /home/db2inst1/export/out_USERSPACE1_DB2INST1_EMPLOYEE.000 (沒有那個檔案或目錄)
INZM053E HPU 主機上發生 host-170-130-106-214 遠端執行失敗
...
目標環境沒有給db2inst1使用者建立HPU工作憑證,報瞭如下錯。參照安裝章節中的工作憑證建立
...
INZM053E HPU 主機上發生 host-170-130-106-214 遠端執行失敗
INZU664E [host-170-130-106-214] 使用者 db2inst1 的目標例項 db2inst1 需要“local”型別的憑證。
...