1. 程式人生 > >檢視前五個最佔用CPU的Oracle會話程序.以及他們正在執行的sql語句

檢視前五個最佔用CPU的Oracle會話程序.以及他們正在執行的sql語句

#!/bin/bash

ps -e -o pcpu -o pid -o user -o args | grep oraclemktdb | sort -k 1| tail -5r
spid=`ps -e -o pcpu -o pid -o user -o args | grep oraclemktdb | sort -k 1| tail -5r | awk '{print $2}'`
for i in $spid
do
sqlplus -S /nolog << EOF
conn / as sysdba
set feedback off
set linesize 200
set pagesize 70
column spid format 99999

column sid format 99999
column module format a20
column username format a8
column sql_text format a60
select distinct c.spid,b.sid,b.username,a.module,a.hash_value,sql_text
from v$sql a,v$session b,v$process c
where a.hash_value=b.sql_hash_value and a.address=b.sql_address and b.paddr=c.addr and c.spid =$i;

exit
EOF
done