您好,登錄后才能下訂單哦!
通過案例學習調優之--Oracle ASH
應用環境:
操作系統: RedHat EL55
Oracle: Oracle 10gR2
案例場景:
SCOTT用戶做事務處理,事務已經完成!
16:42:14 SYS@ prod>conn scott/tiger Connected. 16:42:20 SCOTT@ prod>begin 16:42:23 2 for i in 1..1000000 loop 16:42:27 3 execute immediate 'insert into t1 values ('||i||')'; 16:42:32 4 end loop; 16:42:36 5 end; 16:42:38 6 / PL/SQL procedure successfully completed. Elapsed: 00:08:35.77 16:51:14 SCOTT@ prod>commit; Commit complete.
生成ASH報告:
16:55:43 SYS@ prod>@?/rdbms/admin/ashrpt
Current Instance ~~~~~~~~~~~~~~~~ DB Id DB Name Inst Num Instance ----------- ------------ -------- ------------ 199802235 PROD 1 prod Elapsed: 00:00:00.07 Specify the Report Type ~~~~~~~~~~~~~~~~~~~~~~~ Enter 'html' for an HTML report, or 'text' for plain text Defaults to 'html' Enter value for report_type: html Type Specified: html Instances in this Workload Repository schema ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DB Id Inst Num DB Name Instance Host ------------ -------- ------------ ------------ ------------ * 199802235 1 PROD prod rh65 Defaults to current database Using database id: 199802235 Defaults to current instance Using instance number: 1 ASH Samples in this Workload Repository schema ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Oldest ASH sample available: 15-Aug-14 11:55:37 [ 4625 mins in the past] Latest ASH sample available: 18-Aug-14 17:00:17 [ 1 mins in the past] Specify the timeframe to generate the ASH report ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Enter begin time for report: -- Valid input formats: -- To specify absolute begin time: -- [MM/DD[/YY]] HH24:MI[:SS] -- Examples: 02/23/03 14:30:15 -- 02/23 14:30:15 -- 14:30:15 -- 14:30 -- To specify relative begin time: (start with '-' sign) -- -[HH24:]MI -- Examples: -1:15 (SYSDATE - 1 Hr 15 Mins) -- -25 (SYSDATE - 25 Mins) Defaults to -15 mins Enter value for begin_time: -10 Enter duration in minutes starting from begin time: Defaults to SYSDATE - begin_time Press Enter to analyze till current time Enter value for duration: Report duration specified: Using 18-Aug-14 16:51:39 as report begin time Using 18-Aug-14 17:01:40 as report end time Specify Slot Width (using ashrpti.sql) for 'Activity Over Time' section ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- Explanation: -- In the 'Activity Over Time' section of the ASH report, -- the analysis period is divided into smaller slots -- and top wait events are reported in each of those slots. -- Default: -- The analysis period will be automatically split upto 10 slots -- complying to a minimum slot width of -- 1 minute, if the source is V$ACTIVE_SESSION_HISTORY or -- 5 minutes, if the source is DBA_HIST_ACTIVE_SESS_HISTORY. Specify Slot Width in seconds to use in the 'Activity Over Time' section: Defaults to a value as explained above: Slot Width specified: Specify Report Targets (using ashrpti.sql) to generate the ASH report ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- Explanation: -- ASH Report can accept "Report Targets", -- like a particular SQL statement, or a particular SESSION, -- to generate the report on. If one or more report targets are -- specified, then the data used to generate the report will only be -- the ASH samples that pertain to ALL the specified report targets. -- Default: -- If none of the report targets are specified, -- then the target defaults to all activity in the database instance. Specify SESSION_ID (eg: from V$SESSION.SID) report target: Defaults to NULL: SESSION report target specified: Specify SQL_ID (eg: from V$SQL.SQL_ID) report target: Defaults to NULL: (% and _ wildcards allowed) SQL report target specified: Specify WATI_CLASS name (eg: from V$EVENT_NAME.WAIT_CLASS) report target: [Enter 'CPU' to investigate CPU usage] Defaults to NULL: (% and _ wildcards allowed) WAIT_CLASS report target specified: Specify SERVICE_HASH (eg: from V$ACTIVE_SERVICES.NAME_HASH) report target: Defaults to NULL: SERVICE report target specified: Specify MODULE name (eg: from V$SESSION.MODULE) report target: Defaults to NULL: (% and _ wildcards allowed) MODULE report target specified: Specify ACTION name (eg: from V$SESSION.ACTION) report target: Defaults to NULL: (% and _ wildcards allowed) ACTION report target specified: Specify CLIENT_ID (eg: from V$SESSION.CLIENT_IDENTIFIER) report target: Defaults to NULL: (% and _ wildcards allowed) CLIENT_ID report target specified: Specify the Report Name ~~~~~~~~~~~~~~~~~~~~~~~ The default report file name is ashrpt_1_0818_1704.html. To use this name, press <return> to continue, otherwise enter an alternative. Enter value for report_name: ash4.html
查看生成報告
通過html方式查看ASH報告:
基本信息
TOP事件:User TOP EVENTS
TOP SQL
TOP SESSION
TOP OBJECTS
ASH 說明
ASH以V$SESSION為基礎,每秒采樣一次,記錄活動會話等待的事件。不活動的會話不會采樣,采樣工作由新引入的后臺進程MMNL來完成。
ASH buffers 的最小值為1MB,最大值不超過30MB。內存中記錄數據。期望值是記錄一小時的內容。
ASH內存分配:
SQL> select * from v$sgastat where name like '%ASH%';
POOL NAME BYTES
------------ -------------------------- ----------
shared pool ASH buffers 8388608
ASH報告生成腳本:@?/rdbms/admin/ashrpt.sql
ASH內存記錄數據始終是有限的,為了保存歷史數據,引入了自動負載信息庫(Automatic Workload Repository ,AWR) 由后臺進程MMON完成。ASH信息同樣被采集寫出到AWR負載庫中。由于內存不是足夠的,所以MMNL進程在ASH寫滿后會將信息寫出到AWR負載庫中。ASH全部寫出是不可接受的,所以一般只寫入收集的10%的數據量,而且使用direct-path insert完成,盡量減少日志的生成,從而最小化數據庫性能影響。
內存中的ASH 信息可以通過V$ACTIVE_SESSION_HISTORY查詢,而寫出到AWR負載庫的ASH信息,可以通過AWR的基礎表wrh$_active_session_history查詢,wrh$_active_session_history是一個分區表,Oracle會自動進行數據清理。
一般來說,我們在監控數據庫時,如果是當前正在發生的問題,我們可以通過v$session+v$sqlarea來找出性能最差的SQL語句。如果在一個小時以內發生的我們可以通過生成ASH報告來找出SQL。如果是1小時以上或幾天我們可以通過AWR報告來找出幾小時,幾天以來最影響系統的SQL語句。ADDM報告基于AWR庫,默認可以保存30天的ADDM報告。
相關查詢試圖:
v$session (當前正在發生)
v$session_wait (當前正在發生)
v$session_wait_history (會話最近的10次等待事件)
v$active_session_history (內存中的ASH采集信息,理論為1小時)
wrh$_active_session_history (寫入AWR庫中的ASH信息,理論為1小時以上)
dba_hist_active_sess_history (根據wrh$_active_session_history生成的視圖)
三. ASH 報告生成示例
ASH組件以v$active_session_history視圖為基礎,生成ASH報表,ASH報表與statspack類似,可以提供以下信息:
Top User Events
Top Background Events
Top Event P1/P2/P3 Values
Top Service/Module
Top Client IDs
Top SQL Command Types
Top SQL using literals
Top Blocking Sessions
Top DB Objects
Top DB Files
Top Latches
Activity Over Time
報表間隔時間可以精確到分鐘,因而ASH可以提供比STATSPACK或AWR更詳細的關于歷史會話的信息,可以作為statspack或awr的補充。ASH報告通過@$ORACLE_HOME/rdbms/admin/ashrpt.sql腳本生成,包括hmtl和text兩種格式。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。