AWRスナップショット間隔と保存期間の設定
2016-03-20
対応バージョン
Oracle Database 10.2 - 12.1
2015-01-15AWRレポートについての記載をリンク
2014-12-25記事公開
よく使用する便利ツールの公開です。
※ カスタマイズなどのご要望がございましたら、お見積りいたしますので、弊社までお問い合わせください。
指定した時間内のスナップショットから、インスタンス毎のAWRレポートをテキスト形式で出力します。
RAC環境での動作テストは行っておりません。
awr.shを作成し、oracleユーザにて以下のように実行します。
1 |
awr.sh [引数1:DB名] [引数2:開始時間] [引数3:終了時間] |
実行例
1 2 3 4 5 6 7 8 9 10 11 12 |
# su - oracle $ chmod 755 /tmp/awr.sh $ /tmp/awr.sh orcl 2014/12/21:00:00:00 2014/12/26:00:00:00 BeginDate 2014/12/21:00:00:00 EndDate 2014/12/26:00:00:00 -rw-r--r--. 1 oracle oinstall 228744 12月 25 16:43 2014 /tmp/awrrpt_orcl_1_1_2.txt -rw-r--r--. 1 oracle oinstall 206964 12月 25 16:43 2014 /tmp/awrrpt_orcl_1_3_4.txt -- 省略 -- -rw-r--r--. 1 oracle oinstall 198540 12月 25 16:44 2014 /tmp/awrrpt_orcl_1_20_21.txt -rw-r--r--. 1 oracle oinstall 156358 12月 25 16:44 2014 /tmp/awrrpt_orcl_1_22_23.txt |
以下にawr.sh シェルの内容を示します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
#!/bin/bash # Copyright 2012-2014 SIX SQUARE JAPAN.co.,ltd. All Rights Reserved. # 本著作物は例を示したサンプルであり、資料の内容を利用した場合について、 # 弊社が一切の責任を負うものではありません。 # Version: # Ver 1.0 - 2014/12/25 - 新規作成 # Description: # インスタンス毎のAWRレポートを生成する # Usage: # parameter1: 実行ノードにおける出力対象DBのORACLE_SID # parameter2: 出力範囲の開始日付(YYYY/MM/DD:HH24:MI:SS) # parameter3: 出力範囲の終了日付(YYYY/MM/DD:HH24:MI:SS) ############################################################################### # レポートファイルの出力先定義 REPORT=/tmp # 使い方のエラーメッセージ定義 _USAGE="Usage $0 [ORACLE_SID] [Begin(YYYY/MM/DD:HH24:MI:SS)] [End(YYYY/MM/DD:HH24:MI:SS)]" # 実行ユーザの確認 if [ ${USER} != "oracle" ]; then echo "Change to oracle user(OS)." exit 1 fi # 引数の数を確認 if [ $# -ne 3 ]; then echo "${_USAGE}" exit 1 fi ORACLE_SID=$1 _BEGIN_DATE=$2 _END_DATE=$3 export ORACLE_SID # PMONの起動を確認 ps aux | grep -v grep | grep -q ora_pmon_${ORACLE_SID} _PMON_STATUS=$? if [ ${_PMON_STATUS} -ne 0 ]; then echo "Not found the database of ${ORACLE_SID}." exit 1 fi # フォーマットの確認(YYYY/MM/DD:HH24:MI:SS) echo "BeginDate" echo "${_BEGIN_DATE}" | grep "^[1-2][0-1][0-9][0-9]/[0-1][0-9]/[0-3][0-9]:[0-2][0-9]:[0-5][0-9]:[0-5][0-9]$" _FM_STATUS=$? if [ ${_FM_STATUS} -ne 0 ]; then echo "Wrong format of BeginDate.(${_BEGIN_DATE})." echo "${_USAGE}" exit 1 fi # フォーマットの確認(YYYY/MM/DD:HH24:MI:SS) echo "EndDate" echo "${_END_DATE}" | grep "^[1-2][0-1][0-9][0-9]/[0-1][0-9]/[0-3][0-9]:[0-2][0-9]:[0-5][0-9]:[0-5][0-9]$" _FM_STATUS=$? if [ ${_FM_STATUS} -ne 0 ]; then echo "Wrong format of EndDate.(${_END_DATE})." echo "${_USAGE}" exit 1 fi if [ -z "${ORACLE_HOME}" ]; then echo "The value of environment variable is not set.(ORACLE_HOME)" exit 1 fi PATH=${ORACLE_HOME}/bin:${PATH}:/usr/bin:/bin:/sbin export PATH mkdir -p -m777 ${REPORT} if [ ! -d "${REPORT}" ]; then echo "Failed to create a directory.(${REPORT})" exit 1 fi # DBID,InstanceNum,SnapIDの順で対象の期間取得 _SNAPSHOT_INFOS=`sqlplus -s -L / as sysdba << SQL_EOF set pages 0 line 3000 trim on trims on timi off time off echo off term off select dbid||','||instance_number||','||snap_id from dba_hist_snapshot where BEGIN_INTERVAL_TIME between to_timestamp('${_BEGIN_DATE}','YYYY/MM/DD:HH24:MI:SS') and to_timestamp('${_END_DATE}','YYYY/MM/DD:HH24:MI:SS') or END_INTERVAL_TIME between to_timestamp('${_BEGIN_DATE}','YYYY/MM/DD:HH24:MI:SS') and to_timestamp('${_END_DATE}','YYYY/MM/DD:HH24:MI:SS') order by dbid,instance_number,snap_id; exit SQL_EOF` # DBIDとInstanceNumのユニークソート(一意の組み合わせを判定) _DBID_INSTS=`echo "${_SNAPSHOT_INFOS}" | cut -d',' -f1,2 | sort -u` # 各組合せごとに処理を行う for _DBID_INST in ${_DBID_INSTS} do # 対象のDBIDとインスタンスの塊を取得 _SNAPSHOT_INFO_GROUPS=`echo "${_SNAPSHOT_INFOS}" | grep "^${_DBID_INST},"` # 初回BeginSnapIDを取得 _B_SPSHOT=`echo "${_SNAPSHOT_INFO_GROUPS}" | head -1 | cut -d',' -f3` for _SNAPSHOT_INFO in `echo "${_SNAPSHOT_INFO_GROUPS}" | sed -e 1d` do _DBID=`echo "${_SNAPSHOT_INFO}" | cut -d',' -f1` _INST_NUM=`echo "${_SNAPSHOT_INFO}" | cut -d',' -f2` _E_SPSHOT=`echo "${_SNAPSHOT_INFO}" | cut -d',' -f3` sqlplus -s -L / as sysdba << SQL_EOF > /dev/null set trim on trims on term off define report_type=text define num_days=1 define begin_snap=${_B_SPSHOT} define end_snap=${_E_SPSHOT} define dbid=${_DBID} define inst_num=${_INST_NUM} define report_name=${REPORT}/awrrpt_${ORACLE_SID}_${_INST_NUM}_${_B_SPSHOT}_${_E_SPSHOT}.txt @?/rdbms/admin/awrrpti.sql exit SQL_EOF # スナップショット間に停止起動がある場合、ファイル出力されない為確認しない if [ -f ${REPORT}/awrrpt_${ORACLE_SID}_${_INST_NUM}_${_B_SPSHOT}_${_E_SPSHOT}.txt ]; then ls -l ${REPORT}/awrrpt_${ORACLE_SID}_${_INST_NUM}_${_B_SPSHOT}_${_E_SPSHOT}.txt grep ORA- ${REPORT}/awrrpt_${ORACLE_SID}_${_INST_NUM}_${_B_SPSHOT}_${_E_SPSHOT}.txt fi # 最後のスナップショットについては次回の開始スナップショットにする _B_SPSHOT=${_E_SPSHOT} done done exit 0 |