浅谈oracle数据库dbtime
1、如果等待时间比服务时间长很多,那我们就要优化等待时间,如果服务时间比等待时间长很多,就要先优化服务时间
这就是owi思想
那我们就需要判断整个数据库系统平均响应时间中服务时间(Service time)和等待时间(Wait time)各占的百分比。
服务时间代表的是“ cpu used by this session”,是cpu服务会话所花费的所有时间。
Response Time = Service Time + Wait TIme(即响应时间=cpu服务时间+等待时间)
select a.value "Total cpu time" from v$sysstat a where a.name='cpu used by this session';
sql>selecta.value"Totalcputime"fromv$sysstatawherea.name='cpuusedbythissession'; Totalcputime -------------- 997592 Elapsed:00:00:00.01 sql>
2、会话级
(1)查看统计号 这里为2
select statistic# from v$statname where name='cpu used by this session';
sql>selectstatistic#fromv$statnamewherename='cpuusedbythissession'; 2
(2)查v$sesstat
select sid,a.value "Total cpu time " from v$sesstat a where a.statistic#=2;
查看每一个会话的cpu时间
sql>selectsid,a.value"Totalcputime"fromv$sesstatawherea.statistic#=2; SIDTotalcputime ------------------------- 11 21 221 231 431 441 461 641 651 661 851 861 881 1071 1081 1091 1271 1291 1481 1491 1691 1721 1731 1901 1911 1931 2111 2131 2321 2331 30rowsselected.
3、Service Time = sql解析时间 + 递归调用时间 + 其它时间
(1)sql/PLsql等解析时所花的时间,如果解析时间超过总的cpu服务时间20%,那么需要调优应用程序代码,比如绑定变量、SESSION_CURSOR_CACHE等
怎么样来查看sql解析时间呢?分实例级和会话级
实例级:
select NAME,statistic# from v$statname where name like '%parse%';
sql>selectNAME,statistic#fromv$statnamewherenamelike'%parse%'; NAMESTATISTIC# -------------------------------------------------------------------------- parsetimecpu547 parsetimeelapsed548 parsecount(total)549 parsecount(hard)550 parsecount(failures)551 parsecount(describe)552
select a.value "Total parse cpu time" from v$sysstat a where a.name='parse time cpu';
统计号是548
sql>selecta.value"Totalparsecputime"fromv$sysstatawherea.name='parsetimecpu'; Totalparsecputime -------------------- 64984 Elapsed:00:00:00.00
会话级:
select sid,a.value "Total parse cpu time" from v$sesstat a where a.statistic#=548;
sql>selectsid,a.value"Totalparsecputime"fromv$sesstatawherea.statistic#=548; SIDTotalparsecputime ------------------------------ 10 20 220 230 430 44785 464 640 652 665 850 86225 880 1070 1082 1090 1271 1293 1480 1496 1690 1720 1730 1900 1910 2110 2130 2320 233571 29rowsselected.
(2) 递归调用时间是用在:语义分析阶段查找数据字典或者PLsql内部包造成的解析所花的cpu时间。就是内部字典的一些动作。
select name,statistic# from v$statname where name like '%cpu%';
sql>selectname,statistic#fromv$statnamewherenamelike'%cpu%'; NAMESTATISTIC# -------------------------------------------------------------------------- recursivecpuusage9 parsetimecpu547
这里统计号为9
select a.value "Total recursive cpu time" from v$sysstat a where a.name='recursive cpu usage';
sql>selecta.value"Totalrecursivecputime"fromv$sysstatawherea.name='recursivecpuusage'; Totalrecursivecputime ------------------------ 509888 Elapsed:00:00:00.00
通过查找v$sysstat,v$sesstat,我们可以查看到递归调用的时间。
我们知道sga分类为library cache+rowcache
rowcache数据字典(data dictionary cache )
数据字典cache怎么优化?多半是一些不规范的参数导致,_row_cr 11g 隐含参数的问题
(3)一般来说。其他时间 ,在这里是花费最多的时间(多cpu 的 调度也在这里)
总的来说
select a.value "Total cpu",b.value "parse cpu",c.value "recursive cpu",a.value - b.value - c.value "Other"
from v$sysstat a,v$sysstat b,v$sysstat c
where a.name='cpu used by this session'
and b.name='parse time cpu'
and c.name='recursive cpu usage';
sql>selecta.value"Totalcpu",b.value"parsecpu",c.value"recursivecpu",a.value-b.value-c.value"Other" fromv$sysstata,v$sysstatb,v$sysstatc wherea.name='cpuusedbythissession' andb.name='parsetimecpu' 5andc.name='recursivecpuusage'; TotalcpuparsecpurecursivecpuOther ------------------------------------------- 99892864995509941423992 Elapsed:00:00:00.01
刚刚好: 998928 = 64995 + 509941 + 423992
(4)等待事件分两类: 非空闲 + 空闲等待事件(IDLE)
大部分空闲等待事件 都是客户端相关的消息传输事件
大量idel等待事件造成的性能问题,极有可能是应用服务器本身问题,或者网络问题,因为cpu 都空闲了。
查看下数据库的等待事件数据
select event,time_waited,average_wait from v$system_event
where event not in (
'pmon time',
'smon timer',
'rdbms ipc message',
'parallel dequeue wait',
'virtual circuit',
'sql*Net message from client',
'client message',
'NULL event'
)
order by time_waited desc;
结果如下:
EVENT TIME_WAITED AVERAGE_WAIT
---------------------------------------------------------------- ----------- ------------
DIAG idle wait 935522655 100.09
jobq slave wait 497321787 50.08
shared server idle wait 467876357 3000.92
Streams AQ: qmn coordinator idle wait 467875026 1400.44
Streams AQ: qmn slave idle wait 467873982 2737.96
dispatcher timer 467872026 6000.98
pmon timer 467819350 264.77
Space Manager: slave idle wait 467784915 499.1
Streams AQ: waiting for time management or cleanup tasks 464980103 1690836.74
VKRM Idle 169919651 3146660.21
os thread startup 290703 1.59
control file parallel write 126076 .08
log file parallel write 100734 .03
log file sync 61970 .08
db file async I/O submit 34403 .03
library cache lock 22077 959.85
PL/sql lock timer 12407 98.47
control file sequential read 6042 0
ADR block file read 1845 .11
auto-sqltune: wait graph update 1500 250.02
Disk file operations I/O 1482 0
direct path sync 778 1.05
log file switch completion 537 .81
control file heartbeat 400 400
reliable message 392 .05
sql*Net message to client 375 0
db file sequential read 364 .01
resmgr:internal state change 342 10.06
class slave wait 327 .01
asynch descriptor resize 326 0
switch logfile command 227 56.68
rdbms ipc reply 209 .06
enq: CR - block range reuse ckpt 134 .07
LGWR wait for redo copy 112 0
undo segment extension 110 .75
ADR block file write 91 .01
db file scattered read 85 .01
log file single write 55 .04
JS coord start wait 50 50.02
enq: PR - contention 36 1.17
db file single write 35 .02
enq: RO - fast object reuse 27 .01
latch: shared pool 25 .03
direct path write temp 24 .01
latch free 19 .15
Data file init write 15 .21
这是oracle性能调优的基础。
原文链接:https://www.f2er.com/oracle/212191.html