查找消耗资源多的sql

1 通过top监控操作系统负载发现:
top
top - 09:17:15 up 43 days, 18:51,  5 users,  load average: 38.78, 37.45, 28.53                                                                                                  
Tasks: 391 total,  44 running, 346 sleeping,   0 stopped,   1 zombie                                                                                                            
Cpu(s): 95.8%us,  3.1%sy,  0.0%ni,  0.0%id,  0.0%wa,  0.0%hi,  1.1%si,  0.0%st                                                                                                  
Mem:  16336460k total, 15764084k used,   572376k free,    71200k buffers                                                                                                        
Swap: 17591288k total,  1132188k used, 16459100k free, 12091484k cached                                                                                                         
                                                                                                                                                                                
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                            
10840 oracle    20   0 12.3g 321m 313m R  9.8  2.0  34:42.91 oracle                                                                                                             
10856 oracle    20   0 12.3g 640m 631m R  9.5  4.0  33:49.30 oracle                                                                                                             
11341 oracle    20   0 12.3g 626m 622m R 9.5  3.9   4:13.94 oracle                                                                                                             
11369 oracle    20   0 12.3g 626m 616m R  9.5  3.9   4:23.53 oracle                                                                                                             
11524 oracle    20   0 12.3g 610m 606m R  9.5  3.8   1:39.00 oracle                                                                                                             
11534 oracle    20   0 12.3g 291m 287m R 9.5  1.8   1:32.16 oracle                                                                                                             
11625 oracle    20   0 12.3g 474m 469m R  9.5  3.0   0:57.79 oracle                                                                                                             
11643 oracle    20   0 12.3g 288m 283m R 9.5  1.8   1:06.34 oracle                                                                                                             
11260 oracle    20   0 12.3g 654m 649m R  9.1  4.1   5:18.50 oracle                                                                                                             
11351 oracle    20   0 12.3g 1.0g 1.0g R  9.1  6.6   5:30.35 oracle                                                                                                             
11639 oracle    20   0 12.3g 448m 444m R  9.1  2.8   1:09.25 oracle                                                                                                             
11681 oracle    20   0 12.3g 274m 270m R  9.1  1.7   0:40.24 oracle                                                                                                             
10713 oracle    20   0 12.3g 786m 777m R  8.8  4.9  34:02.16 oracle                                                                                                             
11237 oracle    20   0 12.3g 730m 726m R  8.8  4.6   6:43.29 oracle                                                                                                             
11262 oracle    20   0 12.3g 651m 647m R  8.8  4.1   5:03.98 oracle                                                                                                             
11331 oracle    20   0 12.3g 589m 581m R  8.8  3.7   3:27.44 oracle                                                                                                             
11563 oracle    20   0 12.3g 319m 315m R  8.8  2.0   1:38.29 oracle                                                                                                             
11569 oracle    20   0 12.3g 494m 490m R  8.8  3.1   1:09.75 oracle                                                                                                             
11605 oracle    20   0 12.3g 283m 279m R  8.8  1.8   1:26.11 oracle                                                                                                             
11607 oracle    20   0 12.3g 229m 226m R  8.8  1.4   1:20.35 oracle                                                                                                             
11663 oracle    20   0 12.3g 285m 281m R  8.8  1.8   0:47.90 oracle                                                                                                             
11665 oracle    20   0 12.3g 495m 490m R  8.8  3.1   0:22.92 oracle                                                                                                             
11667 oracle    20   0 12.3g 517m 514m R  8.8  3.2   0:36.17 oracle                                                                                                             
11730 oracle    20   0 12.3g 226m 222m R  8.8  1.4   0:22.71 oracle                                                                                                             
11744 oracle    20   0 12.3g 179m 175m R  8.8  1.1   0:23.03 oracle                                                                                                             
11276 oracle    20   0 12.3g 761m 756m R  8.5  4.8   4:32.40 oracle                                                                                                             
11347 oracle    20   0 12.3g 694m 689m R  8.5  4.4   3:49.45 oracle                                                                                                             
11498 oracle    20   0 12.3g 570m 566m R  8.5  3.6   2:09.96 oracle                                                                                                             
11567 oracle    20   0 12.3g 298m 294m R  8.5  1.9   1:13.86 oracle                                                                                                             
11645 oracle    20   0 12.3g 556m 552m R  8.5  3.5   1:00.15 oracle                                                                                                             
11683 oracle    20   0 12.3g 460m 456m R  8.5  2.9   0:28.87 oracle                                                                                                             
11726 oracle    20   0 12.3g 158m 155m R  8.5  1.0   0:28.52 oracle                                                                                                             
11746 oracle    20   0 12.3g 234m 230m R  8.5  1.5   0:23.50 oracle                                                                                                             
11222 oracle    20   0 12.3g 638m 632m R  8.2  4.0   5:41.07 oracle                                                                                                             
11466 oracle    20   0 12.3g 542m 538m R  8.2  3.4   2:55.76 oracle                                                                                                             


通过top监控到数据库CPU使用率达到了95%以上,并且都是oracle进程


2 通过操作系统的pid定位在数据库执行的sql语句:
select sql_text from v$process pr,v$session ss,v$sqlarea sl where pr.addr=ss.PADDR  and ss.SQL_HASH_VALUE=sl.HASH_VALUE and pr.spid=10840;
select sql_text from v$process pr,v$session ss,v$sqlarea sl where pr.addr=ss.PADDR  and ss.SQL_HASH_VALUE=sl.HASH_VALUE and pr.spid=10856;
select sql_text from v$process pr,v$session ss,v$sqlarea sl where pr.addr=ss.PADDR  and ss.SQL_HASH_VALUE=sl.HASH_VALUE and pr.spid=11341;
select sql_text from v$process pr,v$session ss,v$sqlarea sl where pr.addr=ss.PADDR  and ss.SQL_HASH_VALUE=sl.HASH_VALUE and pr.spid=11369;
select sql_text from v$process pr,v$session ss,v$sqlarea sl where pr.addr=ss.PADDR  and ss.SQL_HASH_VALUE=sl.HASH_VALUE and pr.spid=11524;
select sql_text from v$process pr,v$session ss,v$sqlarea sl where pr.addr=ss.PADDR  and ss.SQL_HASH_VALUE=sl.HASH_VALUE and pr.spid=11534;
select sql_text from v$process pr,v$session ss,v$sqlarea sl where pr.addr=ss.PADDR  and ss.SQL_HASH_VALUE=sl.HASH_VALUE and pr.spid=11625;
select sql_text from v$process pr,v$session ss,v$sqlarea sl where pr.addr=ss.PADDR  and ss.SQL_HASH_VALUE=sl.HASH_VALUE and pr.spid=11643;
发现占用资源较高的进程所执行的sql语句

你可能感兴趣的:(查找消耗资源多的sql)