您好,登錄后才能下訂單哦!
我們都知道Oracle的AWR報(bào)告是一個(gè)很強(qiáng)大的功能通過分析AWR報(bào)告可以打出Oracle數(shù)據(jù)運(yùn)行過程中出現(xiàn)的問題和可能存在的隱患。但是AWR報(bào)告中沒有關(guān)于單個(gè)SQL執(zhí)行計(jì)劃、統(tǒng)計(jì)信息的詳細(xì)描述,但不代表AWR不能提供這種功能。
本文介紹的是如何使用AWR報(bào)告生成一條sql的詳細(xì)執(zhí)行統(tǒng)計(jì)報(bào)告。
實(shí)驗(yàn)環(huán)境11.2.0.4
1、調(diào)整AWR關(guān)于SQL收集的設(shè)置,調(diào)整的目的是因?yàn)槟J(rèn)情況下AWR并非捕獲所有的sql語句,此調(diào)整是為了讓AWR可以收集實(shí)驗(yàn)過程中的SQL語句
zx@ORCL>select * from dba_hist_wr_control; DBID SNAP_INTERVAL RETENTION TOPNSQL ---------- --------------------------------------------------------------------------- --------------------------------------------------------------------------- ------------------------------ 1444351641 +00000 01:00:00.0 +00008 00:00:00.0 DEFAULT zx@ORCL>exec dbms_workload_repository.modify_snapshot_settingS(topnsql=>'MAXIMUM'); PL/SQL procedure successfully completed. zx@ORCL>select * from dba_hist_wr_control; DBID SNAP_INTERVAL RETENTION TOPNSQL ---------- --------------------------------------------------------------------------- --------------------------------------------------------------------------- ------------------------------ 1444351641 +00000 01:00:00.0 +00008 00:00:00.0 MAXIMUM
2、手工創(chuàng)建一個(gè)AWR快照
zx@ORCL>exec dbms_workload_repository.create_snapshot; PL/SQL procedure successfully completed.
3、創(chuàng)建測試表并在不同情況下執(zhí)行測試sql,并找到測試sql的sql_id
zx@ORCL>create table t as select * from dba_objects; Table created. zx@ORCL>create unique index idx_unique_t on t(object_id); Index created. zx@ORCL>exec dbms_stats.gather_table_stats(USER,'T',CASCADE=>TRUE); PL/SQL procedure successfully completed. zx@ORCL>select object_name from t where object_id=123; OBJECT_NAME ------------------------------ ECOL$ zx@ORCL>select sql_id,sql_text from v$sql where sql_text='select object_name from t where object_id=123'; SQL_ID SQL_TEXT ------------------- ----------------------------------------------- 2dymmcx3kf7h2 select object_name from t where object_id=123
4、再次手工生成AWR快照
zx@ORCL>exec dbms_workload_repository.create_snapshot; PL/SQL procedure successfully completed.
5、使用awrsqrpt.sql腳本生成對于sql_id=2dymmcx3kf7h2的sql的詳細(xì)統(tǒng)計(jì)信息。過程與生成awrrpt類似,不同的是需要指定要生成報(bào)告的sql_id
zx@ORCL>@?/rdbms/admin/awrsqrpt Current Instance ~~~~~~~~~~~~~~~~ DB Id DB Name Inst Num Instance ----------- ------------ -------- ------------ 1444351641 ORCL 1 orcl Specify the Report Type ~~~~~~~~~~~~~~~~~~~~~~~ Would you like an HTML report, or a plain text report? Enter 'html' for an HTML report, or 'text' for plain text Defaults to 'html' Enter value for report_type: text Type Specified: text Instances in this Workload Repository schema ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DB Id Inst Num DB Name Instance Host ------------ -------- ------------ ------------ ------------ * 1444351641 1 ORCL orcl rhel6 Using 1444351641 for database Id Using 1 for instance number Specify the number of days of snapshots to choose from ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Entering the number of days (n) will result in the most recent (n) days of snapshots being listed. Pressing <return> without specifying a number lists all completed snapshots. Enter value for num_days: 1 Listing the last day's Completed Snapshots Snap Instance DB Name Snap Id Snap Started Level ------------ ------------ --------- ------------------ ----- orcl ORCL 826 15 Feb 2017 09:25 1 827 15 Feb 2017 10:00 1 828 15 Feb 2017 10:00 1 829 15 Feb 2017 10:04 1 830 15 Feb 2017 10:09 1 831 15 Feb 2017 11:00 1 832 15 Feb 2017 11:02 1 833 15 Feb 2017 11:07 1 Specify the Begin and End Snapshot Ids ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Enter value for begin_snap: 832 Begin Snapshot Id specified: 832 Enter value for end_snap: 833 End Snapshot Id specified: 833 Specify the SQL Id ~~~~~~~~~~~~~~~~~~ Enter value for sql_id: 2dymmcx3kf7h2 SQL ID specified: 2dymmcx3kf7h2 Specify the Report Name ~~~~~~~~~~~~~~~~~~~~~~~ The default report file name is awrsqlrpt_1_832_833.txt. To use this name, press <return> to continue, otherwise enter an alternative. Enter value for report_name: Using the report name awrsqlrpt_1_832_833.txt WORKLOAD REPOSITORY SQL Report Snapshot Period Summary DB Name DB Id Instance Inst Num Startup Time Release RAC ------------ ----------- ------------ -------- --------------- ----------- --- ORCL 1444351641 orcl 1 15-Feb-17 09:14 11.2.0.4.0 NO Snap Id Snap Time Sessions Curs/Sess --------- ------------------- -------- --------- Begin Snap: 832 15-Feb-17 11:02:01 27 1.3 End Snap: 833 15-Feb-17 11:07:24 29 1.5 Elapsed: 5.38 (mins) DB Time: 0.06 (mins) SQL Summary DB/Inst: ORCL/orcl Snaps: 832-833 Elapsed SQL Id Time (ms) ------------- ---------- 2dymmcx3kf7h2 1 Module: SQL*Plus select object_name from t where object_id=123 ------------------------------------------------------------- SQL ID: 2dymmcx3kf7h2 DB/Inst: ORCL/orcl Snaps: 832-833 -> 1st Capture and Last Capture Snap IDs refer to Snapshot IDs witin the snapshot range -> select object_name from t where object_id=123 Plan Hash Total Elapsed 1st Capture Last Capture # Value Time(ms) Executions Snap ID Snap ID --- ---------------- ---------------- ------------- ------------- -------------- 1 3476657867 1 1 833 833 ------------------------------------------------------------- Plan 1(PHV: 3476657867) ----------------------- Plan Statistics DB/Inst: ORCL/orcl Snaps: 832-833 -> % Total DB Time is the Elapsed Time of the SQL statement divided into the Total Database Time multiplied by 100 Stat Name Statement Per Execution % Snap ---------------------------------------- ---------- -------------- ------- Elapsed Time (ms) 1 0.8 0.0 CPU Time (ms) 0 0.0 0.0 Executions 1 N/A N/A Buffer Gets 3 3.0 0.0 Disk Reads 0 0.0 0.0 Parse Calls 1 1.0 0.1 Rows 1 1.0 N/A User I/O Wait Time (ms) 0 N/A N/A Cluster Wait Time (ms) 0 N/A N/A Application Wait Time (ms) 0 N/A N/A Concurrency Wait Time (ms) 0 N/A N/A Invalidations 0 N/A N/A Version Count 1 N/A N/A Sharable Mem(KB) 15 N/A N/A ------------------------------------------------------------- Execution Plan -------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | 2 (100)| | | 1 | TABLE ACCESS BY INDEX ROWID| T | 1 | 30 | 2 (0)| 00:00:01 | | 2 | INDEX UNIQUE SCAN | IDX_UNIQUE_T | 1 | | 1 (0)| 00:00:01 | -------------------------------------------------------------------------------------------- Full SQL Text SQL ID SQL Text ------------ ----------------------------------------------------------------- 2dymmcx3kf7h select object_name from t where object_id=123 Report written to awrsqlrpt_1_832_833.txt
報(bào)告中列出了AWR記錄中sql執(zhí)行的統(tǒng)計(jì)信息和執(zhí)行計(jì)劃。
參考:http://blog.csdn.net/leshami/article/details/8732708
http://www.linuxidc.com/Linux/2013-01/77196.htm
http://docs.oracle.com/cd/E11882_01/appdev.112/e40758/d_workload_repos.htm#ARPLS69140
《基于Oracle的SQL優(yōu)化》
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。