獲取top N cpu pid的sql資訊指令碼
cpu佔用top N的程式及其上執行的sql資訊指令碼
指令碼的作用是根據ps aux命令獲得的cpu佔用前N位的程式資訊,並查處這幾個進場上執行的sql語句,執行計劃以及其他的一些資訊。預設,這裡的N位5
很多其他的功能都可以在其上擴充套件,比如可以再加上sql語句相關的表的索引資訊,表上是否有統計等。
這裡指令碼是以oracle使用者執行的。
很多其他的功能都可以在其上擴充套件,比如可以再加上sql語句相關的表的索引資訊,表上是否有統計等。
這裡指令碼是以oracle使用者執行的。
#!/bin/sh
# Copyright (c) Corporation. All rights reserved.
#
# DESCRIPTION
#
# This script. requests the top cpu load operating system processes identifier(PID) ,
# and then display the infomation about the sql statements on these pid.
#
# NOTES
# Usually run as the oracle on AIX
#
# MODIFIED (MM/DD/YY)
# xigua 03/18/08
#
# generate sql scripts
#
. $HOME/.profile
cd $HOME
cat > get.sql <-- Set up binds for pid,p_address and p_hashvalue
variable pid number;
variable p_address varchar2(30);
variable p_hashvalue varchar2(30);
-- Get the value of pid
begin
:pid := &pid;
end;
/
-- Get the value of p_address and p_hashvalue
begin
select decode(sql_hash_value,0, prev_hash_value,sql_hash_value),
decode(sql_address,0, prev_sql_addr, sql_address)
into :p_address,:p_hashvalue
from v\$session s
where s.paddr = (select addr
from v\$process p
where p.spid = :pid))
;
end;
/
--set sqlplus environment
clear break compute;
repfooter off;
ttitle off;
btitle off;
set timing off veri off space 1 flush on pause off termout on numwidth 10;
set echo off feedback off pagesize 80 linesize 80 newpage 1 recsep off;
set trimspool on trimout on;
set heading on;
Prompt
Prompt The session information about the process
Prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
col "LOGIN" for a10
col "CLIENT MACHINE" for a15
col program for a30
select s.sid,s.serial#,s.username "LOGIN",s.machine "CLIENT MACHINE",p.program
from v\$session s,v\$process p
where s.paddr = p.addr
and p.spid = :pid ;
Prompt
Prompt The SQL statement execute on the process
Prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
select sql_text from v\$sqltext
where address = :p_address
and hash_value = :p_hashvalue
order by piece;
Prompt
Prompt The Execution plan for the SQL statement
Prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
col id for 999
col parent_id for 999
col "Execution plan" for a40
SELECT id,parent_id,LPAD(' ',4*(LEVEL-1))||operation||' '||options||' '||object_name "Execution plan",
cardinality "rows produced"
FROM (
SELECT * FROM v\$sql_plan
WHERE address = :p_address
AND hash_value = :p_hashvalue
)
CONNECT BY PRIOR id = parent_id
START WITH id = 0;
!SC
#
# get top N cpu load pid,N default vaule is 5
#
# Copyright (c) Corporation. All rights reserved.
#
# DESCRIPTION
#
# This script. requests the top cpu load operating system processes identifier(PID) ,
# and then display the infomation about the sql statements on these pid.
#
# NOTES
# Usually run as the oracle on AIX
#
# MODIFIED (MM/DD/YY)
# xigua 03/18/08
#
# generate sql scripts
#
. $HOME/.profile
cd $HOME
cat > get.sql <-- Set up binds for pid,p_address and p_hashvalue
variable pid number;
variable p_address varchar2(30);
variable p_hashvalue varchar2(30);
-- Get the value of pid
begin
:pid := &pid;
end;
/
-- Get the value of p_address and p_hashvalue
begin
select decode(sql_hash_value,0, prev_hash_value,sql_hash_value),
decode(sql_address,0, prev_sql_addr, sql_address)
into :p_address,:p_hashvalue
from v\$session s
where s.paddr = (select addr
from v\$process p
where p.spid = :pid))
;
end;
/
--set sqlplus environment
clear break compute;
repfooter off;
ttitle off;
btitle off;
set timing off veri off space 1 flush on pause off termout on numwidth 10;
set echo off feedback off pagesize 80 linesize 80 newpage 1 recsep off;
set trimspool on trimout on;
set heading on;
Prompt
Prompt The session information about the process
Prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
col "LOGIN" for a10
col "CLIENT MACHINE" for a15
col program for a30
select s.sid,s.serial#,s.username "LOGIN",s.machine "CLIENT MACHINE",p.program
from v\$session s,v\$process p
where s.paddr = p.addr
and p.spid = :pid ;
Prompt
Prompt The SQL statement execute on the process
Prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
select sql_text from v\$sqltext
where address = :p_address
and hash_value = :p_hashvalue
order by piece;
Prompt
Prompt The Execution plan for the SQL statement
Prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
col id for 999
col parent_id for 999
col "Execution plan" for a40
SELECT id,parent_id,LPAD(' ',4*(LEVEL-1))||operation||' '||options||' '||object_name "Execution plan",
cardinality "rows produced"
FROM (
SELECT * FROM v\$sql_plan
WHERE address = :p_address
AND hash_value = :p_hashvalue
)
CONNECT BY PRIOR id = parent_id
START WITH id = 0;
!SC
#
# get top N cpu load pid,N default vaule is 5
#
N=5
if [ $# -ge 1 ]; then
if [ $# -eq 1 ]; then
N=$1
else
echo "Error, you had enter too may parameters. "
echo "USAGE:sh $(basename $0) N "
exit 1
fi
fi
ps aux |grep oracle${ORACLE_SID} | grep -v grep | sort -nr | head -${N} > pid.txt
for pidnum in ` cat ./pid.txt |awk '{print $2}'`
do
sqlplus -s '/as sysdba' <clear break compute;
repfooter off;
ttitle off;
btitle off;
set timing off veri off space 1 flush on pause off termout on numwidth 10;
set echo off feedback off pagesize 80 linesize 80 newpage 1 recsep off;
set trimspool on trimout on;
set heading on;
Prompt
Prompt The operation system process identifies : $pidnum
Prompt
@get.sql
$pidnum
!EOF
done
#
# remove the temp file
#
rm -f get.sql
rm -f pid.txt
ps aux |grep oracle${ORACLE_SID} | grep -v grep | sort -nr | head -${N} > pid.txt
for pidnum in ` cat ./pid.txt |awk '{print $2}'`
do
sqlplus -s '/as sysdba' <clear break compute;
repfooter off;
ttitle off;
btitle off;
set timing off veri off space 1 flush on pause off termout on numwidth 10;
set echo off feedback off pagesize 80 linesize 80 newpage 1 recsep off;
set trimspool on trimout on;
set heading on;
Prompt
Prompt The operation system process identifies : $pidnum
Prompt
@get.sql
$pidnum
!EOF
done
#
# remove the temp file
#
rm -f get.sql
rm -f pid.txt
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10867315/viewspace-209677/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Python 指令碼之獲取CPU資訊Python指令碼
- AWR 中 top sql 的資訊獲取 - 分析SQL
- Linux下在指令碼中獲取程式ID(PID)Linux指令碼
- mac獲取cpu資訊Mac
- 【DataGuarad】獲取standby 庫的配置資訊的指令碼指令碼
- 實時獲取最耗CPU的SQLSQL
- 獲取sql完整指令碼,get_fulltext.shSQL指令碼
- 一次捕獲SQL調優資訊的指令碼 sql9.sqlSQL指令碼
- 一次捕獲SQL調優資訊的指令碼 sql10.sqlSQL指令碼
- 利用javascript獲取圖片的top N主色值JavaScript
- vbs指令碼獲取Am註冊路徑資訊指令碼
- 獲取linux伺服器基本資訊指令碼Linux伺服器指令碼
- Linux cpuinfo cpu資訊獲取詳解LinuxUI
- [Android]獲取整體APP CPU資訊AndroidAPP
- TOP N 查詢 SQLSQL
- postgresql定位top cpu sqlSQL
- oracle獲取ddl指令碼Oracle指令碼
- 獲取所有域使用者的登陸歷史資訊指令碼指令碼
- 深入 Nodejs 原始碼探究 CPU 資訊的獲取與利用率計算NodeJS原始碼
- 監控使用高cpu的sql語句指令碼SQL指令碼
- 批次過程獲取指令碼指令碼
- 獲取 CPU資訊,並透過登錄檔寫入
- 見過最全的獲取資料庫資訊的指令碼--生成html的報告資料庫指令碼HTML
- 【SQL】如何獲得表及欄位的說明資訊(comment)的建立指令碼SQL指令碼
- 單個過程獲取指令碼指令碼
- Android程式碼獲取CPU執行情況Android
- 透過hostname獲取IP的perl指令碼指令碼
- 檢視錶的統計資訊SQL指令碼SQL指令碼
- shell指令碼中如何報錯即刻退出以及如何獲取子shell指令碼的錯誤資訊:set -o errexit指令碼
- Jquery中獲取iframe的程式碼(window.top.parent)jQuery
- 透過top命令抓取cpu高消耗的sqlSQL
- 通過top命令抓取cpu高消耗的sqlSQL
- 直播軟體原始碼,js獲取n天前的日期原始碼JS
- 獲取指定pid的session的pga/uga使用情況Session
- 獲取完整的sqltext指令碼。get_fulltext.shSQL指令碼
- 指令碼:獲取當前的User Trace檔案指令碼
- 常用指令碼:獲取隱含引數指令碼
- 獲取單個檢視DDL指令碼指令碼