【AWR】自動生成AWR報告指令碼以及用法
1,使用ftp工具上傳檔案autoawrrpt.sh到伺服器/home/oracle目錄
2,以Oracle使用者登入,修改shell指令碼執行許可權
[root@PrimaryDB oracle]# su - oracle
[oracle@PrimaryDB ~]$ chmod 755 autoawrrpt.sh
3,shell指令碼使用方法
./autoawrrpt.sh -s orcl -f 2013092917 -t 2013092918 -p HTML -h /home/ora11g/product/11.1.0
4,autoawrrpt.sh是附件shell指令碼
shell指令碼引數說明:
-f 2013092917 開始時間 格式年月日小時
-t 2013092918 結束時間 格式年月日小時
-p 格式 html或者是text
-h 環境變數ORACLE_HOME的值
-s 環境變數ORACLE_SID的值
5,使用瀏覽器開啟當前目錄下awr報告檔案,定位到SQL ordered by CPU Time部分分析
附autoawrrpt.shshell指令碼內容:
#!/bin/bash
# ********************************
# * autoawrrpt.sh
# ********************************
# Usage: autoawrrpt.sh -s [instance_name]
# -f [from time]
# -t [to time]
# -p [report type, html or text]
# -h [oracle home]
# -n [tns admin]
#
# time format: 'yyyymmddhh24'.
# E.g 2011030417 means 05pm, Mar 04, 2011
#
#
# **********************
# get parameters
# **********************
while getopts ":s:f:t:p:h:n" opt
do
case $opt in
s) instance=$OPTARG
;;
f) from=$OPTARG
;;
t) to=$OPTARG
;;
p) type=$OPTARG
type=$(echo $type|tr "[:upper:]" "[:lower:]")
;;
h) oracle_home=$OPTARG
;;
n) tns_admin=$OPTARG
;;
'?') echo "$0: invalid option -$OPTARG">&2
exit 1
;;
esac
done
if [ "$instance" = "" ]
then
echo "instance name(-s) needed"
echo "program exiting..."
exit 1
fi
if [ "$from" = "" ]
then
echo "from time (-f} needed"
echo "program exiting..."
exit 1
fi
if [ "$to" = "" ]
then
echo "to time (-t) needed"
echo "program exiting..."
exit 1
fi
if [ "${oracle_home}" = "" ]
then
echo "oracle home (-h) needed"
echo "program exiting..."
exit 1
fi
sqlplus="${oracle_home}/bin/sqlplus"
echo $sqlplus
if [ "$type" = "" ]
then
type="html"
fi
# ********************
# trim function
# ********************
function trim()
{
local result
result=`echo $1|sed 's/^ *//g' | sed 's/ *$//g'`
echo $result
}
# *******************************
# read interchange ID & passwd
# *******************************
#read_act()
#{
#echo "interchange ID: "
#read user
#echo "password: "
#stty -echo
#read pswd
#stty echo
#}
# *******************************
# get begin and end snapshot ID
# *******************************
define_dur()
{
begin_id=`$sqlplus -s /nolog<
set pages 0
set head off
set feed off
select max(SNAP_ID) from DBA_HIST_SNAPSHOT where
BEGIN_INTERVAL_TIME<=to_date($from,'yyyymmddhh24');
EOF`
ret_code=$?
if [ "$ret_code" != "0" ]
then
echo "sqlplus failed with code $ret_code"
echo "program exiting..."
exit 10
fi
end_id=`$sqlplus -s /nolog<
set pages 0
set head off
set feed off
select min(SNAP_ID) from DBA_HIST_SNAPSHOT where
END_INTERVAL_TIME>=to_date($to,'yyyymmddhh24');
spool off
EOF`
ret_code=$?
if [ "$ret_code" != "0" ]
then
echo "sqlplus failed with code $ret_code"
echo "program exiting..."
exit 10
fi
begin_id=$(trim ${begin_id})
end_id=$(trim ${end_id})
# echo "begin_id: $begin_id end_id: $end_id"
}
# *******************************
# generate AWR report
# *******************************
generate_awr()
{
awrsql="${oracle_home}/rdbms/admin/awrrpt.sql"
if [ ! -e $awrsql ]
then
echo "awrrpt.sql does not exist, exiting..."
exit 20
fi
tmp1_id=${begin_id}
#echo "begin_id is: $begin_id"
#echo "tmp1_id is: $tmp1_id"
while [ ${tmp1_id} -lt ${end_id} ]
do
let tmp2_id=${tmp1_id}+1
if [ $type = "text" ]
then
report_name="awrrpt_${instance}_${tmp1_id}_${tmp2_id}.txt"
else
report_name="awrrpt_${instance}_${tmp1_id}_${tmp2_id}.html"
fi
#echo $report_name
$sqlplus -s "/as sysdba">/dev/null<
define report_type=$type
define num_days=1
define begin_snap=${tmp1_id}
define end_snap=${tmp2_id}
define report_name=${report_name}
@${oracle_home}/rdbms/admin/awrrpt.sql
exit;
EOF
tmp1_id=${tmp2_id}
done
}
# *******************************
# main routing
# *******************************
#read_act
define_dur
generate_awr
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/14359/viewspace-774020/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- AWR報告自動生成指令碼指令碼
- 自動生成awr報告指令碼指令碼
- awr報告每天自動生成指令碼指令碼
- 【AWR】Oracle批量生成awr報告指令碼Oracle指令碼
- shell指令碼實現自動生成awr報告指令碼
- 一個自動生成awr報告的shell指令碼指令碼
- 生成awr報告的指令碼指令碼
- 自動生成AWR HTML報告HTML
- Oracle10g 自動生成AWR報告的指令碼Oracle指令碼
- 指令碼:定時生成awr報告指令碼
- Oracle10g自動生成AWR分析報告的指令碼Oracle指令碼
- 定時自動生成awr報告
- 轉貼:批量生成awr報告指令碼指令碼
- AWR Report 自動生成指令碼 [final]指令碼
- awr自動收集指令碼指令碼
- Oracle生成awr報告Oracle
- Oracle 生成awr報告Oracle
- 手工生成AWR分析報告
- 自動生成AWR報告並以郵件附件傳送
- 【效能優化】sqlplus中使用指令碼生成awr報告優化SQL指令碼
- 使用shell自動傳送Oracle AWR報告Oracle
- ORACLE 11G生成AWR報告Oracle
- 自動生成ASH報告指令碼指令碼
- 儲存過程批量生成awr指令碼儲存過程指令碼
- Oracle 11g RAC 如何生成AWR報告?Oracle
- Oracle 11g RAC生成 AWR 報告方法Oracle
- AWR不能自動生成快照解決方法?
- AWR解析報告分析
- mysql-awr報告MySql
- oracle效能awr報告Oracle
- awr 自動mailAI
- 通過shell指令碼抓取awr報告中的問題sql指令碼SQL
- 透過shell指令碼抓取awr報告中的問題sql指令碼SQL
- 本機生成遠端資料庫AWR報告資料庫
- 手工生成AWR執行期對比報告記錄
- AWR報告基礎操作
- Oracle AWR報告大綱Oracle
- oracle 產生awr 報告Oracle