AWR报告提取
1、如果不在oracle用户下请切换到oracle用户
su - oracle
2、以sysdba权限登录数据库
sqlplus "/as sysdba"
3、执行awrprt命令
SQL> @?/rdbms/admin/awrrpt
4、出现选择awr的输出格式界面(默认选HTML比较直观) -----------------------------------------------
Current Instance
~~~~~~~~~~~~~~~~
DB Id DB Name Inst Num Instance
----------- ------------ -------- ------------
2566595041 samp 2 samp2
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: html
Type Specified: html
-----------------------------------------------
5、选择采集日期间隔(下述samp1\samp2是RAC节点的两个实例) -----------------------------------------------
Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DB Id Inst Num DB Name Instance Host
------------ -------- ------------ ------------ ------------ * 2566595041 2 samp samp2 p650b
2566595041 1 samp samp1 p650a
Using 2566595041 for database Id
Using 2 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
------------------------------------------------
6、选择开始和结束采集点30132-30148
------------------------------------------------
Listing the last day's Completed Snapshots
Snap
Instance DB Name Snap Id Snap Started Level ------------ ------------ --------- ------------------ ----- samp2 samp 30132 13 Aug 2010 00:00 1 30133 13 Aug 2010 01:00 1
30134 13 Aug 2010 02:00 1
30135 13 Aug 2010 03:00 1
30136 13 Aug 2010 04:00 1
30137 13 Aug 2010 05:00 1
30138 13 Aug 2010 06:00 1
30139 13 Aug 2010 07:00 1
30140 13 Aug 2010 08:00 1
30141 13 Aug 2010 09:00 1
30142 13 Aug 2010 10:00 1
30143 13 Aug 2010 11:00 1
30144 13 Aug 2010 12:00 1
30145 13 Aug 2010 13:00 1
30146 13 Aug 2010 14:00 1
30147 13 Aug 2010 15:00 1
30148 13 Aug 2010 16:00 1
Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: 30132
Begin Snapshot Id specified: 30132
Enter value for end_snap: 30148
End Snapshot Id specified: 30148
------------------------------------------------
7、指定输出地址和名称/tmp/awrrpt_2_30132_30148.html
------------------------------------------------
Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrrpt_2_30132_30148.html. To use this name,
press <return> to continue, otherwise enter an alternative. Enter value for report_name: /tmp/awrrpt_2_30132_30148.html ------------------------------------------------
8、生成过程----屏幕打印一堆html代码
------------------------------------------------
Using the report name /tmp/awrrpt_2_30132_30148.html
<HTML><HEAD><TITLE>AWR Report</TITLE><style type="text/css">body.awr {font:bold 10pt Arial,Helvetica,Geneva,sans-serif;color:black; background:White;}
9、结束生成过程
------------------------------------------------
End of Report
</BODY></HTML>
Report written to /tmp/awrrpt_2_30132_30148.html
SQL>
------------------------------------------------
10、到指定目录下查看报告。windows系统则在c:\Documents and
Settings\username\目录下(执行sqlplus命令的目录)
获取sql的执行计划
SQL>spool file_name.txt (将执行结果保存到file_name.txt文件)
SQL>select plan_table_output from table(dbms_xplan.display_awr('statement_id'));(statement_id为awr报告中需要查询执行计划的sql语句的id)
SQL>spool off
到指定目录下查看生成的执行计划文件file_name.txt 。
第二篇:如何获取AWR报告
简介
awr报告是oracle 10g下提供的一种性能收集和分析工具,它能提供一个时间段内整个系统资源使用情况的报告,通过这个报告,我们就可以了解一个系统的整个运行情况,这就像一个人全面的体检报告。
获取方法
要获取awr报告,首先需要两个数据库快照,Oracle默认每个一个小时创建一个数据库快照,默认只保留最近7天的快照信息。
方法一
1:登陆对应的数据库服务器
2:找到oracle磁盘空间(d:oracle\product\10.2.0\db_1\RDBMS\Admin)
3:执行cmd-cd d:回车
4: cd d:oracle\product\10.2.0\db_1\RDBMS\Admin 回车
5:sqlplus 用户名/密码@服务连接名(例:sqlplus carmot_esz_1/carmot@igrp)
6:执行@awrrpt.sql 回车
方法二
1、用system用户登录PL/SQL
2、查看快照,查询出来的快照snap_id,SQL如下
select * from sys.wrh$_active_session_history order by snap_id desc;
3、直接通过sql获取即可
SELECT * FROM TABLE( dbms_workload_repository.awr_report_html(
(select dbid
from v$database), 1,
31187, -- begin snap_id 比如上午8点的时候的snap_id
31188 --end snap_id 比如下午5点的时候的snap_id
))
4、把查看的结果全部展开,并全选COPY 出来,保存到txt 文件,并修改后缀为html, 即生成 AWR报告。