11g Database Replay使用詳解

dbhelper發表於2015-01-23

Database Replay將生產系統上的負荷進行採集後還原到測試系統上進行重放,這個特性有助於我們在資料庫升級、主機引數修改、資料庫引數修改等重大變更實施前在測試系統上完全仿照生產系統的負荷進行全面的測試,量化評估出變更實施後對現有的效能的影響程度。

Database Replay實施的流程是workload_capture->workload preprocess->replay client prepare->replay->generate replay report,對於同一個capture可以進行多次replay

實施過程中需要的伺服器如下:

生產資料庫伺服器:用於workload_capture,即負載捕獲

測試資料庫伺服器:用於workload_ preprocessreplay,即負載預處理和負載重放

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';

###建立過濾器,過濾器中的內容是被包含還是排除,取決於captureinclude還是exclude屬性,如果是include,那麼下面過濾器的內容將會被排除掉,此演示中將會採用includecapture所以我們過濾器中指定的是我們不需要的內容:排除掉OMSemagent這兩個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.shs_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 databaseexpdp & impdpsnapshot 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 capturecapture包括了filter_prog1filter_prog2 兩個filter以外的所有內容,capture動作開始時自動解除restrict模式,以10分鐘為間隔同時捕捉sql tuning setsSTS可以在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=91capture

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的結果的比較報告或者replaycapture之間的比較報告,就要用到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 ProfileCaptured Workload StatisticsTop Events CapturedTop SQL Captured等內容

注:在/oradata06/repdir/cap目錄下其實已經存在wcr_cr.htmlwcr_cr.text兩個檔案分別對應了htmltxt版本的capture報告,拿來用即可

 

///////////////////////////

// 2preprocess 階段

///////////////////////////

###先將capture fileprod 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數量的預估結果,內容如下:

 

    v1026c1

    2028908302

    TSTDB1

    11.2.0.3.0

    NO

    HISDMP

    /oradata01/hisdmp/monthly

    TRUE

    COMPLETED

    27-10-14 20:03:35

    27-10-14 20:13:32

    9 minutes 57 seconds

    3022402

    3088331

    INCLUDE

    2

    1096881

    534902718

    .9

    605738506

    7939

    9345

    1222

    286

    469

    312

    370

    2

    NOT POSSIBLE

    0

    11.2.0.3.0

 

  11.2.0.3.0

 

    4

    50

 

 

    4

    313

    1

    1

    15

 

///////////////////////////////

//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上執行:將capturepreprocess的結果copy到執行replay clients,需要指出的是這裡不僅要將preprocess的結果copy過去,還要將capcapfiles兩個目錄一起copyreplay 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

###解釋一下為何capcapfiles目錄也要一起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

###每個客戶端可以模擬出多個sessioncalibrate 模式下使用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

/////////////////////////////////////////////////

// 4replay 階段,在replay db server上執行

/////////////////////////////////////////////////

###initialize replay,生成新的replay資訊,同時會將將replay_dir目錄下的capture資訊、之前已經存在的replay資訊一併匯入到資料庫,可以透過dba_workload_replaysdba_workload_connection_mapdba_workload_filters等檢視檢視

exec dbms_workload_replay.initialize_replay(replay_name=>'v1028r1',replay_dir=>'HISDMP');  --replay_dir指定的是包含有preprocess datacapture 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,過濾掉程式名包含emagentperlsession

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或者emagentsession              

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_filterstype=REPLAYfilter狀態從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              %)%

---使用名為v1028fs1filter set過濾接下來的replaytype=REPLAY行的ID=24status=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=123的連線串分別對映到test1test2test3對應的資料庫

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)))

                      

注意test1test2test3必須在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開頭的目錄,其中XXXoracle為每個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=26replay

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 reportcompare period report兩種。

replay reportsreplay執行時的效能統計資訊列出來,並與capture作簡單的比較

compare period report側重於在兩個不同的replay之間,或者replaycapture之間從資料庫引數配置、主機硬體環境、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 informationoptionsstatisticsdivergence等資訊,也會包含細化到SQL語句的負載分析

截圖如下:

上圖中Replay Divergence Summary用來反應replaycapture階段執行SQL時遇到的錯誤次數,這些錯誤是否僅在replay還是capture階段出現;DMLSELECT語句返回記錄數是否不一致的情況等

上圖對於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=24id=26兩個replay形成比較報告之前需要從prod db server上將capture階段的AWR負載export出來,importreplay 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 serverDBMS_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 reporthardwaretop sqlDivergence等維度比對兩次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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章