獲取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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 獲取sql完整指令碼,get_fulltext.shSQL指令碼
- vbs指令碼獲取Am註冊路徑資訊指令碼
- postgresql定位top cpu sqlSQL
- 深入 Nodejs 原始碼探究 CPU 資訊的獲取與利用率計算NodeJS原始碼
- 獲取所有域使用者的登陸歷史資訊指令碼指令碼
- 獲取 CPU資訊,並透過登錄檔寫入
- shell指令碼整合json數值輸出從而獲取硬體資訊指令碼JSON
- jenkins pipline指令碼 獲取git分支Jenkins指令碼Git
- Jquery中獲取iframe的程式碼(window.top.parent)jQuery
- Kubernetes 教程:根據 PID 獲取 Pod 名稱
- 常用指令碼:獲取隱含引數指令碼
- 獲取位置資訊
- 直播軟體原始碼,js獲取n天前的日期原始碼JS
- 如何使用 Bash 指令碼從 SAR 報告中獲取 CPU 和記憶體使用情況指令碼記憶體
- 在SQL隱碼攻擊中使用DNS獲取資料SQLDNS
- 採用lua指令碼獲取mysql、redis資料以及jwt的校驗指令碼MySqlRedisJWT
- 【Redis】獲取沒有設定ttl的key指令碼Redis指令碼
- 獲取AWR的指令碼,可以在crontab裡面部署指令碼
- Python一鍵獲取日漫Top100榜單電影資訊Python
- shell指令碼獲取函式返回值指令碼函式
- shell指令碼獲取時間格式化指令碼
- Linux: 獲取硬碟的UUID資訊Linux硬碟UI
- 獲取.crt證書的資訊
- 【IDL】獲取n*n陣列的對角線元素的方法陣列
- 使用捕獲 獲取身份證號的資訊
- python kubernetes 獲取 pod 的 cpu 佔用率Python
- [20221216]建立修改表統計資訊minmaxtab.sql指令碼.txtSQL指令碼
- [20221216]建立修改表統計資訊modtab.sql指令碼.txtSQL指令碼
- Oracle優化案例-教你線上搞定top cpu的sql(十二)Oracle優化SQL
- 小程式獲取帶有分享者資訊的小程式碼
- 使用ajax指令碼取資料指令碼
- oracle刪除超過N天資料指令碼的方法Oracle指令碼
- Linux c程式中獲取shell指令碼輸出(如獲取system命令輸出)LinuxC程式指令碼
- iphone 獲取地址的詳細資訊iPhone
- Oracle獲取所有表名資訊和獲取指定表名欄位資訊Oracle
- 獲取陣列第N個元素的方法陣列
- [系列] Go - 基於 GORM 獲取當前請求所執行的 SQL 資訊GoORMSQL
- 前端獲取視訊編碼格式前端
- 7種Linux中獲取CPU速度的方法Linux