TA的每日心情 | 开心 2023-8-9 11:05 |
---|
|
- --等待事件组
- select WAIT_CLASS,
- TOTAL_WAITS,
- round(100 * (TOTAL_WAITS / SUM_WAITS), 2) PCT_WAITS,
- ROUND((TIME_WAITED / 100), 2) TIME_WAITED_SECS,
- round(100 * (TIME_WAITED / SUM_TIME), 2) PCT_TIME
- from (select WAIT_CLASS, TOTAL_WAITS, TIME_WAITED
- from V$SYSTEM_WAIT_CLASS
- where WAIT_CLASS != 'Idle'),
- (select sum(TOTAL_WAITS) SUM_WAITS, sum(TIME_WAITED) SUM_TIME
- from V$SYSTEM_WAIT_CLASS
- where WAIT_CLASS != 'Idle')
- order by 5 desc;
- select WAIT_CLASS,count(*) from v$session_wait where wait_time is not null group by WAIT_CLASS order by 2 desc;
- --等待事件top
- set linesize 120
- col event for a60
- select event,
- sum(decode(wait_time, 0, 0, 1)) prev,
- sum(decode(wait_time, 0, 1, 0)) cur,
- count(*) tot
- from v$session_wait
- group by event
- order by 4 desc;
- --等待耗时top
- select *
- from (select event, total_waits, average_wait
- from v$system_event
- where event not like 'SQL%'
- order by 3 desc)
- where rownum <= 10;
- --查询当前的top_sql,根据cpu_time,elapsed_time,disk_read,executions等条件替换
- select sql_id,command_type,cpu_time
- from
- (select sql_id,
- command_type,
- cpu_time,
- rank() over(order by disk_read desc) exec_rank
- from v$sql)
- where exec_rank <= 10
- --根据等待事件查询相关的sql语句
- select b.*, sq.sql_text
- from v$session se,
- v$sql sq,
- (select a.*
- from v$sql s,
- (select sid, p1
- from v$session_wait
- where event = 'library cache: mutex X') a
- where s.hash_value = a.p1) b
- where se.sid = b.sid
- and se.sql_hash_value = sq.hash_value
- select sql_id
- from v$sql
- where hash_value in (select distinct p1 from v$session_wait
- where event = 'log file sync')
- select sid,serial#,username,blocking_session,ROW_WAIT_OBJ#,ROW_WAIT_BLOCK# from v$session where event='select b.*, sq.sql_text
- from v$session se,
- v$sql sq,
- (select a.*
- from v$sql s,
- (select sid, p1
- from v$session_wait
- where event = 'library cache: mutex X') a
- where s.hash_value = a.p1) b
- where se.sid = b.sid
- and se.sql_hash_value = sq.hash_value
- select sql_id
- from v$sql
- where hash_value in (select distinct p1 from v$session_wait
- where event = 'log file sync')';
- --根据等待事件查询cursor pin s wait on x 的语句
- select a.*, s.sql_text
- from v$sql s,
- (select sid,
- event,
- wait_class,
- p1 cursor_hash_value,
- p2raw Mutex_value,
- to_number(substr(p2raw, 1, 8), 'xxxxxxxx') hold_nutex_x_sid
- from v$session_wait
- where event like 'cursor%') a
- where s.hash_value = a.cursor_hash_value
复制代码
|
|