elasticsearch入門系列">elasticsearch入門系列
867
2022-05-30
我寫的SQL調(diào)優(yōu)專欄:https://blog.csdn.net/u014427391/article/category/8679315
整體分析調(diào)優(yōu)工具
AWR:關注數(shù)據(jù)庫的整體性能的報告;
ASH:數(shù)據(jù)庫中的等待事件與哪些SQL具體對應的報告;
ADDM:oracle給出的一些建議
AWRDD:Oracle針對不同時段的性能對比報告
AWRSQRPT:oracle獲取統(tǒng)計信息與執(zhí)行計劃
不同場景對應工具
局部分析調(diào)優(yōu)工具:
explain plan for
set autotrace on
statistics_level=all
直接通過sql_id獲取
10046 trace
awrrpt.sql
整體性能工具要點
AWR關注點:load profile、efficiency percentages、top 5 time events、SQL Statistics、segment_statistics
ASH關注點:等待事件與sql完美結合
ADDM:各種建議與對應SQL
AWRDD:不同時期 load profile的比較、不同時期等待事件的比較、不同時期TOP SQL的比較
AWRSQRPT:獲取與關注點(統(tǒng)計信息與執(zhí)行計劃)
select output from table (dbms_workload_repository.awr_report_html(v_dbid,v_instance_number,v_min_snap_id,v_max_snap_id));
1
相關查詢試圖:
v$session (當前正在發(fā)生)
v$session_wait(當前正在等待)
v$session_wait_history (會話最近的10次等待事件)
v$active_session_history (內(nèi)存中的ASH采集信息,理論為1小時)
wrh$_active_session_history (寫入AWR庫中的ASH信息,理論為1小時以上)
dba_hist_active_sess_history (根據(jù)wrh$_active_session_history生成的視圖)
對于局部的,比如某個頁面列表sql,我們可以使用Oracle的執(zhí)行計劃進行sql調(diào)優(yōu),但是對于整個系統(tǒng)來說,你可以知道哪些sql比較耗時?當然可以通過查Oracle的共享池得到,不過Oracle系統(tǒng)本身就提供了幾種性能分析報告,比如AWR、ASH、ADDM等等報告,本博客介紹一下ASH性能分析報告
ASH即活動會話歷史,Active Session History,ASH以V$SESSION為基礎,每秒采樣一次,記錄活動會話等待的事件。不活動的會話不會采樣, 采樣工作由新引入的后臺進程MMNL完成。
v$active_session_history視圖提供了在實例級別抽取會話活動信息?;顒訒捗糠昼姇怀闃右淮吻冶淮鎯υ趕ga中的循環(huán)緩沖區(qū)中。任何被連接到數(shù)據(jù)庫且正等待一個不屬于空閑等待時間的會話會被考慮是一個活動的會話。每個會話抽樣都是一組行數(shù)據(jù)且通過v$active_session_history視圖來返回每個被抽樣活動會話的行數(shù)據(jù),返回最新被抽樣會話的第一行數(shù)據(jù)。
一、ASH報告生成
繼上一篇AWR方面的博客之后,https://smilenicky.blog.csdn.net/article/details/89414432,我再寫一篇ASH方面的博客:
1.1 工具選擇
對于Oracle數(shù)據(jù)庫可以使用sqlplus或者plsql developer客戶端軟件
sqlplus 使用
可以使用sqlplus工具登錄
進入數(shù)據(jù)庫
sqlplus / as sysdba
1
查看用戶
show parameter db_name
1
用登錄之后才可以使用
plsql developer使用
plsql developer也可以使用,登錄之后,選擇文件(File)->新建(New)->命令窗口(Command Window)
1.2 自動創(chuàng)建快照
開始壓測后執(zhí)行
exec DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT ();
1
可以通過dba_hist_wr_control查看當前的配置情況,當前awr為每1小時做一次數(shù)據(jù)快照,保留時間為8天。
select * from dba_hist_wr_control;
1
修改配置,每隔30分鐘收集一次,保存1天
execute dbms_workload_repository.modify_snapshot_settings(interval=>30,retention=>14000);
1
關閉自動收集
SQL>exec dbms_workload_repository.modify_snapshot_settings (interval=>0,retention=>24*60);
1
1.3 手工創(chuàng)建快照
除了自動創(chuàng)建快照,也可以手工創(chuàng)建快照
select dbms_workload_repository.create_snapshot() from dual;
1
1.4 ASH報告生成
對于sqlplus客戶端的可以使用
@?/rdbms/admin/ashrpt.sql
1
對于plsql客戶端,我用絕對路徑去執(zhí)行,@?的命令找不到文件
這個要根據(jù)自己的Oracle安裝路徑去修改,例如:
@D:/oracle/product/11.1.0/db_1/RDBMS/ADMIN/ashrpt.sql
1
(1)日志報告類型
Enter value for report_type: text
選擇生成的ASH 報告類型,是text 還是html,一般選擇html
(2)日志報告起始時間
Enter value for begin_time: 04/18/1920:00:00
輸入ASH 開始的時間,時間格式上面的示例有說明,比如我這里是2019年4月18日晚上20:00:00開始。
(3)日志報告結束時間
Enter value for duration:15
輸入ASH 結束時間,默認是SYSDATE - begin_time,一般輸入,一般默認是秒或者分組,拿出15分組的ash分析日志來。
(4) ASH報告名稱
Enter value of report name:ash20190420
輸入ASH報告名稱,可以隨意填,非生產(chǎn),報告名稱,打印的日志后面可以找到報告存放路徑,比如:
D:\oracle\product\11.2.0\dbhome_1\RDBMS\ADMIN\ash.html
SQL> @D:/oracle/product/11.1.0/db_1/RDBMS/ADMIN/ashrpt.sql Current Instance ~~~~~~~~~~~~~~~~ DBID DB_NAME INST_ INST_NAME ---------- ------------ ----- ------------ 1525762377 ORCL 1 orcl Specify the Report Type ~~~~~~~~~~~~~~~~~~~~~~~ Enter 'html' for an HTML report, or 'text' for plain text Defaults to 'html' Type Specified: html Instances in this Workload Repository schema ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DBBID INSTT DBB_NAME INSTT_NAME HOST ------------ ----- ------------ ------------ ------------ * 1525762377 1 ORCL orcl PC-201508171 906 Defaults to current database Using database id: 1525762377 Enter instance numbers. Enter 'ALL' for all instances in a RAC cluster or explicitly specify list of instances (e.g., 1,2,3). Defaults to current instance. Using instance number(s): 1 PL/SQL procedure successfully completed ... 0 PL/SQL procedure successfully completed ... 18-Apr-19 22:05:54 ASH Samples in this Workload Repository schema ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Oldest ASH sample available: 09-Apr-19 22:00:36 [ 12968 mins in the past] Latest ASH sample available: 18-Apr-19 22:05:54 [ 3 mins in the past] ... 18-Apr-19 22:05:54 Specify the timeframe to generate the ASH report ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Enter begin time for report: -- Valid input formats: -- To specify absolute begin time: -- [MM/DD[/YY]] HH24:MI[:SS] -- Examples: 02/23/03 14:30:15 -- 02/23 14:30:15 -- 14:30:15 -- 14:30 -- To specify relative begin time: (start with '-' sign) -- -[HH24:]MI -- Examples: -1:15 (SYSDATE - 1 Hr 15 Mins) -- -25 (SYSDATE - 25 Mins) Defaults to -15 mins Report begin time specified: 04/18/1920:00:00 PL/SQL procedure successfully completed 18-Apr-20 00:00:00 Enter duration in minutes starting from begin time: Defaults to SYSDATE - begin_time Press Enter to analyze till current time Report duration specified: 7200 PL/SQL procedure successfully completed ... 23-Apr-20 00:00:00 Specify Slot Width (using ashrpti.sql) for 'Activity Over Time' section ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- Explanation: -- In the 'Activity Over Time' section of the ASH report, -- the analysis period is divided into smaller slots -- and top wait events are reported in each of those slots. -- Default: -- The analysis period will be automatically split upto 10 slots -- complying to a minimum slot width of -- 1 minute, if the source is V$ACTIVE_SESSION_HISTORY or -- 5 minutes, if the source is DBA_HIST_ACTIVE_SESS_HISTORY. Specify Slot Width in seconds to use in the 'Activity Over Time' section: Defaults to a value as explained above: Slot Width specified: Specify Report Targets (using ashrpti.sql) to generate the ASH report ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- Explanation: -- ASH Report can accept "Report Targets", -- like a particular SQL statement, or a particular SESSION, -- to generate the report on. If one or more report targets are -- specified, then the data used to generate the report will only be -- the ASH samples that pertain to ALL the specified report targets. -- Default: -- If none of the report targets are specified, -- then the target defaults to all activity in the database instance. Specify SESSION_ID (eg: from V$SESSION.SID) report target: Defaults to NULL: SESSION report target specified: Specify SQL_ID (eg: from V$SQL.SQL_ID) report target: Defaults to NULL: (% and _ wildcards allowed) SQL report target specified: Specify WAIT_CLASS name (eg: from V$EVENT_NAME.WAIT_CLASS) report target: [Enter 'CPU' to investigate CPU usage] Defaults to NULL: (% and _ wildcards allowed) WAIT_CLASS report target specified: Specify SERVICE_HASH (eg: from V$ACTIVE_SERVICES.NAME_HASH) report target: Defaults to NULL: SERVICE report target specified: Specify MODULE name (eg: from V$SESSION.MODULE) report target: Defaults to NULL: (% and _ wildcards allowed) MODULE report target specified: Specify ACTION name (eg: from V$SESSION.ACTION) report target: Defaults to NULL: (% and _ wildcards allowed) ACTION report target specified: Specify CLIENT_ID (eg: from V$SESSION.CLIENT_IDENTIFIER) report target: Defaults to NULL: (% and _ wildcards allowed) CLIENT_ID report target specified: Specify PLSQL_ENTRY name (eg: "SYS.DBMS_LOB.*") report target: Defaults to NULL: (% and _ wildcards allowed) PLSQL_ENTRY report target specified: Specify the Report Name ~~~~~~~~~~~~~~~~~~~~~~~ The default report file name is ashrpt_1_0423_0000.html. To use this name, press
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
遇到問題:假如執(zhí)行命令遇到:ORA-01843:無效月份報錯,就可以執(zhí)行下面sql
ALTER SESSION SET NLS_LANGUAGE=American; alter session set NLS_DATE_FORMAT='DD-MON-YY';
1
2
二、ASH報告指標分析
ASH報告就非常直接了,直接給出等待事件和哪些SQL關聯(lián),然后我們就可以拿SQL去調(diào)優(yōu)了
圖來自《收獲,不止SQL優(yōu)化》一書
Oracle SQL
版權聲明:本文內(nèi)容由網(wǎng)絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實的內(nèi)容,請聯(lián)系我們jiasou666@gmail.com 處理,核實后本網(wǎng)站將在24小時內(nèi)刪除侵權內(nèi)容。