一、AWE報告生成步驟
對於SQL調優,局部SQL,我們可以直接使用執行計划等直接調優,而對於整個系統來說?這時候就可以用Oracle系統自帶的報告對系統進行整體分析了,Oracle提供好幾種性能分析的報告,比如AWR、ASH、ADDM等等
這篇博客主要介紹AWR
AWR全稱Automatic Workload Repository,自動負載信息庫,是Oracle 10g版本后推出的一種性能收集和分析工具,提供了一個時間段內整個系統的報表數據。通過AWR報告,可以分析指定的時間段內數據庫系統的性能。
1.1 工具選擇
對於Oracle數據庫可以使用sqlplus或者plsql developer客戶端軟件
sqlplus 使用
可以使用sqlplus工具登錄
進入數據庫
sqlplus / as sysdba
查看用戶
show parameter db_name
用登錄之后才可以使用
plsql developer使用
plsql developer也可以使用,登錄之后,選擇文件(File)->新建(New)->命令窗口(Command Window)
1.2 自動創建快照
開始壓測后執行
exec DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT ();
可以通過dba_hist_wr_control查看當前的配置情況,當前awr為每1小時做一次數據快照,保留時間為8天。
select * from dba_hist_wr_control;
修改配置,每隔30分鍾收集一次,保存1天
execute dbms_workload_repository.modify_snapshot_settings(interval=>30,retention=>14000);
關閉AWR自動收集
SQL>exec dbms_workload_repository.modify_snapshot_settings (interval=>0,retention=>24*60);
注:10g默認是自動開啟awr信息收集的,會對系統有一定的影響(很小);如果要關閉awr信息收集,只需設置interval參數為0即可。但interval設0后,AWR報告無法生成。
1.3 手工創建快照
除了自動創建快照,也可以手工創建快照
select dbms_workload_repository.create_snapshot() from dual;
1.4 生成AWR報告
在sqlplus或者plsql使用命令,${ORACLE_HOME}是Oracle的安裝路徑
@/${ORACLE_HOME}/.../RDBMS/ADMIN/awrrpt.sql
例如我的命令為:
@D:/oracle/product/11.1.0/db_1/RDBMS/ADMIN/awrrpt.sql
sqlplus登錄的可以使用
@?/rdbms/admin/awrrpt/awrrpt.sql
@?/rdbms/admin/awrrpt; 本實例AWR包括:
@?/rdbms/admin/awrrpti; RAC中選擇實例號
@?/rdbms/admin/awrddrpt; AWR 比對報告
@?/RDBMS/admin/awrgrpt; RAC全局AWR報告
執行命令之后,會提示你輸入一些參數
- (1) Enter value of report_type
意思是生成報告的格式有兩種,html和txt,這里選擇html - (2) Enter value of num_days
收集幾天的報告信息,數字,可以輸入1 - (3) Enter value of begin_snap
輸入開始快照id,要根據日志打印的快照id范圍來填
例如我實驗時候,日志打印的快照id范圍為:6727 ~6745
Listing the last day's Completed Snapshots
INST_NAME DB_NAME SNAP_ID SNAPDAT LV
------------ ------------ -------- ------------------ --
orcl ORCL 6727 17 4月 2019 00:00 1
orcl ORCL 6728 17 4月 2019 01:00 1
orcl ORCL 6729 17 4月 2019 02:00 1
orcl ORCL 6730 17 4月 2019 03:00 1
orcl ORCL 6731 17 4月 2019 04:00 1
orcl ORCL 6732 17 4月 2019 05:00 1
orcl ORCL 6733 17 4月 2019 06:00 1
orcl ORCL 6734 17 4月 2019 07:00 1
orcl ORCL 6735 17 4月 2019 08:00 1
orcl ORCL 6736 17 4月 2019 09:00 1
orcl ORCL 6737 17 4月 2019 10:00 1
orcl ORCL 6738 17 4月 2019 11:00 1
orcl ORCL 6739 17 4月 2019 12:00 1
orcl ORCL 6740 17 4月 2019 13:00 1
orcl ORCL 6741 17 4月 2019 14:00 1
orcl ORCL 6742 17 4月 2019 14:13 1
orcl ORCL 6743 17 4月 2019 14:15 1
orcl OANET 6744 17 4月 2019 14:16 1
orcl OANET 6745 17 4月 2019 14:40 1
所以我隨意填寫:6743
- (4) Enter value of end_snap
輸入結束快照id,要根據日志打印的快照id范圍來填,所以我隨意填寫:6745
SQL> @D:/oracle/product/11.1.0/db_1/RDBMS/ADMIN/awrrpt.sql
Current Instance
~~~~~~~~~~~~~~~~
DBID DB_NAME INST_ INST_NAME
---------- ------------ ----- ------------
4279242421 ORCL 1 orcl
rpt_options
---------
0
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'
Type Specified: html
Cannot SET TRIMSPOOL
Cannot SET UNDERLINE
Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DBBID INSTT DBB_NAME INSTT_NAME HOST
------------ ----- ------------ ------------ ------------
* 4279242421 1 ORCL ORCL zwdb
Using 4279242421 for database Id
Using 1 for instance number
dbid
---------
4279242421
inst_num
---------
1
inst_num
---------
1
dbid
---------
4279242421
max_snap_time
---------
17/04/2019
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.
Listing the last day's Completed Snapshots
INST_NAME DB_NAME SNAP_ID SNAPDAT LV
------------ ------------ -------- ------------------ --
orcl ORCL 6727 17 4月 2019 00:00 1
orcl ORCL 6728 17 4月 2019 01:00 1
orcl ORCL 6729 17 4月 2019 02:00 1
orcl ORCL 6730 17 4月 2019 03:00 1
orcl ORCL 6731 17 4月 2019 04:00 1
orcl ORCL 6732 17 4月 2019 05:00 1
orcl ORCL 6733 17 4月 2019 06:00 1
orcl ORCL 6734 17 4月 2019 07:00 1
orcl ORCL 6735 17 4月 2019 08:00 1
orcl ORCL 6736 17 4月 2019 09:00 1
orcl ORCL 6737 17 4月 2019 10:00 1
orcl ORCL 6738 17 4月 2019 11:00 1
orcl ORCL 6739 17 4月 2019 12:00 1
orcl ORCL 6740 17 4月 2019 13:00 1
orcl ORCL 6741 17 4月 2019 14:00 1
orcl ORCL 6742 17 4月 2019 14:13 1
orcl ORCL 6743 17 4月 2019 14:15 1
orcl OANET 6744 17 4月 2019 14:16 1
orcl OANET 6745 17 4月 2019 14:40 1
dbid
---------
4279242421
inst_num
---------
1
max_snap_time
---------
17/04/2019
Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Begin Snapshot Id specified: 6743
End Snapshot Id specified: 6745
bid
---------
6743
eid
---------
6745
inst_num
---------
1
dbid
---------
4279242421
bid
---------
6743
eid
---------
6745
Cannot SET TRIMSPOOL
Cannot SET UNDERLINE
Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrrpt_1_6743_6745.html. To use this name,
press <return> to continue, otherwise enter an alternative.
Using the report name awr.html
Started spooling to D:\Program Files\PLSQL Developer 8.0.3.1510\awr.html
二、AWR報告分析
2.1 AWR之DB Time
DB Time主要用來判斷當前系統有沒有相關瓶頸,是否較為頻繁訪問系統導致等待時間很長?然后要怎么看?一般來說,Elapsed時間乘以CPU個數如果大於DB Time,就是正常的,系統壓力不大,反之就說明壓力較大,例子如圖,24.93*8很明顯大於0.49,所以說明系統壓力很小
2.2 AWR之load_profile
load_profile指標主要用來顯示當前系統的一些指示性能的總體參數,這里介紹一些Redo_size,用來顯示平均每秒的日志尺寸和平均每個事務的日志尺寸,有時候可以結合Transactions這個每秒事務數,分析當前事務的繁忙程度
如圖,平均每秒的事務數Transactions非常小,說明系統壓力非常小,一般來說Transactions不超過200都是正常的,或者200左右都是正常的,超過1000就是非常繁忙了,再看看平均每秒的日志尺寸是4位數的,平均每個事務的日志尺寸是5位數的,說明了系統訪問不是很頻繁,而單個業務是比較復雜的,如果反過來,平均每秒日志尺寸比平均每秒事務日志尺寸大很多,說明系統訪問很頻繁,而業務比較簡單,不需要響應很久
2.3 AWR之efficiency percentages
efficiency percentages是一些命中率指標。Buffer Hint、Library Hint等表示SGA(System global area)的命中率;Soft Parse指標表示共享池的軟解析率,如果小於90%,就說明存在未綁定變量的情況
2.4 AWR之top 10 events
Top 10 Foreground Events by Total Wait Time,等待事件是衡量數據庫優化情況的重要指標,通過觀察Event和%DB time兩列就可以直觀看出當前數據庫的主要等待事件
如圖可以看出系統面試的主要是CPU被占用太多了和鎖等待
### 2.5 AWR之SQL Statistics
SQL Statistics從幾個維度列舉了系統執行比較慢的SQL,可以點擊,然后拿SQL去調優,調優SQL可以用執行計划看看
對於AWR的性能指標還有很多,本博客是看了《收獲,不止SQL優化》一書的筆記,這里只簡單介紹一些比較重要的指標