10gTop N Timed Events統計
我們可以透過awr去檢視
Normal
0
7.8 磅
0
2
false
false
false
EN-US
ZH-CN
X-NONETop 5 Timed Events,但粒度還是不夠細,對於秒殺類的活動,我們可能需要統計到分鐘甚至更細,我們也可能老是更改awr的粒度,我們可以採用一種變通的方式去實現類似更能。
在10g中,並沒有方便統計分鐘級的事件等待時間,為了方便統計分鐘級的等待事件等待時間,
可以採用如下方式
--建立v$sys_time_model備份表
create table SYSTIMEMODEL_LOG
(
STAT_ID NUMBER,
STAT_NAME VARCHAR2(64),
VALUE NUMBER,
CREATETIME DATE
)
partition by range (CREATETIME)
(
partition P_20131001 values less than (TO_DATE(' 2013-10-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
tablespace monitor,
partition P_20131101 values less than (TO_DATE(' 2013-11-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
tablespace monitor,
partition P_20131201 values less than (TO_DATE(' 2013-12-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
tablespace monitor,
partition P_20140101 values less than (TO_DATE(' 2014-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
tablespace monitor
)
;
--建立v$system_event備份表
create table SYSTEMEVENT_LOG
(
EVENT VARCHAR2(64),
TOTAL_WAITS NUMBER,
TOTAL_TIMEOUTS NUMBER,
TIME_WAITED NUMBER,
AVERAGE_WAIT NUMBER,
TIME_WAITED_MICRO NUMBER,
EVENT_ID NUMBER,
WAIT_CLASS_ID NUMBER,
WAIT_CLASS# NUMBER,
WAIT_CLASS VARCHAR2(64),
CREATETIME DATE
)
partition by range (CREATETIME)
(
partition P_20131001 values less than (TO_DATE(' 2013-10-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
tablespace monitor,
partition P_20131101 values less than (TO_DATE(' 2013-11-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
tablespace monitor,
partition P_20131201 values less than (TO_DATE(' 2013-12-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
tablespace monitor,
partition P_20140101 values less than (TO_DATE(' 2014-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
tablespace monitor
)
;
--建立備份v$system_event與v$sys_time_model備份的儲存過程。
CREATE OR REPLACE PROCEDURE productmon.PRC_SYSTIMEMODEL IS
BEGIN
insert into SYSTIMEMODEL_LOG
select STAT_ID ,STAT_NAME,VALUE,sysdate from v$sys_time_model;
commit;
END PRC_SYSTIMEMODEL;
CREATE OR REPLACE PROCEDURE PRC_SYSTEMEVENT IS
BEGIN
insert into SYSTEMEVENT_LOG
select EVENT,TOTAL_WAITS,TOTAL_TIMEOUTS,TIME_WAITED,AVERAGE_WAIT,TIME_WAITED_MICRO,EVENT_ID,WAIT_CLASS_ID,WAIT_CLASS#,WAIT_CLASS,sysdate from v$system_event;
commit;
END PRC_SYSTEMEVENT;
--建立job,每分鐘執行一次
begin
productmon.PRC_SYSTIMEMODEL;
productmon.PRC_SYSTEMEVENT;
end;
--按照awr中sql改寫查詢sql,這樣我們就可以統計人員粒度為分鐘的等待事件查詢了,這對於秒殺類的活動的負載統計將十分有效
SELECT EVENT,
WAITS,
TIME,
DECODE(WAITS,
NULL,
TO_NUMBER(NULL),
0,
TO_NUMBER(NULL),
TIME / WAITS * 1000) AVGWT,
PCTWTT,
WAIT_CLASS
FROM (SELECT EVENT, WAITS, TIME, PCTWTT, WAIT_CLASS
FROM (SELECT E.EVENT EVENT,
E.TOTAL_WAITS - NVL(B.TOTAL_WAITS, 0) WAITS,
(E.TIME_WAITED_MICRO - NVL(B.TIME_WAITED_MICRO, 0)) /
1000000 TIME,
100 *
(E.TIME_WAITED_MICRO - NVL(B.TIME_WAITED_MICRO, 0)) /
((SELECT sum(value)
FROM PRODUCTMON.Systimemodel_Log e
WHERE createtime=to_date('2013-9-18 10:12:17','yyyy-mm-dd hh24:mi:ss')
AND e.STAT_NAME = 'DB time') -
(SELECT sum(value)
FROM PRODUCTMON.Systimemodel_Log b
WHERE createtime=to_date('2013-9-18 10:11:17','yyyy-mm-dd hh24:mi:ss')
AND b.STAT_NAME = 'DB time')) PCTWTT,
E.WAIT_CLASS WAIT_CLASS
FROM PRODUCTMON.SYSTEMEVENT_LOG B, PRODUCTMON.SYSTEMEVENT_LOG E
WHERE B.createtime = to_date('2013-9-18 10:11:17','yyyy-mm-dd hh24:mi:ss')
AND E.createtime = to_date('2013-9-18 10:12:17','yyyy-mm-dd hh24:mi:ss')
AND B.EVENT_ID(+) = E.EVENT_ID
AND E.TOTAL_WAITS > NVL(B.TOTAL_WAITS, 0)
AND E.WAIT_CLASS != 'Idle'
UNION ALL
SELECT 'CPU time' EVENT,
TO_NUMBER(NULL) WAITS,
((SELECT sum(value)
FROM PRODUCTMON.Systimemodel_Log e
WHERE e.createtime = to_date('2013-9-18 10:12:17','yyyy-mm-dd hh24:mi:ss')
AND e.STAT_NAME = 'DB CPU') -
(SELECT sum(value)
FROM PRODUCTMON.Systimemodel_Log b
WHERE b.createtime = to_date('2013-9-18 10:11:17','yyyy-mm-dd hh24:mi:ss')
AND b.STAT_NAME = 'DB CPU')) / 1000000 TIME,
100 * ((SELECT sum(value)
FROM PRODUCTMON.Systimemodel_Log e
WHERE e.createtime = to_date('2013-9-18 10:12:17','yyyy-mm-dd hh24:mi:ss')
AND e.STAT_NAME = 'DB CPU') -
(SELECT sum(value)
FROM PRODUCTMON.Systimemodel_Log b
WHERE b.createtime = to_date('2013-9-18 10:11:17','yyyy-mm-dd hh24:mi:ss')
AND b.STAT_NAME = 'DB CPU')) /
((SELECT sum(value)
FROM PRODUCTMON.Systimemodel_Log e
WHERE e.createtime = to_date('2013-9-18 10:12:17','yyyy-mm-dd hh24:mi:ss')
AND e.STAT_NAME = 'DB time') -
(SELECT sum(value)
FROM PRODUCTMON.Systimemodel_Log b
WHERE b.createtime = to_date('2013-9-18 10:11:17','yyyy-mm-dd hh24:mi:ss')
AND b.STAT_NAME = 'DB time')) PCTWTT,
NULL WAIT_CLASS
from dual
WHERE ((SELECT sum(value)
FROM PRODUCTMON.Systimemodel_Log e
WHERE e.createtime = to_date('2013-9-18 10:12:17','yyyy-mm-dd hh24:mi:ss')
AND e.STAT_NAME = 'DB CPU') -
(SELECT sum(value)
FROM PRODUCTMON.Systimemodel_Log b
WHERE b.createtime = to_date('2013-9-18 10:11:17','yyyy-mm-dd hh24:mi:ss')
AND b.STAT_NAME = 'DB CPU')) > 0)
ORDER BY TIME DESC, WAITS DESC)
WHERE ROWNUM <= 5;
EVENT WAITS TIME AVGWT PCTWTT WAIT_CLASS
---------------------------------------------------------------- ---------- ---------- ---------- ---------- ----------------------------------------------------------------
CPU time 384.046156 45.9012772
db file sequential read 102380 235.221073 2.29752952 28.1136720 User I/O
db file scattered read 51499 97.292668 1.88921470 11.6284401 User I/O
read by other session 73688 77.392337 1.05027055 9.24994838 User I/O
log file sync 30880 60.359582 1.95464967 7.21418992 Commit
5 rows selected
Executed in 0.157 seconds
10:49:15 SQL>
在10g中,並沒有方便統計分鐘級的事件等待時間,為了方便統計分鐘級的等待事件等待時間,
可以採用如下方式
--建立v$sys_time_model備份表
create table SYSTIMEMODEL_LOG
(
STAT_ID NUMBER,
STAT_NAME VARCHAR2(64),
VALUE NUMBER,
CREATETIME DATE
)
partition by range (CREATETIME)
(
partition P_20131001 values less than (TO_DATE(' 2013-10-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
tablespace monitor,
partition P_20131101 values less than (TO_DATE(' 2013-11-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
tablespace monitor,
partition P_20131201 values less than (TO_DATE(' 2013-12-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
tablespace monitor,
partition P_20140101 values less than (TO_DATE(' 2014-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
tablespace monitor
)
;
--建立v$system_event備份表
create table SYSTEMEVENT_LOG
(
EVENT VARCHAR2(64),
TOTAL_WAITS NUMBER,
TOTAL_TIMEOUTS NUMBER,
TIME_WAITED NUMBER,
AVERAGE_WAIT NUMBER,
TIME_WAITED_MICRO NUMBER,
EVENT_ID NUMBER,
WAIT_CLASS_ID NUMBER,
WAIT_CLASS# NUMBER,
WAIT_CLASS VARCHAR2(64),
CREATETIME DATE
)
partition by range (CREATETIME)
(
partition P_20131001 values less than (TO_DATE(' 2013-10-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
tablespace monitor,
partition P_20131101 values less than (TO_DATE(' 2013-11-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
tablespace monitor,
partition P_20131201 values less than (TO_DATE(' 2013-12-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
tablespace monitor,
partition P_20140101 values less than (TO_DATE(' 2014-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
tablespace monitor
)
;
--建立備份v$system_event與v$sys_time_model備份的儲存過程。
CREATE OR REPLACE PROCEDURE productmon.PRC_SYSTIMEMODEL IS
BEGIN
insert into SYSTIMEMODEL_LOG
select STAT_ID ,STAT_NAME,VALUE,sysdate from v$sys_time_model;
commit;
END PRC_SYSTIMEMODEL;
CREATE OR REPLACE PROCEDURE PRC_SYSTEMEVENT IS
BEGIN
insert into SYSTEMEVENT_LOG
select EVENT,TOTAL_WAITS,TOTAL_TIMEOUTS,TIME_WAITED,AVERAGE_WAIT,TIME_WAITED_MICRO,EVENT_ID,WAIT_CLASS_ID,WAIT_CLASS#,WAIT_CLASS,sysdate from v$system_event;
commit;
END PRC_SYSTEMEVENT;
--建立job,每分鐘執行一次
begin
productmon.PRC_SYSTIMEMODEL;
productmon.PRC_SYSTEMEVENT;
end;
--按照awr中sql改寫查詢sql,這樣我們就可以統計人員粒度為分鐘的等待事件查詢了,這對於秒殺類的活動的負載統計將十分有效
SELECT EVENT,
WAITS,
TIME,
DECODE(WAITS,
NULL,
TO_NUMBER(NULL),
0,
TO_NUMBER(NULL),
TIME / WAITS * 1000) AVGWT,
PCTWTT,
WAIT_CLASS
FROM (SELECT EVENT, WAITS, TIME, PCTWTT, WAIT_CLASS
FROM (SELECT E.EVENT EVENT,
E.TOTAL_WAITS - NVL(B.TOTAL_WAITS, 0) WAITS,
(E.TIME_WAITED_MICRO - NVL(B.TIME_WAITED_MICRO, 0)) /
1000000 TIME,
100 *
(E.TIME_WAITED_MICRO - NVL(B.TIME_WAITED_MICRO, 0)) /
((SELECT sum(value)
FROM PRODUCTMON.Systimemodel_Log e
WHERE createtime=to_date('2013-9-18 10:12:17','yyyy-mm-dd hh24:mi:ss')
AND e.STAT_NAME = 'DB time') -
(SELECT sum(value)
FROM PRODUCTMON.Systimemodel_Log b
WHERE createtime=to_date('2013-9-18 10:11:17','yyyy-mm-dd hh24:mi:ss')
AND b.STAT_NAME = 'DB time')) PCTWTT,
E.WAIT_CLASS WAIT_CLASS
FROM PRODUCTMON.SYSTEMEVENT_LOG B, PRODUCTMON.SYSTEMEVENT_LOG E
WHERE B.createtime = to_date('2013-9-18 10:11:17','yyyy-mm-dd hh24:mi:ss')
AND E.createtime = to_date('2013-9-18 10:12:17','yyyy-mm-dd hh24:mi:ss')
AND B.EVENT_ID(+) = E.EVENT_ID
AND E.TOTAL_WAITS > NVL(B.TOTAL_WAITS, 0)
AND E.WAIT_CLASS != 'Idle'
UNION ALL
SELECT 'CPU time' EVENT,
TO_NUMBER(NULL) WAITS,
((SELECT sum(value)
FROM PRODUCTMON.Systimemodel_Log e
WHERE e.createtime = to_date('2013-9-18 10:12:17','yyyy-mm-dd hh24:mi:ss')
AND e.STAT_NAME = 'DB CPU') -
(SELECT sum(value)
FROM PRODUCTMON.Systimemodel_Log b
WHERE b.createtime = to_date('2013-9-18 10:11:17','yyyy-mm-dd hh24:mi:ss')
AND b.STAT_NAME = 'DB CPU')) / 1000000 TIME,
100 * ((SELECT sum(value)
FROM PRODUCTMON.Systimemodel_Log e
WHERE e.createtime = to_date('2013-9-18 10:12:17','yyyy-mm-dd hh24:mi:ss')
AND e.STAT_NAME = 'DB CPU') -
(SELECT sum(value)
FROM PRODUCTMON.Systimemodel_Log b
WHERE b.createtime = to_date('2013-9-18 10:11:17','yyyy-mm-dd hh24:mi:ss')
AND b.STAT_NAME = 'DB CPU')) /
((SELECT sum(value)
FROM PRODUCTMON.Systimemodel_Log e
WHERE e.createtime = to_date('2013-9-18 10:12:17','yyyy-mm-dd hh24:mi:ss')
AND e.STAT_NAME = 'DB time') -
(SELECT sum(value)
FROM PRODUCTMON.Systimemodel_Log b
WHERE b.createtime = to_date('2013-9-18 10:11:17','yyyy-mm-dd hh24:mi:ss')
AND b.STAT_NAME = 'DB time')) PCTWTT,
NULL WAIT_CLASS
from dual
WHERE ((SELECT sum(value)
FROM PRODUCTMON.Systimemodel_Log e
WHERE e.createtime = to_date('2013-9-18 10:12:17','yyyy-mm-dd hh24:mi:ss')
AND e.STAT_NAME = 'DB CPU') -
(SELECT sum(value)
FROM PRODUCTMON.Systimemodel_Log b
WHERE b.createtime = to_date('2013-9-18 10:11:17','yyyy-mm-dd hh24:mi:ss')
AND b.STAT_NAME = 'DB CPU')) > 0)
ORDER BY TIME DESC, WAITS DESC)
WHERE ROWNUM <= 5;
EVENT WAITS TIME AVGWT PCTWTT WAIT_CLASS
---------------------------------------------------------------- ---------- ---------- ---------- ---------- ----------------------------------------------------------------
CPU time 384.046156 45.9012772
db file sequential read 102380 235.221073 2.29752952 28.1136720 User I/O
db file scattered read 51499 97.292668 1.88921470 11.6284401 User I/O
read by other session 73688 77.392337 1.05027055 9.24994838 User I/O
log file sync 30880 60.359582 1.95464967 7.21418992 Commit
5 rows selected
Executed in 0.157 seconds
10:49:15 SQL>
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29033984/viewspace-772881/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- AWR--Top 5 Timed Foreground Events
- oracle gcr sleep in the Top Timed Events in reportOracleGC
- oracle eventsOracle
- 計算2的N次冪n 可輸入,n為自然數
- ORACLE EVENTS(轉)Oracle
- oracle set eventsOracle
- wait eventsAI
- EVENTS設定
- Fortran程式設計 n!程式設計
- ALTER SESSION SET EVENTSSession
- dump oracle events(轉)Oracle
- Enqueue events part oneENQ
- Enqueue events part twoENQ
- efcore 新特性 SaveChanges Events
- pointer-events屬性
- Oracle RAC Wait EventsOracleAI
- [Angular] Progress HTTP Events with 'HttpRequest'AngularHTTP
- Server-Sent Events 教程Server
- Understanding Delegated JavaScript EventsJavaScript
- alter session|system set eventsSession
- Simulating Mouse Events in JavaScriptJavaScript
- Data Guard Wait EventsAI
- Parallel Query Wait EventsParallelAI
- 全面學習ORACLE Scheduler特性(7)使用Events之Scheduler丟擲的EventsOracle
- 全面學習ORACLE Scheduler特性(8)使用Events之Application丟擲的EventsOracleAPP
- 改進的sql計算n王后SQL
- 計算2..n的素數
- 階乘之和 輸入n,計算S=1!+2!+3!+…+n!的末6位(不含前導0)。n≤10 6 ,n!表示 前n個正整數之積。
- Oracle Enqueues Wait Events 二OracleENQAI
- Oracle Enqueues Wait Events 一OracleENQAI
- Oracle Enqueues Wait Events 三OracleENQAI
- CSS3 pointer-eventsCSSS3
- MySQL Events學習筆記MySql筆記
- Oracle跟蹤事件 -- set eventsOracle事件
- 【DATAGUARD】Data Guard Wait EventsAI
- 幾個ORACLE wait eventsOracleAI
- Linux系統程式設計 - 07. 迴圈建立N個子程式分析Linux程式設計
- [Clickhouse] Clickhouse 報SQLException : Read timed outSQLException