ASH汇报的产生-学习小结

ASH报告的产生--学习小结

                                                        ASH报告的产生


You can examine the current Active Session Hist ory (ASH) data in the  V$ACTIVE_SESSION_HISTORY view
and historical data in the   DBA_HIST_ACTIVE_SESS_HISTORY   view
 
 
  <1>V$ACTIVE_SESSION_HISTORY
  one  sample every 1 seconds
 
 
  <2>DBA_HIST_ACTIVE_SESS_HISTORY
  one  sample every 10 seconds
 
 查看当前活跃回话的ash data 信息
 
 select * from V$ACTIVE_SESSION_HISTORY;
 SAMPLE_ID SAMPLE_TIME
---------- ------------------------------

    430857 18-3月 -13 08.20.06.998 下午
    430782 18-3月 -13 08.18.51.965 下午
    430781 18-3月 -13 08.18.50.965 下午
    430780 18-3月 -13 08.18.49.969 下午
    430779 18-3月 -13 08.18.48.965 下午
    430778 18-3月 -13 08.18.47.965 下午
    430737 18-3月 -13 08.18.06.966 下午
    430734 18-3月 -13 08.18.03.967 下午
    430731 18-3月 -13 08.18.00.967 下午
    430728 18-3月 -13 08.17.57.967 下午
    430722 18-3月 -13 08.17.51.967 下午
 。。。。。
 
 
 查看ash data的历史信息:
SQL> select * from DBA_HIST_ACTIVE_SESS_HISTORY;

   SNAP_ID       DBID INSTANCE_NUMBER  SAMPLE_ID SAMPLE_TIME
---------- ---------- --------------- ---------- -------------------------------

       154 2546074315               1     407670 16-3月 -13 07.55.56.716 下午
       161 2546074315               1     422430 18-3月 -13 06.00.41.425 下午
       161 2546074315               1     425330 18-3月 -13 06.49.01.498 下午
       159 2546074315               1     419670 18-3月 -13 05.14.38.109 下午
       159 2546074315               1     419670 18-3月 -13 05.14.38.109 下午
       159 2546074315               1     419670 18-3月 -13 05.14.38.109 下午
       159 2546074315               1     419670 18-3月 -13 05.14.38.109 下午
       159 2546074315               1     419670 18-3月 -13 05.14.38.109 下午
       159 2546074315               1     419680 18-3月 -13 05.14.48.109 下午
       159 2546074315               1     419970 18-3月 -13 05.19.38.153 下午
       158 2546074315               1     416070 17-3月 -13 03.00.24.075 下午

。。。。。。。

ash内存的使用:
The memory for the ASH come s from the System Global Area  (SGA), and it is fixed for
the lifetime of the instance. It  represents 2 MB of memory  per CPU. The ASH cannot exceed a
maximum bound of five percent of the shared pool size , or five percent of the SGA_TARGET. 


在sqlplus 下使用脚本产生ash 报告:
脚本默认位置: $ORACLE_HOME/rdbms/admin/ashrpt.sql


以下为windows server 2003下测试:

SQL> @?/rdbms/admin/ashrpt.sql    -------------- @表示执行sql脚本 ;?  表示$oracle_home

Current Instance
~~~~~~~~~~~~~~~~

   DB Id    DB Name      Inst Num Instance
----------- ------------ -------- ------------
 2546074315 MAX                 1 max


Specify the Report Type
~~~~~~~~~~~~~~~~~~~~~~~
Enter 'html' for an HTML report, or 'text' for plain text
Defaults to 'html'
输入 report_type 的值:  html

Type Specified:  html


Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   DB Id     Inst Num DB Name      Instance     Host
------------ -------- ------------ ------------ ------------
* 2546074315        1 MAX          max          MAX

Defaults to current database

Using database id: 2546074315

Defaults to current instance

Using instance number: 1


ASH Samples in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
行将被截断

行将被截断

行将被截断

行将被截断


Oldest ASH sample available:  13-3月 -13 16:39:48  [   7429 mins in the pa


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
输入 begin_time 的值:
Report begin time specified:

Enter duration in minutes starting from begin time:
Defaults to SYSDATE - begin_time
Press Enter to analyze till current time
输入 duration 的值:
Report duration specified:
行将被截断


Using 18-3月 -13 20:17:24 as report begin 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_0318_2032.html.  To use this name,
press <return> to continue, otherwise enter an alternative.
输入 report_name 的值:  《  需要填入ash报告的文件名可添加目录 eg:d:/ashrpt_1_0318_2032.html  或者          /tmp/ashrpt_1_0318_2032.html》


Returns most active SQL in the past minute
 查找最近活跃度最高的sql语句:

SELECT   sql_id, count(*),
round(count(*)/sum(count(*)) over (), 2) pctload
FROM     v$active_session_history
WHERE    sample_time > sysdate -1/24/60 and
session_type <> 'BACKGROUND'
GROUP BY sql_id
ORDER BY count(*) desc;

 

当有多个数据库是可以使用以下脚本:

SQL> define dbid        = '';
SQL> define inst_num    = '';
SQL> define report_type = 'html';
SQL> define begin_time  = '09:00';
SQL> define duration    = 480;
SQL> define report_name = '/tmp/sql_ashrpt.txt';
SQL> define slot_width  = '';
SQL> define target_session_id   = '';
SQL> define target_sql_id       = 'abcdefghij123';
SQL> define target_wait_class   = '';
SQL> define target_service_hash = '';
SQL> define target_module_name  = '';
SQL> define target_action_name  = '';
SQL> define target_client_id    = '';
SQL> @?/rdbms/admin/ashrpti