理解DB Time
DB Time指得是活动session(不包括后台进程)的时间总和。DB Time越大,数据库负载相应的也就越大。
--查看活动session(不包括后台进程)
select * from v$session where  status='ACTIVE' and type<>'BACKGROUND';


--查看当前的AWR保存策略,默认情况下每小时产生一个快照,快照保留7天。
SQL> select * from dba_hist_wr_control;

      DBID SNAP_INTERVAL        RETENTION            TOPNSQL
---------- -------------------- -------------------- ----------
 3913660635 +00000 01:00:00.0    +00007 00:00:00.0    DEFAULT


--调整AWR配置,interval与retention的单位为分钟
exec dbms_workload_repository.modify_snapshot_settings(interval=>30, retention=>10*24*60);

--手工创建awr快照
exec dbms_workload_repository.create_snapshot ();

--使用DBA_HIST_SNAPSHOT查看所有的快照
select * from DBA_HIST_SNAPSHOT order by snap_id;

--生成awr报告
运行$ORACLE_HOME/rdbms/admin/awrrpt.sql
 

 
  
  1. --生成awr示例,以手动生成的两个快照生成awr报告 
  2. SQL> col dbid for 9999999999 
  3. SQL> col snap_interval for a20 
  4. SQL> col retention for a20 
  5. SQL> col topsql for a20 
  6. SQL> set linesize 100 
  7. SQL> select * from dba_hist_wr_control; 
  8.  
  9.        DBID SNAP_INTERVAL        RETENTION            TOPNSQL 
  10. ----------- -------------------- -------------------- ---------- 
  11.  3913660635 +00000 01:00:00.0    +00007 00:00:00.0    DEFAULT 
  12.  
  13. SQL> exec dbms_workload_repository.modify_snapshot_settings(interval=>30, retention=>10*24*60); 
  14.  
  15. PL/SQL 过程已成功完成。 
  16.  
  17. SQL> select * from dba_hist_wr_control; 
  18.  
  19.        DBID SNAP_INTERVAL        RETENTION            TOPNSQL 
  20. ----------- -------------------- -------------------- ---------- 
  21.  3913660635 +00000 00:30:00.0    +00010 00:00:00.0    DEFAULT 
  22.  
  23. --以手动生成的两个快照生成awr报告 
  24. SQL> exec dbms_workload_repository.create_snapshot (); 
  25.  
  26. PL/SQL 过程已成功完成。 
  27.  
  28. SQL> exec dbms_workload_repository.create_snapshot (); 
  29.  
  30. PL/SQL 过程已成功完成。 
  31.  
  32. SQL> @G:\oracle\product\10.2.0\db_1\RDBMS\ADMIN\awrrpt.sql 
  33.  
  34. Current Instance 
  35. ~~~~~~~~~~~~~~~~ 
  36.  
  37.    DB Id    DB Name      Inst Num Instance 
  38. ----------- ------------ -------- ------------ 
  39.  3913660635 ORALIFE             1 oralife 
  40.  
  41.  
  42. Specify the Report Type 
  43. ~~~~~~~~~~~~~~~~~~~~~~~ 
  44. Would you like an HTML report, or a plain text report? 
  45. Enter 'html' for an HTML report, or 'text' for plain text 
  46. Defaults to 'html' 
  47. 输入 report_type 的值: 
  48.  
  49. Type Specified:  html 
  50.  
  51.  
  52. Instances in this Workload Repository schema 
  53. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  54.  
  55.    DB Id     Inst Num DB Name      Instance     Host 
  56. ------------ -------- ------------ ------------ ------------ 
  57. * 3913660635        1 ORALIFE      oralife      LAUGHING-PC 
  58.  
  59. Using 3913660635 for database Id 
  60. Using          1 for instance number 
  61.  
  62.  
  63. Specify the number of days of snapshots to choose from 
  64. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  65. Entering the number of days (n) will result in the most recent 
  66. (n) days of snapshots being listed.  Pressing <return> without 
  67. specifying a number lists all completed snapshots. 
  68.  
  69.  
  70. 输入 num_days 的值:  1 
  71.  
  72. Listing the last day's Completed Snapshots 
  73.  
  74.                                                         Snap 
  75. Instance     DB Name        Snap Id    Snap Started    Level 
  76. ------------ ------------ --------- ------------------ ----- 
  77. oralife      ORALIFE            943 18 8月  2012 00:00     1 
  78.  
  79.                                 944 18 8月  2012 09:31     1 
  80.                                 945 18 8月  2012 10:56     1 
  81.                                 946 18 8月  2012 10:59     1 
  82.                                 947 18 8月  2012 17:25     1 
  83.                                 948 18 8月  2012 18:00     1 
  84.                                 949 18 8月  2012 19:00     1 
  85.                                 950 18 8月  2012 19:10     1 
  86.                                 951 18 8月  2012 19:10     1 
  87.  
  88.  
  89.  
  90. Specify the Begin and End Snapshot Ids 
  91. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  92. 输入 begin_snap 的值:  950 
  93. Begin Snapshot Id specified: 950 
  94.  
  95. 输入 end_snap 的值:  951 
  96. End   Snapshot Id specified: 951 
  97.  
  98.  
  99.  
  100. Specify the Report Name 
  101. ~~~~~~~~~~~~~~~~~~~~~~~ 
  102. The default report file name is awrrpt_1_950_951.html.  To use this name
  103. press <returnto continue, otherwise enter an alternative. 
  104.  
  105. 输入 report_name 的值: 
  106.  
  107. Using the report name awrrpt_1_950_951.html 
  108. ... 
  109. ... 
  110. ... 
  111. Report written to awrrpt_1_950_951.html