首頁 >資料庫 >mysql教程 >模拟产生CBCLATCH与bufferbusywait等待事件

模拟产生CBCLATCH与bufferbusywait等待事件

WBOY
WBOY原創
2016-06-07 15:22:181090瀏覽

数据库版本:11.2.0.4.0 1.查出表TEST相关信息 select rowid, dbms_rowid.rowid_row_number(rowid) rowid_rownum, dbms_rowid.rowid_relative_fno(rowid) file_id, dbms_rowid.rowid_block_number(rowid) block_id,test.* from test; ROWID ROWID_ROWNUM FIL

数据库版本:11.2.0.4.0

1.查出表TEST相关信息

select rowid,
dbms_rowid.rowid_row_number(rowid) rowid_rownum,
dbms_rowid.rowid_relative_fno(rowid) file_id,
dbms_rowid.rowid_block_number(rowid) block_id,test.* from test;
ROWID ROWID_ROWNUM FILE_ID BLOCK_ID OBJECT_NAME STATUS
------------------ ------------ ---------- ---------- ------------ -------
AAAFSJAAEAAAACkAAA 0 4 164 10 15
AAAFSJAAEAAAACkAAB 1 4 164 10 15
可以看到,TEST表的两条记录在同一文件的同一个BLOCK中。

2.写一个循环:

循环执行查询语句一百万次:--查询164数据块的第一行
declare
aa varchar2(100);
begin
for i in 1..1000000 loop
select object_name into aa from test where rowid='AAAFSJAAEAAAACkAAA';
end loop;
end;
/

循环更新查询语句200次 --查询164数据块的第二行
declare
begin
for i in 1..200 loop
update test set status=15 where rowid='AAAFSJAAEAAAACkAAB';
end loop;
commit;
end;
/

3.打开两个会话,查出会话SID。--这里会话SID分别是30 35.

在30号会话执行循环查询:
BYS@ bys3>select sid from v$mystat where rownum=1;
SID
----------
30
节约篇幅,执行循环的语句就不贴了。

在35号会话执行循环更新语句:
BYS@ bys3>select sid from v$mystat where rownum=1;
SID
----------
35
节约篇幅,执行循环的语句就不贴了。

4.再打开一个会话,使用语句查询35 30号会话的等待事件

23:03:20 SYS@ bys3>select sid ,event,total_waits,total_timeouts,time_waited_micro from v$session_event
23:03:21 2 where sid in(30,35);

SID EVENT TOTAL_WAITS TOTAL_TIMEOUTS TIME_WAITED_MICRO
---------- ---------------------------------------- ----------- -------------- -----------------
30 buffer busy waits 1 0 968 --------这里30号会话是读操作,35号会话是写操作,也就是30号会话的读被写阻塞。
30 latch: In memory undo latch 1 0 960
30 resmgr:cpu quantum 3 0 33589
30 SQL*Net message to client 15 0 637
30 SQL*Net message from client 14 0 206010788
35 Disk file operations I/O 3 0 312
35 latch: cache buffers chains 2 0 1174
35 db file sequential read 64 0 9065
35 direct path read 100 0 53191
35 SQL*Net message to client 25 0 259
35 SQL*Net message from client 24 0 625117659
35 SQL*Net break/reset to client 4 0 1046

12 rows selected.

Elapsed: 00:00:00.02
23:03:22 SYS@ bys3>select sid ,event,total_waits,total_timeouts,time_waited_micro from v$session_event
23:03:30 2 where sid in(30,35) and event like '%buffer%';

SID EVENT TOTAL_WAITS TOTAL_TIMEOUTS TIME_WAITED_MICRO
---------- ---------------------------------------- ----------- -------------- -----------------
30 buffer busy waits 1 0 968
35 latch: cache buffers chains 2 0 1174

Elapsed: 00:00:00.03
查看等待事件截图:

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn