用SHELL 查看spid執行SQL

使用OS命令 top / topas(AIX) / glance(HP-UX) 看到TOP PROCESS 的時候,想立即知道某些一直在TOP 中的

ORACLE進程是那個應用發出、在跑什麼、在經歷什麼等待事件、耗時多久,下面這個腳本可以完成。

將下面腳本存在ssql.sh中,給執行權限

使用方法:

./ssql.sh  33903  /* 33903 是從TOP命令看到的 spid*/


#!/bin/ksh sqlplus -s '/as sysdba' <<EOF col machine format a20 set linesize 1000 set pagesize 8000 col program format a15 col sid format 999999 col serial# format 999999 col username format a10 col osuser format a10 col machine format a15 col event format a30 set timing off

prompt ########################################################### select a.sid,a.serial#,a.sql_id from v\$session a,v\$process b where b.SPID=$1 and a.PADDR=b.ADDR;

prompt ########################################################### select a.username, a.osuser, a.machine, to_char(a.logon_time,'yyyy/mm/dd hh24:mi:ss') LogonTime from v\$session a , v\$process b where b.SPID = $1 and a.paddr = b.addr;

prompt ########################################################### select a.program ,a.event,a.LAST_CALL_ET from v\$session a,v\$process b where a.paddr = b.addr and b.spid = $1;

prompt ########################################################### select a.sql_text from v\$sqltext a,v\$session b,v\$process c where c.spid = $1 and b.paddr = c.addr and a.hash_value = b.SQL_HASH_VALUE order by a.piece;

exit; EOF

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章