監控——數據庫awr報告
[oracle@node3 /]$ su - oracle
[oracle@node3 ~]$ sqlplus system/[email protected]/orcl
SQL*Plus: Release 11.2.0.4.0 Production on Sun Oct 9 14:16:59 2016
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL> exec dbms_workload_repository.create_snapshot(); (loadrunner 開始跑壓力測試腳本後,通過這句話手動創建Snapshots ,此時生產一個id ,大致記住當前時間,在後面會用到)
PL/SQL procedure successfully completed.
SQL> exec dbms_workload_repository.create_snapshot(); (loadrunner 結束跑壓力測試腳本後,通過這句話再手動創建
(後面會取這兩個id之間的值,作為html報告生成。)
PL/SQL procedure successfully completed.
SQL> @?/rdbms/admin/awrrpt.sql
Current Instance
~~~~~~~~~~~~~~~~
DB Id DB Name Inst Num Instance
----------- ------------ -------- ------------
787750339 LTDB 1 ltdb1
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: (回車)
Type Specified: html
Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DB Id Inst Num DB Name Instance Host
------------ -------- ------------ ------------ ------------
* 787750339 1 LTDB ltdb1 node1
787750339 2 LTDB ltdb2 node2
Using 787750339 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 <return> without
specifying a number lists all completed snapshots.
Enter value for num_days: (回車)
Listing all Completed Snapshots
Instance DB Name Snap Id Snap Started Level
------------ ------------ --------- ------------------ -----
ltdb1 LTDB 1412 08 Oct 2016 11:00 1
1429 09 Oct 2016 13:04 1
1430 09 Oct 2016 13:35 1
1431 09 Oct 2016 13:35 1
1432 09 Oct 2016 13:51 1
1433 09 Oct 2016 14:07 1
1434 09 Oct 2016 14:17 1
Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: (1433 從上面的列表選出來的。 )(基本上是取最後兩個id , 因為上面也是手動創建過兩次Snapshots)
Enter value for end_snap: 1434(1434 從上面的列表選出來的。 )
End Snapshot Id specified: 1434
Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrrpt_1_1431_1434.html. To use this name,
press <return> to continue, otherwise enter an alternative.
Enter value for report_name: (默認報告的名字。路徑是/home/orace/ awrrpt_1_1431_1434.html) 回車後就生產報告了。
/export/home/oracle
報告裏需要關註的點:主要就是sql腳本執行時間, 這裏需要開發調優。
第三列:表示執行該sql所用的時間,如果時間長了需要優化。
簡單介紹:
--如果需要的話DBA可以通過DBMS_WORKLOAD_REPOSITORY過程手動創建、刪除或修改snapshots.
--提示調用DBMS_WORKLOAD_REPOSITORY包需要擁有DBA權限。
--1.手動創建Snapshots 手動創建Snapshots通過DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT過程
--例如
exec dbms_workload_repository.create_snapshot();
-- 然後可以通過 DBA_HIST_SNAPSHOT 視圖查看剛剛創建的Snapshots信息。
SELECT * FROM DBA_HIST_SNAPSHOT;
-- 2手動刪除Snapshots
--刪除Snapshots是使用DBMS_WORKLOAD_REPOSITORY包的另一個過程DROP_SNAPSHOT_RANGE 該過程在執行時可以通過指定snap_id的範圍的方式一次刪除多個Snapshot
--例如
select count(0) from dba_hist_snapshot where snap_id between 6770 and 6774;
select max(snap_id) from dba_hist_snapshot;
select dbid from v$database;
exec dbms_workload_repository.drop_snapshot_range(low_snap_id => 6770,high_snap_id => 6774,dbid => 4059638244);
--或者
begin
dbms_workload_repository.drop_snapshot_range(
low_snap_id => 6770,
high_snap_id => 6774,
dbid => 4059638244);
end;
select count(0) from dba_hist_snapshot where snap_id between 6770 and 6774;
監控——數據庫awr報告