您好,登錄后才能下訂單哦!
通過案例學(xué)習(xí)調(diào)優(yōu)之--Oracle ASH
應(yīng)用環(huán)境:
操作系統(tǒng): RedHat EL55
Oracle: Oracle 10gR2
案例場(chǎng)景:
SCOTT用戶做事務(wù)處理,事務(wù)已經(jīng)完成!
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報(bào)告:
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
查看生成報(bào)告
通過html方式查看ASH報(bào)告:
基本信息
TOP事件:User TOP EVENTS
TOP SQL
TOP SESSION
TOP OBJECTS
ASH 說明
ASH以V$SESSION為基礎(chǔ),每秒采樣一次,記錄活動(dòng)會(huì)話等待的事件。不活動(dòng)的會(huì)話不會(huì)采樣,采樣工作由新引入的后臺(tái)進(jìn)程MMNL來完成。
ASH buffers 的最小值為1MB,最大值不超過30MB。內(nèi)存中記錄數(shù)據(jù)。期望值是記錄一小時(shí)的內(nèi)容。
ASH內(nèi)存分配:
SQL> select * from v$sgastat where name like '%ASH%';
POOL NAME BYTES
------------ -------------------------- ----------
shared pool ASH buffers 8388608
ASH報(bào)告生成腳本:@?/rdbms/admin/ashrpt.sql
ASH內(nèi)存記錄數(shù)據(jù)始終是有限的,為了保存歷史數(shù)據(jù),引入了自動(dòng)負(fù)載信息庫(Automatic Workload Repository ,AWR) 由后臺(tái)進(jìn)程MMON完成。ASH信息同樣被采集寫出到AWR負(fù)載庫中。由于內(nèi)存不是足夠的,所以MMNL進(jìn)程在ASH寫滿后會(huì)將信息寫出到AWR負(fù)載庫中。ASH全部寫出是不可接受的,所以一般只寫入收集的10%的數(shù)據(jù)量,而且使用direct-path insert完成,盡量減少日志的生成,從而最小化數(shù)據(jù)庫性能影響。
內(nèi)存中的ASH 信息可以通過V$ACTIVE_SESSION_HISTORY查詢,而寫出到AWR負(fù)載庫的ASH信息,可以通過AWR的基礎(chǔ)表wrh$_active_session_history查詢,wrh$_active_session_history是一個(gè)分區(qū)表,Oracle會(huì)自動(dòng)進(jìn)行數(shù)據(jù)清理。
一般來說,我們?cè)诒O(jiān)控?cái)?shù)據(jù)庫時(shí),如果是當(dāng)前正在發(fā)生的問題,我們可以通過v$session+v$sqlarea來找出性能最差的SQL語句。如果在一個(gè)小時(shí)以內(nèi)發(fā)生的我們可以通過生成ASH報(bào)告來找出SQL。如果是1小時(shí)以上或幾天我們可以通過AWR報(bào)告來找出幾小時(shí),幾天以來最影響系統(tǒng)的SQL語句。ADDM報(bào)告基于AWR庫,默認(rèn)可以保存30天的ADDM報(bào)告。
相關(guān)查詢?cè)噲D:
v$session (當(dāng)前正在發(fā)生)
v$session_wait (當(dāng)前正在發(fā)生)
v$session_wait_history (會(huì)話最近的10次等待事件)
v$active_session_history (內(nèi)存中的ASH采集信息,理論為1小時(shí))
wrh$_active_session_history (寫入AWR庫中的ASH信息,理論為1小時(shí)以上)
dba_hist_active_sess_history (根據(jù)wrh$_active_session_history生成的視圖)
三. ASH 報(bào)告生成示例
ASH組件以v$active_session_history視圖為基礎(chǔ),生成ASH報(bào)表,ASH報(bào)表與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
報(bào)表間隔時(shí)間可以精確到分鐘,因而ASH可以提供比STATSPACK或AWR更詳細(xì)的關(guān)于歷史會(huì)話的信息,可以作為statspack或awr的補(bǔ)充。ASH報(bào)告通過@$ORACLE_HOME/rdbms/admin/ashrpt.sql腳本生成,包括hmtl和text兩種格式。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。