可以通过dba_hist_wr_control查看当前的配置情况,当前awr为每1小时做一次数据快照,保留时间为7天。sys@peng sqlgt; select *
可以通过dba_hist_wr_control查看当前的配置情况,当前awr为每1小时做一次数据快照,保留时间为7天。
sys@peng sql> select * from dba_hist_wr_control;
dbid snap_interval retention topnsql
---------- --------------------------- ------------------------------------ ----------
620748923 +00000 01:00:00.0 +00007 00:00:00.0 default
elapsed: 00:00:00.16
sys@peng sql>
调整配置数据:
sys@peng sql> execute dbms_workload_repository.modify_snapshot_settings(interval=>30,retention=>14000);
pl/sql procedure successfully completed.
elapsed: 00:00:00.17
再查看修改后的效果:
sys@peng sql> select * from dba_hist_wr_control;
dbid snap_interval retention topnsql
---------- --------------------------- ------------------------------------ ----------
620748923 +00000 00:30:00.0 +00009 17:20:00.0 default
elapsed: 00:00:00.02
sys@peng sql>
除自动建立快照以外,还可以在需要的时候手工创建快照,数据和自动创建的一样使用。
sys@peng sql> select dbms_workload_repository.create_snapshot() from dual;
dbms_workload_repository.create_snapshot()
------------------------------------------
68
elapsed: 00:00:01.00
sys@peng sql> select dbms_workload_repository.create_snapshot() from dual;
dbms_workload_repository.create_snapshot()
------------------------------------------
69
elapsed: 00:00:00.60
sys@peng sql>
[oracle@localhost admin]$ pwd
/oracle/product/10g/rdbms/admin
这里存放了很多sql脚本,有时间可以打开阅读,对提高水平有作用。这里我们用到awrrpt.sql。
可以先打开看一下内容。
[oracle@localhost admin]$ cat awrrpt.sql
rem $header: awrrpt.sql 24-oct-2003.12:04:53 pbelknap exp $
rem
rem awrrpt.sql
rem
rem copyright (c) 1999, 2003, oracle corporation. all rights reserved.
rem
rem name
rem awrrpt.sql
rem
rem description
rem this script defaults the dbid and instance number to that of the
rem current instance connected-to, then calls awrrpti.sql to produce
rem the workload repository report.
rem
rem notes
rem run as select_catalog privileges.
rem this report is based on the statspack report.
rem
rem if you want to use this script in an non-interactive fashion,
rem see the 'customer-customizable report settings' section in
rem awrrpti.sql
rem
rem modified (mm/dd/yy)
rem pbelknap 10/24/03 - swrfrpt to awrrpt
rem pbelknap 10/14/03 - moving params to rpti
rem pbelknap 10/02/03 - adding non-interactive mode cmnts
rem mlfeng 09/10/03 - heading on
rem aime 04/25/03 - aime_going_to_main
rem mlfeng 01/27/03 - mlfeng_swrf_reporting
rem mlfeng 01/13/03 - update comments
rem mlfeng 07/08/02 - swrf flushing
rem mlfeng 06/12/02 - created
rem
--
-- get the current database/instance information - this will be used
-- later in the report along with bid, eid to lookup snapshots
set echo off heading on underline on;
column inst_num heading inst num new_value inst_num format 99999;
column inst_name heading instance new_value inst_name format a12;
column db_name heading db name new_value db_name format a12;
column dbid heading db id new_value dbid format 9999999999 just c;
prompt
prompt current instance
prompt ~~~~~~~~~~~~~~~~
select d.dbid dbid
, d.name db_name
, i.instance_number inst_num
, i.instance_name inst_name
from v$database d,
v$instance i;
@@awrrpti
undefine num_days;
undefine report_type;
undefine report_name;
undefine begin_snap;
undefine end_snap;
--
-- end of file
其中一段的结果为
select d.dbid dbid
, d.name db_name
, i.instance_number inst_num
, i.instance_name inst_name
from v$database d,
v$instance i;
dbid db_name inst_num inst_name
---------- --------- ---------- ----------------
620748923 peng 1 peng
然后调用了awrrpti.sql,,其内容较多,以后找机会在专门分析。
这里我们直接执行awrrpt.sql。
sys@peng sql> @/oracle/product/10g/rdbms/admin/awrrpt.sql
current instance
~~~~~~~~~~~~~~~~
db id db name inst num instance
----------- ------------ -------- ------------
620748923 peng 1 peng
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: text
type specified: text
instances in this workload repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
db id inst num db name instance host
------------ -------- ------------ ------------ ------------
* 620748923 1 peng peng localhost
using 620748923 for database id
using 1 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 without
specifying a number lists all completed snapshots.
enter value for num_days: 2
listing the last 2 days of completed snapshots
snap
instance db name snap id snap started level
------------ ------------ --------- ------------------ -----
peng peng 58 12 dec 2010 01:11 1
59 12 dec 2010 02:01 1
60 12 dec 2010 03:01 1
61 12 dec 2010 04:02 1
62 12 dec 2010 05:02 1
63 13 dec 2010 01:00 1
64 13 dec 2010 02:00 1
65 13 dec 2010 03:02 1
66 13 dec 2010 04:01 1
67 13 dec 2010 04:54 1
68 13 dec 2010 04:59 1
69 13 dec 2010 05:00 1
70 13 dec 2010 05:30 1
specify the begin and end snapshot ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
enter value for begin_snap: 64
begin snapshot id specified: 64
enter value for end_snap: 70
end snapshot id specified: 70
specify the report name
~~~~~~~~~~~~~~~~~~~~~~~
the default report file name is awrrpt_1_64_70.txt. to use this name,
press to continue, otherwise enter an alternative.
enter value for report_name: /tmp/awrrpt_1_64_70.txt
生成文件存放在指定的/tmp下。
文件包含一下内容:
report summary wait events statistics sql statistics instance activity statistics io stats buffer pool statistics advisory statistics wait statistics undo statistics latch statistics segment statistics dictionary cache statistics library cache statistics memory statistics streams statistics resource limit statistics init.ora parameters