11g Database Replay使用詳解
Database Replay將生產系統上的負荷進行採集後還原到測試系統上進行重放,這個特性有助於我們在資料庫升級、主機引數修改、資料庫引數修改等重大變更實施前在測試系統上完全仿照生產系統的負荷進行全面的測試,量化評估出變更實施後對現有的效能的影響程度。
Database Replay實施的流程是workload_capture->workload preprocess->replay client prepare->replay->generate replay report,對於同一個capture可以進行多次replay
實施過程中需要的伺服器如下:
生產資料庫伺服器:用於workload_capture,即負載捕獲
測試資料庫伺服器:用於workload_ preprocess和replay,即負載預處理和負載重放
Replay client:用於發起workload的客戶端程式
如果純粹是用於測試那麼生產資料庫、測試資料庫、Replay client可以指向同一臺機器。為了較為清晰的展示Database replay的整個過程,接下來的演示中我們會用到三臺主機:
Prod db Server:生產資料庫伺服器
Replay Client:用於發起workload的客戶端程式wrc
Replay db Server:測試資料庫伺服器
////////////////////////////////////////////////////////////////////////////
//1、 workload_capture階段,這些操作均在prod Server上執行
////////////////////////////////////////////////////////////////////////////
###建立capture dir,確保目錄下無任何檔案
mkdir -p /oradata06/repdir
create or replace directory repdir as '/oradata06/repdir';
###建立過濾器,過濾器中的內容是被包含還是排除,取決於capture是include還是exclude屬性,如果是include,那麼下面過濾器的內容將會被排除掉,此演示中將會採用include的capture所以我們過濾器中指定的是我們不需要的內容:排除掉OMS和emagent這兩個program;如果是exclusion屬性,那麼過濾器中的才是我們需要捕捉的,除此之外都會被排除;
exec dbms_workload_capture.add_filter(fname=>'filter_prog1',fattribute=>'PROGRAM',fvalue=>'%OMS%');
exec dbms_workload_capture.add_filter(fname=>'filter_prog2',fattribute=>'PROGRAM',fvalue=>'%emagent%');
col set_name format a20
col type format a10
col id format a20
col name format a15
col attribute format a15
col value format a18
set linesize 130
select * from dba_workload_filters;
TYPE ID STATUS SET_NAME NAME ATTRIBUTE VALUE
---------- -------------------- ------ -------------------- --------------- --------------- ------------------
CAPTURE NEW FILTER_PROG2 PROGRAM %emagent%
CAPTURE NEW FILTER_PROG1 PROGRAM %OMS%
###開啟workload capture之前,重啟資料庫到restricted模式->此步驟可選,為的是能一個不落的capture到所有session
shutdown immediate
startup restrict
###建立兩張測試表
create table tabfix1 (id1 number,id1_mod number);
declare
begin
for i in 1..100000 loop
insert into tabfix1 values (i,i+dbms_random.value(-2,2));
end loop;
commit;
end;
/
create table tabvar1 (vid1 number,vid1_mod number);
declare
begin
for i in 1..100000 loop
insert into tabvar1 values (i,i+dbms_random.value(-2,2));
end loop;
commit;
end;
/
###準備模擬負載執行指令碼s_cap1.sh、s_cap2.sh
---s_cap1.sh內容
while [ true ]
do
sqlplus system/xxxxxx@tstdb1 << EOF
update tabfix1 set id1_mod=id1_mod+dbms_random.value(-2,2) where id1<=50000;
commit;
select count(*) from tabfix1 where id1<=50000;
EOF
sleep 1
done
---s_cap2.sh內容
while [ true ]
do
sqlplus system/xxxxxx@tstdb1 << EOF
update tabvar1 set vid1_mod=vid1_mod+dbms_random.value(-2,2) where vid1_mod<=50000;
commit;
select count(*) from tabfix1 where id1<=50000;
EOF
sleep 1
done
###準備Replay db Server用於replay,將Replay db恢復到prod db Server開啟capture前的狀態,oracle推薦使用duplicate database、expdp & impdp、snapshot standby
三種方式,本演示中僅將上面兩張測試表匯入到replay db server
expdp system/xxxxxx tables=tabfix1,tabvar1 directory=hisdmp logfile=tabf.log dumpfile=tabf.dmp
scp /oradata01/hisdmp/monthly/tabf.dmp oracle@192.168.0.207:/oradata01/hisdmp/monthly/
impdp system/xxxxxx directory=hisdmp logfile=tabf.log dumpfile=tabf.dmp
###正式開啟workload capture,capture包括了filter_prog1、filter_prog2 兩個filter以外的所有內容,capture動作開始時自動解除restrict模式,以10分鐘為間隔同時捕捉sql tuning sets,STS可以在Replay報告比較階段生產更細化的效能資料
exec dbms_workload_capture.start_capture(name=>'v1026c1',dir=>'REPDIR',duration=>600,default_action=>'INCLUDE',auto_unrestrict=>TRUE,capture_sts=>TRUE,sts_cap_interval=>300);
###執行模擬負載指令碼
./s_cap1.sh
./s_cap2.sh
###capture期間可以檢視dba_workload_captures瞭解capture狀態
col name format a10
col status format a20
col sqlset_name format a25
set linesize 120
select id,name,status,duration_secs,awr_begin_snap,awr_end_snap,sqlset_name from dba_workload_captures;
ID NAME STATUS DURATION_SECS AWR_BEGIN_SNAP AWR_END_SNAP SQLSET_NAME
---------- ---------- -------------------- ------------- -------------- ------------ -------------------------
91 v1026c1 COMPLETED 597 131 132 v1026c1_c_9196364
###dba_sqlsets標示著此sqlset來自於id=91的capture
col description format a40
col owner format a10
col name format a20
set linesize 140
select * from dba_sqlset where name='v1026c1_c_9196364';
ID NAME OWNER DESCRIPTION CREATED LAST_MODIFIE STATEMENT_COUNT
---------- -------------------- ---------- ---------------------------------------- ------------ ------------ ---------------
8 v1026c1_c_9196364 SYSTEM STS capture for capture with ID=91 27-OCT-14 27-OCT-14 378
###停止workload capture->此步驟可選,如果start capture時沒有指定持續時間可以人工停止
exec dbms_workload_capture.finish_capture(timeout=>0);
###匯出capture期間的AWR資料->此步驟可選,如果之後要生成compare period report,即兩個replay的結果的比較報告或者replay與capture之間的比較報告,就要用到export_awr
select id from dba_workload_captures; --得到Capture_id
exec dbms_workload_capture.export_awr(capture_id=>91)
###生成capture階段報告到v1026c1.html檔案
set serveroutput on
spool /home/tstdb1/v1026c1.html
set long 200000
set pagesize 20000
DECLARE
v_cap_id NUMBER;
v_cap_rpt CLOB;
BEGIN
v_cap_id:=DBMS_WORKLOAD_CAPTURE.GET_CAPTURE_INFO(dir => 'REPDIR');
v_cap_rpt:=DBMS_WORKLOAD_CAPTURE.REPORT(capture_id =>v_cap_id,format => DBMS_WORKLOAD_CAPTURE.TYPE_HTML);
dbms_output.put_line(v_cap_rpt);
END;
/
spool off
###capture報告內容擷取如下:
主要包含了Capture Profile、Captured Workload Statistics、Top Events Captured、Top SQL Captured等內容
注:在/oradata06/repdir/cap目錄下其實已經存在wcr_cr.html、wcr_cr.text兩個檔案分別對應了html和txt版本的capture報告,拿來用即可
///////////////////////////
// 2、preprocess 階段
///////////////////////////
###先將capture file從prod db server複製到replay db server
scp -r /oradata06/repdir/* oracle@192.168.0.207:/oradata01/hisdmp/monthly/
***copy完成後replay db server主機上的目錄結構如下
ls -rlt /oradata01/hisdmp/monthly/
drwxr-xr-x 3 oracle oinstall 96 Oct 29 14:59 capfiles
drwxr-xr-x 2 oracle oinstall 8192 Oct 29 14:59 cap
-rw-r--r-- 1 oracle oinstall 0 Oct 29 16:00 wcr_cap_0002x.start
-rw-r--r-- 1 oracle oinstall 0 Oct 29 16:00 wcr_cap_0002w.start
###在replay db server上進行preprocess
exec dbms_workload_replay.process_capture(capture_dir=>'HISDMP');
###preprocess完成後在replay db server的/oradata01/hisdmp/monthly/目錄下生成了pp11.2.0.3.0子目錄
oracle@jq570322a:/oradata01/hisdmp/monthly>ls -rlt pp11.2.0.3.0
total 432
-rw-r----- 1 oracle oinstall 28672 Oct 29 16:03 wcr_seq_data.extb
-rw-r----- 1 oracle oinstall 28672 Oct 29 16:03 wcr_scn_order.extb
-rw-r--r-- 1 oracle oinstall 25787 Oct 29 16:03 wcr_login.pp
-rw-r----- 1 oracle oinstall 12288 Oct 29 16:03 wcr_conn_data.extb
-rw-r----- 1 oracle oinstall 12288 Oct 29 16:03 wcr_data.extb
-rw-r----- 1 oracle oinstall 16384 Oct 29 16:03 wcr_references.extb
-rw-r--r-- 1 oracle oinstall 35 Oct 29 16:03 wcr_process.wmd
-rw-r----- 1 oracle oinstall 36864 Oct 29 16:03 wcr_dep_graph.extb
-rw-r----- 1 oracle oinstall 12288 Oct 29 16:03 wcr_commits.extb
-rw-r--r-- 1 oracle oinstall 3510 Oct 29 16:03 wcr_calibrate.xml
這些檔案主要是對capfiles目錄下.rec檔案進行彙總,在之後的replay階段起到索引的作用。其中wcr_calibrate.xml是對replay時發起replay client數量的預估結果,內容如下:
///////////////////////////////
//3、 replay client準備階段
///////////////////////////////
###準備replay clients環境,replay clients主要作用是模擬客戶端連線到test database發起壓力測試
首先,執行replay clients的主機至少要安裝oracle client;
replay client主機上的sqlnet.ora必須包含有DIAG_ADR_ENABLED=ON,否則會收到ORA-15555 "workload replay client encountered unexpected error: %s錯誤
###在replay db server上執行:將capture及preprocess的結果copy到執行replay clients,需要指出的是這裡不僅要將preprocess的結果copy過去,還要將cap,capfiles兩個目錄一起copy到replay clients主機
scp -r /oradata01/hisdmp/monthly/pp11.2.0.3.0 oracle@192.168.0.221:/oradata01/hisdmp/monthly
scp -r /oradata01/hisdmp/monthly/cap oracle@192.168.0.221:/oradata01/hisdmp/monthly
scp -r /oradata01/hisdmp/monthly/capfiles oracle@192.168.0.221:/oradata01/hisdmp/monthly
###解釋一下為何cap、capfiles目錄也要一起copy過去
原因很簡單在preprocess生成一堆檔案相當於給負載編制好的一套目錄,其中有個wcr_login.pp檔案記錄了capture階段生成的所有.rec檔案,一個session登陸後就生成一個.rec檔案,用strings命令可以清楚的看到:
strings /oradata01/hisdmp/monthly/pp11.2.0.3.0/wcr_login.pp | grep .rec | head -n 10
wcr_4wd4rh0000000.rec
wcr_4wd4sh0000003.rec
wcr_4wd4th0000004.rec
wcr_4wd4uh0000006.rec
wcr_4wd4uh0000007.rec
wcr_4wd4vh0000009.rec
以上每一個檔案都能在/oradata01/hisdmp/monthly/capfiles/inst1/目錄下找到,負載重放時會到此目錄下讀取對應的檔案,如果僅將pp11.2.0.3.0目錄copy過去在replay Client執行wrc的時候會出現:ORA-15559: workload replay client cannot open workload capture file
###每個客戶端可以模擬出多個session,calibrate 模式下使用wrc可以根據捕捉到的workload資訊估算出需要發起多少個Replay client,在replay client上執行:
wrc mode=calibrate replaydir=/oradata01/hisdmp/monthly
Workload Replay Client: Release 11.2.0.3.0 - Production on Wed Oct 29 15:07:23 2014
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Report for Workload in: /oradata01/hisdmp/monthly
-----------------------
Recommendation:
Consider using at least 1 clients divided among 1 CPU(s)
You will need at least 15 MB of memory per client process.
If your machine(s) cannot match that number, consider using more clients.
Workload Characteristics:
- max concurrency: 4 sessions
- total number of sessions: 313
Assumptions:
- 1 client process per 50 concurrent sessions
- 4 client process per CPU
- 256 KB of memory cache per concurrent session
- think time scale = 100
- connect time scale = 100
- synchronization = TRUE
/////////////////////////////////////////////////
// 4、replay 階段,在replay db server上執行
/////////////////////////////////////////////////
###initialize replay,生成新的replay資訊,同時會將將replay_dir目錄下的capture資訊、之前已經存在的replay資訊一併匯入到資料庫,可以透過dba_workload_replays、dba_workload_connection_map、dba_workload_filters等檢視檢視
exec dbms_workload_replay.initialize_replay(replay_name=>'v1028r1',replay_dir=>'HISDMP'); --replay_dir指定的是包含有preprocess data及capture data的目錄
***replay狀態為initialized
col name format a30
set linesize 120
select id,name,status from dba_workload_replays;
ID NAME STATUS
---------- ------------------------------ ----------------------------------------
24 v1028r1 INITIALIZED
###設定Replay時的filter->此為可選步驟
利用capture到的負載進行replay時如果要過濾掉部分sql,可以按照如下步驟,建立filter,過濾掉程式名包含emagent、perl的session
exec dbms_workload_replay.add_filter(fname=>'v1028f1',fattribute=>'PROGRAM',fvalue=>'%emagent%');
exec dbms_workload_replay.add_filter(fname=>'v1028f1_1',fattribute=>'PROGRAM',fvalue=>'%perl%');
***dba_workload_filter看到TYPE=REPLAY型別的filter,過濾掉program=perl或者emagent的session
col set_name format a20
col type format a10
col id format a20
col name format a15
col attribute format a15
col value format a18
set linesize 130
select * from dba_workload_filters;
TYPE ID STATUS SET_NAME NAME ATTRIBUTE VALUE
---------- -------------------- ------ -------------------- --------------- --------------- ------------------
CAPTURE 34 USED FILTER_PROG2 PROGRAM %emagent%
CAPTURE 34 USED FILTER_PROG1 PROGRAM %OMS%
REPLAY NEW V1028F1 CONNECTION_STRI %(PROGRAM=%emagent
NG %)%
REPLAY NEW V1028F1_1 CONNECTION_STRI %(PROGRAM=%perl%)%
NG
***將前面建立的filter加入到Filter_set,入參裡沒有指定filter_name,預設是把上一次create_filter_set執行後使用add_filter新增的所有filter加入到該filter_set內
exec dbms_workload_replay.create_filter_set(replay_dir=>'HISDMP',filter_set=>'v1028fs1',default_action=>'INCLUDE');
*** dba_workload_filters裡type=REPLAY的filter狀態從NEW變為了IN SET,表示已經加入到filter Set裡了,ID列為空說明還未被任何replay使用
select * from dba_workload_filters;
TYPE ID STATUS SET_NAME NAME ATTRIBUTE VALUE
---------- -------------------- ---------- -------------------- --------------- --------------- ------------------
CAPTURE 34 USED FILTER_PROG2 PROGRAM %emagent%
CAPTURE 34 USED FILTER_PROG1 PROGRAM %OMS%
REPLAY IN SET v1028fs1 V1028F1_1 CONNECTION_STRI %(PROGRAM=%perl%)%
NG
REPLAY IN SET v1028fs1 V1028F1 CONNECTION_STRI %(PROGRAM=%emagent
NG %)%
---使用名為v1028fs1的filter set過濾接下來的replay,type=REPLAY行的ID=24,status=IN USE說明這個filter_set正在被replay所使用
exec dbms_workload_replay.use_filter_set(filter_set=>'v1028fs1');
col set_name format a20
col type format a10
col id format a20
col name format a15
col attribute format a15
col value format a18
set linesize 130
select * from dba_workload_filters;
TYPE ID STATUS SET_NAME NAME ATTRIBUTE VALUE
---------- -------------------- ---------- -------------------- --------------- --------------- ------------------
CAPTURE 34 USED FILTER_PROG2 PROGRAM %emagent%
CAPTURE 34 USED FILTER_PROG1 PROGRAM %OMS%
REPLAY 24 IN USE v1028fs1 V1028F1 CONNECTION_STRI %(PROGRAM=%emagent
NG %)%
REPLAY 24 IN USE v1028fs1 V1028F1_1 CONNECTION_STRI %(PROGRAM=%perl%)%
NG
###replay之前檢查capture裡包含的連線串資訊
***capture內容裡的連線串還是指向production database,在replay之前需要重定向到test database
col capture_conn format a50
set linesize 120 pagesize 120
select * from dba_workload_connection_map;
REPLAY_ID CONN_ID CAPTURE_CONN
---------- ---------- --------------------------------------------------
REPLAY_CONN
------------------------------------------------------------------------------------------------------------------------
24 1 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.10.14
1.209)(PORT=1521))(CONNECT_DATA=(SID=tstdb1)(CID=(
PROGRAM=E:\Program?Files??x86?\PLSQL?Developer\pls
qldev.exe)(HOST=CHHHHC)(USER=CHH))))
24 2 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.10.14
1.209)(PORT=1521))(CONNECT_DATA=(SID=tstdb1)(SERVE
R=DEDICATED)(CID=(PROGRAM=sqlplus)(HOST=jq570322b)
(USER=tstdb1))))
24 3 (DESCRIPTION=(CONNECT_DATA=(SID=tstdb1)(CID=(PROGR
AM=perl@jq570322b)(HOST=jq570322b)(USER=oracle)))(
ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.209)(Port=15
21)))
###可選步驟:對於capture階段捕捉到的連線串資訊可以在Replay階段將這些連線資訊重新對映到其它資料庫,例如下面的例子中將connect_id=1、2、3的連線串分別對映到test1、test2、test3對應的資料庫
exec DBMS_WORKLOAD_REPLAY.REMAP_CONNECTION(connection_id=>1,replay_connection=>'test1');
exec DBMS_WORKLOAD_REPLAY.REMAP_CONNECTION(connection_id=>2,replay_connection=>'test2');
exec DBMS_WORKLOAD_REPLAY.REMAP_CONNECTION(connection_id=>3,replay_connection=>'test3');
***重新對映連線串後,replay_conn顯示replay client時使用的連線串
col replay_conn format a15
select replay_id,conn_id,capture_conn,REPLAY_CONN from dba_workload_connection_map;
REPLAY_ID CONN_ID CAPTURE_CONN REPLAY_CONN
---------- ---------- -------------------------------------------------- ---------------
24 1 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.10.14 test1
1.209)(PORT=1521))(CONNECT_DATA=(SID=tstdb1)(CID=(
PROGRAM=E:\Program?Files??x86?\PLSQL?Developer\pls
qldev.exe)(HOST=CHHHHC)(USER=CHH))))
24 2 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.10.14 test2
1.209)(PORT=1521))(CONNECT_DATA=(SID=tstdb1)(SERVE
R=DEDICATED)(CID=(PROGRAM=sqlplus)(HOST=jq570322b)
(USER=tstdb1))))
24 3 (DESCRIPTION=(CONNECT_DATA=(SID=tstdb1)(CID=(PROGR test3
AM=perl@jq570322b)(HOST=jq570322b)(USER=oracle)))(
ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.209)(Port=15
21)))
注意test1、test2、test3必須在replay client端能夠tnsping通這些別名,或者乾脆使用"(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.209)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=shzw)))"這種顯示指定的方法來實現重對映
但在實際使用時發現connection_remap特性無法正常用起來,在Replay client側發起客戶端連線程式的時候報ORA-15561錯誤
oracle@jq570314a:/oradata01/hisdmp/monthly>wrc system/XXXXXX@test mode=replay replaydir=/oradata01/hisdmp/monthly
Workload Replay Client: Release 11.2.0.3.0 - Production on Wed Oct 29 09:36:47 2014
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Errors in file :
ORA-15561: workload replay client cannot connect to the remapped connection with conn_id : 1
要規避這個錯誤按照MOS 1135960.1的做法是在wrc命令里加上CONNECTION_OVERRIDE=TRUE引數,使用wrc命令裡自帶的連線串指向test database,但這個做法的問題在於只能將多個capture連線串重定義到同一個replay連線串,無法為每個capture連線串指定各自不同replay連線串
###prepare replay,控制replay的引數設定,synchronization=>'OBJECT_ID'針對於DML操作,在維持同一個物件前後事務依賴性的前提下,必要時會略微調整DML語句的執行順序(調整不會影響語句結果),特別是在多個事務併發操作不同的物件時,相比synchronization=>'SCN'更能提高replay期間DML的執行效率,capture_sts=>TRUE會在replay時同時生成STS
exec dbms_workload_replay.prepare_replay(synchronization=>'OBJECT_ID',capture_sts=>TRUE,sts_cap_interval=>300);
***prepare後在replay_dir下生成了一個repXXX開頭的目錄,其中XXX是oracle為每個replay分配的唯一標識,可以在dba_workload_replays檢視的replay_dir_number欄位中查到
drwxr-xr-x 3 oracle oinstall 96 Oct 29 14:59 capfiles
-rw-r--r-- 1 oracle oinstall 0 Oct 29 16:00 wcr_cap_0002x.start
-rw-r--r-- 1 oracle oinstall 0 Oct 29 16:00 wcr_cap_0002w.start
drwxr-xr-x 2 oracle oinstall 8192 Oct 29 16:03 pp11.2.0.3.0
drwxr-xr-x 2 oracle oinstall 8192 Oct 30 09:48 cap
drwxr-xr-x 2 oracle oinstall 96 Oct 30 10:17 filter11.2.0.3.0
drwxr-xr-x 2 oracle oinstall 96 Oct 30 10:20 rep423075657
set linesize 140
select name,replay_dir_number from dba_workload_replays
NAME REPLAY_DIR_NUMBER
---------------------------------------------------------------------------------------------------- -----------------
v1028r1 423075657
***replay任務的狀態變為了prepare
col name format a30
set linesize 120
select id,name,status from dba_workload_replays;
ID NAME STATUS
---------- ------------------------------ ----------------------------------------
24 v1028r1 PREPARE
###在replay client所在主機發起replay client,這時客戶端提示等待start_replay發起,使用CONNECTION_OVERRIDE覆蓋掉dba_workload_connection_map設定,規避掉ORA-15561錯誤
wrc system/xxxxxx@test mode=replay CONNECTION_OVERRIDE=TRUE REPLAYDIR=/oradata01/hisdmp/monthly
Wait for the replay to start (10:24:23)
###在replay db server執行:開啟replay
exec DBMS_WORKLOAD_REPLAY.START_REPLAY;
###replay client主機立刻顯示replay開始
Wait for the replay to start (10:24:23)
Replay started (10:24:43)
###replay期間主要透過v$workload_replay_thread檢視觀察進展情況,檢視裡顯示了每個session當前正在處理哪一個capture file以及當前所耗費的dbtime等資訊
col event format a40
col file_name format a30
set linesize 130
select sid,session_type,event,file_name,dbtime from v$workload_replay_thread where session_type='REPLAY';
SID SESSION_TYPE EVENT FILE_NAME DBTIME
---------- ------------- ---------------------------------------- ------------------------------ ----------
1912 REPLAY Disk file operations I/O wcr_4wdmch000008b.rec 74599
3303 REPLAY SQL*Net message from client wcr_4wdhyh000006k.rec 69859
3775 REPLAY SQL*Net message from client wcr_4wdhnh0000069.rec 87932
5658 REPLAY Disk file operations I/O wcr_4wdmch000008c.rec 73601
7080 REPLAY null event wcr_4wd59h000000t.rec 0
###至此一個完整的replay完成,為了輔助講解後面的compare period report,我們又進行了一次replay,產生一個id=26的replay
select id,name,status,start_time,end_time from dba_workload_replays;
ID NAME STATUS START_TIME END_TIME
---------- ---------- ---------- ----------------- -----------------
24 v1028r1 COMPLETED 20141030 10:23:37 20141030 10:33:36
26 v1028r2 COMPLETED 20141030 12:16:00 20141030 12:26:00
////////////////////////////
//5、生成replay報告
////////////////////////////
Replay報告有幾種,本文主要介紹replay report、compare period report兩種。
replay reports將replay執行時的效能統計資訊列出來,並與capture作簡單的比較
compare period report側重於在兩個不同的replay之間,或者replay和capture之間從資料庫引數配置、主機硬體環境、Top SQL耗用資源等方面形成全方位的診斷報告
###生成replay report
set serveroutput on
spool /home/oracle/v1028r1.html
set pagesize 20000
set long 200000
declare
v_offset number;
v_length number;
v_nowlength number;
v_char1 varchar2(32767);
v_reprpt clob;
begin
v_reprpt:=dbms_workload_replay.report(replay_id=>24,format=>dbms_workload_replay.TYPE_HTML);
v_nowlength:=1;
v_length:=dbms_lob.getlength(lob_loc=>v_reprpt);
v_offset:=1;
while ( v_offset < v_length ) loop
v_char1:=dbms_lob.substr(lob_loc=>v_reprpt,offset=>v_offset);
dbms_output.put_line(v_char1);
v_offset:=v_offset+32767;
end loop;
end;
/
spool off
###生成的replay報告主要包括replay information、options、statistics、divergence等資訊,也會包含細化到SQL語句的負載分析
截圖如下:
上圖中Replay Divergence Summary用來反應replay和capture階段執行SQL時遇到的錯誤次數,這些錯誤是否僅在replay還是capture階段出現;DML或SELECT語句返回記錄數是否不一致的情況等
上圖對於SQL語句按照負荷從高到低進行排序,並對這些負荷的分佈進行breakdown
###生成compare period report
select id,name,status,start_time,end_time from dba_workload_replays;
ID NAME STATUS START_TIME END_TIME
---------- ---------- ---------- ----------------- -----------------
24 v1028r1 COMPLETED 20141030 10:23:37 20141030 10:33:36
26 v1028r2 COMPLETED 20141030 12:16:00 20141030 12:26:00
###將之前生成的id=24、id=26兩個replay形成比較報告之前需要從prod db server上將capture階段的AWR負載export出來,import到replay db server中,以下在product database上實施export_awr操作
exec DBMS_WORKLOAD_CAPTURE.EXPORT_AWR(capture_id=>91);
###在prod db server上執行:將export_awr匯出的檔案傳輸到replay db server,以下標紅的檔案都要複製到replay db server
oracle@jq570322b:/oradata06/repdir/cap>ls -rlt
total 28336
-rw-r--r-- 1 oracle oinstall 162 Oct 27 20:03 wcr_scapture.wmd
-rw-r----- 1 oracle oinstall 268 Oct 27 20:14 wcr_fcapture.wmd
-rw-r----- 1 oracle oinstall 46708 Oct 27 20:14 wcr_cr.html
-rw-r----- 1 oracle oinstall 19196 Oct 27 20:14 wcr_cr.text
-rw-r----- 1 oracle oinstall 29141 Oct 30 09:36 wcr_ca.log
-rw-r----- 1 oracle oinstall 12222464 Oct 30 09:36 wcr_ca.dmp
-rw-r----- 1 oracle oinstall 12288 Oct 30 09:36 wcr_cap_uc_graph.extb
-rw-r----- 1 oracle oinstall 2146304 Oct 30 09:36 wcr_ca_sts.dmp
scp /oradata06/repdir/cap/wcr_ca.log oracle@192.168.0.207:/oradata01/hisdmp/monthly/cap/
scp /oradata06/repdir/cap/wcr_ca.dmp oracle@192.168.0.207:/oradata01/hisdmp/monthly/cap/
scp /oradata06/repdir/cap/wcr_cap_uc_graph.extb oracle@192.168.0.207:/oradata01/hisdmp/monthly/cap/
scp /oradata06/repdir/cap/wcr_ca_sts.dmp oracle@192.168.0.207:/oradata01/hisdmp/monthly/cap/
***replay db server上操作:將上述export_awr的結果透過函式DBMS_WORKLOAD_CAPTURE.IMPORT_AWR匯入到replay db server,DBMS_WORKLOAD_CAPTURE.IMPORT_AWR的返回值是隨機生成的DBID,可以在dba_workload_captures.awr_dbid裡找到
var v_randbid number;
exec :v_randbid:=DBMS_WORKLOAD_CAPTURE.IMPORT_AWR(capture_id=>34,staging_schema=>'SYSTEM',force_cleanup=>FALSE);
print :v_randbid;
V_RANDBID
----------
383379053
select id,name,status,start_time,end_time,dir_path,awr_dbid,awr_begin_snap,awr_end_snap from dba_workload_captures;
ID NAME STATUS START_TIME END_TIME DIR_PATH AWR_DBID AWR_BEGIN_SNAP AWR_END_SNAP
---------- --------------- ---------- ----------------- ----------------- -------------------- ---------- -------------- ------------
34 v1026c1 COMPLETED 20141027 20:03:35 20141027 20:13:32 /oradata01/hisdmp/mo 383379053 131 132
nthly
***dba_hist_snapshot裡可以看到AWR負載已經匯入
col begin_interval_time format a30
col end_interval_time format a30
set linesize 120
select snap_id,dbid,begin_interval_time,end_interval_time from dba_hist_snapshot where dbid=383379053;
SNAP_ID DBID BEGIN_INTERVAL_TIME END_INTERVAL_TIME
---------- ---------- ------------------------------ ------------------------------
131 383379053 27-OCT-14 08.00.35.987 PM 27-OCT-14 08.03.32.072 PM
132 383379053 27-OCT-14 08.03.32.072 PM 27-OCT-14 08.14.02.139 PM
###生成兩個replay間的比較報告輸出到v1028r1r2.html檔案
set serveroutput on
spool /home/oracle/v1028r1r2.html
declare
v_rlt clob;
v_replay_id1 number:=24;
v_replay_id2 number:=26;
v_snum number:=1;
v_length number;
v_char varchar2(32767);
begin
dbms_workload_replay.compare_period_report(replay_id1=>v_replay_id1,replay_id2=>v_replay_id2,format=>'HTML',result=>v_rlt);
v_length:=dbms_lob.GETLENGTH(v_rlt);
while ( v_snum < v_length ) loop
v_char:=dbms_lob.substr(lob_loc=>v_rlt,amount=>32767,offset=>v_snum);
v_snum:=v_snum+32767;
dbms_output.put_line(v_char);
end loop;
end;
/
spool off
###生成的compare period report從hardware、top sql、Divergence等維度比對兩次replay的結果
###如果要進行更細化的針對每條sql語句的分析,可以使用dbms_workload_replay.compare_sqlset_report函式,其實質是利用SPA對於兩次replay期間生成的STS進行分析,函式dbms_workload_replay.compare_sqlset_report返回值是task_name,在dba_advisor_tasks中能夠查到
set serveroutput on
spool /home/oracle/v1028r1r2_spa.html
declare
v_rlt clob;
v_replay_id1 number:=26;
v_replay_id2 number:=24;
v_snum number:=1;
v_length number;
v_char varchar2(32767);
v_ret varchar2(32767);
begin
v_ret:=dbms_workload_replay.compare_sqlset_report(replay_id1=>v_replay_id1,replay_id2=>v_replay_id2,format=>'HTML',result=>v_rlt);
v_length:=dbms_lob.GETLENGTH(v_rlt);
while ( v_snum < v_length ) loop
v_char:=dbms_lob.substr(lob_loc=>v_rlt,amount=>32767,offset=>v_snum);
v_snum:=v_snum+32767;
dbms_output.put_line(v_char);
end loop;
dbms_output.put_line(v_ret);
end;
/
spool off
###SPA報告截圖如下
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8494287/viewspace-1411711/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle 11g Database Replay 實驗OracleDatabase
- Oracle Database ReplayOracleDatabase
- oracle rat database replayOracleDatabase
- database replay基礎學習Database
- 資料庫負荷重放(Database replay)資料庫Database
- HTTP流量神器Goreplay核心原始碼詳解HTTPGo原始碼
- Oracle 資料庫重放(Database Replay)功能演示Oracle資料庫Database
- 執行database replay進行升級測試Database
- goreplay 使用教程Go
- Oracle database link 詳解OracleDatabase
- Oracle 11g Data Guard 使用 duplicate from active database 建立 standby databaseOracleDatabase
- Oracle 11g Data Guard 使用duplicate from active database 建立 standby databaseOracleDatabase
- Replaykit2(IOS11+)視訊錄製詳解iOS
- Database Capture and Replay: Common Errors and Reasons (文件 ID 463263.1)DatabaseAPTError
- DATABASE REPLAY加壓播放引數之SCALE_UP_MULTIPLIERDatabase
- Oracle 11g Data Guard 使用duplicate from active databaseOracleDatabase
- 使用Oracle Database 11g建立Interval分割槽表OracleDatabase
- 11g 新特性—— Active Database Duplication for A standby databaseDatabase
- Oracle 11G Duplicate DatabaseOracleDatabase
- 資料庫分片(Database Sharding)詳解資料庫Database
- OGG 11g Checkpoint 詳解
- oracle 11g streams 配置詳解Oracle
- Use Database Replay Feature to Help With Upgrade From 10.2.0.4 to 11g_748895.1Database
- Oracle Database 11g Launch WebcastOracleDatabaseWebAST
- TcpreplayTCP
- 11g rman新特性 duplicate target database for standby from active databaseDatabase
- 解決Aireplay-ng通道問題AI
- 11g 新特性—— Active Database DuplicationDatabase
- Oracle 11g Rman Active database duplicateOracleDatabase
- Oracle Database 11g索引技術OracleDatabase索引
- Cursor Sharing in Oracle Database 11gOracleDatabase
- Oracle Database 12.2新特性詳解 --該國強OracleDatabase
- 使用oracle 11g rman新特性 duplicate target database for standby from active database 建立物理dataguard並開啟RealOracleDatabase
- Oracle 11g Database靜默安裝OracleDatabase
- Jpa使用詳解
- mitmproxy使用詳解MIT
- Thymeleaf使用詳解
- mydumper使用詳解