博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
oracle 定位热块和热链的方法
阅读量:5061 次
发布时间:2019-06-12

本文共 5870 字,大约阅读时间需要 19 分钟。

定位热链的方法

declare

        v_num number;
begin
        for i in 1..1000000
        loop
                select sal into v_num
                from emp
                where ename='SMITH';
        end loop;
end;
/

declare

        v_num number;
begin
        for i in 1..1000000
        loop
                select sal into v_num
                from emp
                where ename='KING';
        end loop;
end;
/

declare

        v_num number;
begin
        for i in 1..1000000
        loop
                select sal into v_num
                from emp
                where ename='SCOTT';
        end loop;
end;
/

一.获取当前系统等待事件

select event, count(*) from v$session
where wait_class <> 'Idle' group by event order by 2;

EVENT            COUNT(*)

---------------------------------------------------------- ----------
SQL*Net message to client         1
latch: cache buffers chains         1

>

二.获取哪些活跃会话正在处于latch: cache buffers chains
select sid,username,event,p1raw,sql_id,logon_time,last_call_et
from v$session where event='latch: cache buffers chains' and status='ACTIVE'
> /

 

 SID USERNAME      EVENT       P1RAW      SQL_ID  LOGON_TIM LAST_CALL_ET

----------- ---------------- ------------------------------ ------------------------------ ------------- --------- ------------
 138 SCOTT      latch: cache buffers chains    0000000082FED878     766dr19szth9c 07-OCT-14      18
 140 SCOTT      latch: cache buffers chains    0000000082E3FCC0     5mmqfh10738vp 07-OCT-14      15

>

三.确认等待的P1RAW是否出现很多是相同的.

> l
  1  select sid,p1raw,p2,p3,seconds_in_wait,wait_time,state from v$session_wait
  2* where event='latch: cache buffers chains' order by 3,2
> /

 SID P1RAW       P2  P3 SECONDS_IN_WAIT  WAIT_TIME STATE

----------- ---------------- ---------- ---------- --------------- ---------- -------------------
 140 0000000082E3FCC0     122   1  15    10 WAITED KNOWN TIME
 138 0000000082E3FCC0     122   0   3    -1 WAITED SHORT TIME

>

四.找出这个latch管理的对象.

 关注TCH值
> undefine latch_addr
> l
    select a.hladdr,a.file#,a.dbablk,a.tch,a.obj,b.object_name from x$bh a, dba_objects b
    where (a.obj = b.object_id or a.obj = b.data_object_id) and a.hladdr = '&&latch_addr'
    union select hladdr,file#,dbablk,tch,obj,null from x$bh
   where obj in (select obj from x$bh where hladdr = '&latch_addr'
   minus select object_id from dba_objects
   minus select data_object_id from dba_objects) and hladdr = '&latch_addr' order by 4
> /
Enter value for latch_addr: 0000000082E3FCC0

HLADDR        FILE# DBABLK       TCH  OBJ OBJECT_NAME

---------------- ---------- ---------- ---------- ---------- ------------------------------
0000000082E3FCC0   1  55349  0   92 DEPENDENCY$
0000000082E3FCC0   2   1662  1 4294967295
0000000082E3FCC0   3    963  1 3709 WRI$_ADV_RATIONALE_PK
0000000082E3FCC0   3   4835  1 9246
0000000082E3FCC0   3   5068  1      51296 ORDER_ITEMS
0000000082E3FCC0   3   5068  1      51296 WRH$_PARAMETER
0000000082E3FCC0   4  17383  1      52516 O1
0000000082E3FCC0   4  39306  1      52516 O1
0000000082E3FCC0   4  60530  1      52516 O1
0000000082E3FCC0   4  60763  1      52516 O1
0000000082E3FCC0   4  60996  1      52516 O1
0000000082E3FCC0   4  61229  1      52516 O1
0000000082E3FCC0   4  64868  1      52516 O1
0000000082E3FCC0   4  65101  1      52516 O1
0000000082E3FCC0   4  65334  1      52516 O1
0000000082E3FCC0   4  65567  1      52516 O1
0000000082E3FCC0   4  69206  1      52516 O1
0000000082E3FCC0   4  69439  1      52516 O1
0000000082E3FCC0   4  69672  1      52516 O1
0000000082E3FCC0   4  69905  1      52516 O1
0000000082E3FCC0   4  70138  1      52516 O1
0000000082E3FCC0   3  23119        39      49873 SYS_IOT_OVER_49872
0000000082E3FCC0   4     31       411      51151 EMP

23 rows selected.

>

五.根据sql_id获取到相应SQL.结合SQL中的对象.结合上面的TCH值进一步判断热块.

> select executions,sql_text from v$sqlarea where sql_id in ('766dr19szth9c','5mmqfh10738vp');

EXECUTIONS SQL_TEXT

---------- ------------------------------------------------------------
   7000000 SELECT SAL FROM EMP WHERE ENAME='KING'
  45374216 SELECT SAL FROM EMP WHERE ENAME='SCOTT'

>

六.复杂SQL,太多表关联,要依据执行计划来判断.

 

 

定位热块的方法

 

latch: buffer busy waits    等待事件

 原因:
  热块 修改导致

declare

        v_num number;
begin
   for i in 1..1000000
   loop
    select sal into v_num
    from emp
    where ename='SMITH';
      update emp set sal=sal+0
     where ename='SMITH';
     commit;
   end loop;
end;
/

declare

        v_num number;
begin
   for i in 1..1000000
   loop
    select sal into v_num
    from emp
    where ename='KING';
      update emp set sal=sal+0
     where ename='KING';
     commit;
   end loop;
end;
/

declare

        v_num number;
begin
   for i in 1..1000000
   loop
    select sal into v_num
    from emp
    where ename='SCOTT';
      update emp set sal=sal+0
     where ename='SCOTT';
     commit;
   end loop;
end;
/

> select event, count(*) from v$session where wait_class <> 'Idle' group by event order by 2;
> /

EVENT            COUNT(*)

---------------------------------------------------------- ----------
log file switch (checkpoint incomplete)        1
SQL*Net message to client         1
buffer busy waits          2

>

> select sid,username,event,p1,p2,p3,sql_id,logon_time,last_call_et
   from v$session where event='buffer busy waits' and status='ACTIVE'

> /

 SID USERNAME      EVENT        P1        P2   P3 SQL_ID    LOGON_TIM LAST_CALL_ET

----------- ---------------- ------------------------------ ---------- ---------- ---------- ------------- --------- ------------
 138 SCOTT      buffer busy waits        4        32    1 dh3kc1jqtnxw5 07-OCT-14       249
 140 SCOTT      buffer busy waits        4        32    1 71ssxfx45kyrh 07-OCT-14       246
 158 SCOTT      buffer busy waits        4        32    1 5vcss49awm6fn 07-OCT-14       252

>

    SELECT  owner , segment_name , segment_type

    FROM  dba_extents
    WHERE  file_id = &FileNumber
   AND  &BlockNumber BETWEEN block_id AND block_id + blocks -1
> /
Enter value for filenumber: 4
old   3: WHERE file_id = &FileNumber
new   3: WHERE file_id = 4
Enter value for blocknumber: 32
old   4: AND  &BlockNumber BETWEEN block_id AND block_id + blocks -1
new   4: AND  32 BETWEEN block_id AND block_id + blocks -1

OWNER      SEGMENT_NAME        SEGMENT_TYPE

------------ ------------------------- ------------------
SCOTT      EMP         TABLE

>

 

SYS_S:191_P:5773_ora11g> select * from v$waitstat order by 1;

CLASS   COUNT     TIME

------------------ ---------- ----------
1st level bmb      0        0
2nd level bmb      0        0
3rd level bmb      0        0
bitmap block      0        0
bitmap index block     0        0
data block      0        0
extent map      0        0
file header block    60      240
free list      0        0
save undo block      0        0
save undo header     0        0
segment header      0        0
sort block      0        0
system undo block     0        0
system undo header     0        0
undo block      0        0
undo header      1        0
unused       0        0

18 rows selected. 

转载于:https://www.cnblogs.com/travel6868/p/5010699.html

你可能感兴趣的文章
AJAX
查看>>
ActiveMQ与spring整合
查看>>
web服务器
查看>>
js数组操作大全
查看>>
创业者要处理好的10大关系
查看>>
佛教和道教对“妖”的差异
查看>>
[TimLinux] Python IDE工具
查看>>
[TimLinux] Python Django与WSGI的简介
查看>>
从其它系统登录到SharePoint 2010系统的单点登录
查看>>
ElMAH(ASP.NET错误日志记录与通知)系列文章-基础应用篇
查看>>
pexpect学习阶段
查看>>
做最多的,展示最好的
查看>>
会员未登录显示ID=1的会员信息 解决方案
查看>>
Git与Repo入门(转载)
查看>>
夺命雷公狗---linux NO:10 linux的文件与目录的基本操作
查看>>
Flask16 项目结构、flask_script插件
查看>>
html5 的头部
查看>>
一个计时器, 点击按钮 让他 停一会, 5s后继续自动运行
查看>>
UVA - 1585 Score
查看>>
漫画算法:深度优先遍历 和 广度优先遍历
查看>>