AWR 中 top sql 的資訊獲取 - 分析
1. 檢視資料庫AWR報告的生成頻率.
select * from dba_hist_wr_control;
2. 檢視AWR報告中sql_id 及 sql_text.
select * from dba_hist_sqlstat;
select * from dba_hist_sql_summary;
3. 檢視AWR報告中某一sql_id 的執行計劃.
select * from table(dbms_xplan.display_awr('66gs90fyynks7'));
select dbms_xplan.display_awr('66gs90fyynks7') from dual;
4. 後期分析待續.....................
工作時間段內以15min為粒度進行awr報告抽取(不包含週六、日,對於工作日不包含18:00—08:00的非工作時間)
+++++++++++++++++++++
#!/usr/bin/ksh
##############paramter######################
startdate=$1' 00:00:01'
enddate=$2' 23:59:59'
reporttype=$3
reportformat='text'
###################env######################
oraclehome=`echo $ORACLE_HOME`
startdate=$1' 00:00:01'
enddate=$2' 23:59:59'
reporttype=$3
reportformat='text'
###################env######################
oraclehome=`echo $ORACLE_HOME`
#############################################
dbname=`sqlplus -s "/ as sysdba" <set head off
set echo off
set feedback off
set linesize 120 ;
set pagesize 0;
set heading off;
select name from v\\$database;
quit;
EOF
`
dbid=`sqlplus -s "/ as sysdba" <set head off
set echo off
set feedback off
set linesize 120 ;
set pagesize 0;
set heading off;
select dbid from v\\$database;
quit;
EOF
`
dbname=`sqlplus -s "/ as sysdba" <
set echo off
set feedback off
set linesize 120 ;
set pagesize 0;
set heading off;
select name from v\\$database;
quit;
EOF
`
dbid=`sqlplus -s "/ as sysdba" <
set echo off
set feedback off
set linesize 120 ;
set pagesize 0;
set heading off;
select dbid from v\\$database;
quit;
EOF
`
instid=`sqlplus -s "/ as sysdba" <set head off
set echo off
set feedback off
set linesize 120 ;
set pagesize 0;
set heading off;
select instance_number from v\\$instance;
quit;
EOF `
set echo off
set feedback off
set linesize 120 ;
set pagesize 0;
set heading off;
select instance_number from v\\$instance;
quit;
EOF `
databaseid=$dbid
instanceid=`echo $instid|tr -d ' '`
instanceid=`echo $instid|tr -d ' '`
echo "from database-->"$dbname" database id--->"$dbid" instance id--->"$instanceid
echo "report type--->"$reporttype"|"$reporttype" snapshot from--->"$startdate" to--->"$enddate
echo "report type--->"$reporttype"|"$reporttype" snapshot from--->"$startdate" to--->"$enddate
if [ $reporttype = 'AWR' ];
then
then
export NLS_LANG=american_america.AL32UTF8
echo "generate the awr report sql...."
$ORACLE_HOME/bin/sqlplus -s "/ as sysdba" <awrreport.sql
set head off
set echo off
set feedback off
set linesize 120 ;
set pagesize 0;
set heading off;
select * from (
select snap_id as snaped,
lag(snap_id, 1) OVER(ORDER BY snap_id) as snapst,
to_char(end_interval_time, 'yyyymmddhh24miss') as snaped1,
lag(to_char(end_interval_time, 'yyyymmddhh24miss'), 1) OVER(ORDER BY to_char(end_interval_time, 'yyyymmddhh24miss')) as snaped2
from dba_hist_snapshot a
where a.begin_interval_time >=to_date('$startdate', 'yyyy-mm-dd hh24:mi:ss')
and a.begin_interval_time <=to_date('$enddate', 'yyyy-mm-dd hh24:mi:ss')
and rtrim(ltrim(to_char(a.begin_interval_time,'day','NLS_DATE_LANGUAGE=AMERICAN'))) not in ('saturday','sunday')
and to_char(a.begin_interval_time,'HH24') >=8
and to_char(a.end_interval_time,'HH24') <=18
and a.DBID='$dbid'
and a.INSTANCE_NUMBER='$instanceid'
) where snapst is not null AND substr(snaped1,1,8)=substr(snaped2,1,8) and substr(snaped1,9,2)||substr(snaped2,9,2) not in ('0900','0830','0908','0808','0800')
order by snapst;
quit
EOF
echo "generate the awr report sql...."
$ORACLE_HOME/bin/sqlplus -s "/ as sysdba" <
set head off
set echo off
set feedback off
set linesize 120 ;
set pagesize 0;
set heading off;
select * from (
select snap_id as snaped,
lag(snap_id, 1) OVER(ORDER BY snap_id) as snapst,
to_char(end_interval_time, 'yyyymmddhh24miss') as snaped1,
lag(to_char(end_interval_time, 'yyyymmddhh24miss'), 1) OVER(ORDER BY to_char(end_interval_time, 'yyyymmddhh24miss')) as snaped2
from dba_hist_snapshot a
where a.begin_interval_time >=to_date('$startdate', 'yyyy-mm-dd hh24:mi:ss')
and a.begin_interval_time <=to_date('$enddate', 'yyyy-mm-dd hh24:mi:ss')
and rtrim(ltrim(to_char(a.begin_interval_time,'day','NLS_DATE_LANGUAGE=AMERICAN'))) not in ('saturday','sunday')
and to_char(a.begin_interval_time,'HH24') >=8
and to_char(a.end_interval_time,'HH24') <=18
and a.DBID='$dbid'
and a.INSTANCE_NUMBER='$instanceid'
) where snapst is not null AND substr(snaped1,1,8)=substr(snaped2,1,8) and substr(snaped1,9,2)||substr(snaped2,9,2) not in ('0900','0830','0908','0808','0800')
order by snapst;
quit
EOF
export NLS_LANG=american_america.AL32UTF8
cat awrreport.sql | while read line
do
endd=`echo $line | awk ' { print $1 } '`
startd=`echo $line | awk ' { print $2 } '`
endt=`echo $line | awk ' { print $3 } '`
startt=`echo $line | awk ' { print $4 } '`
awrrp="awrrpt_"$startt"_"$endt".txt"
instid=`echo $instanceid`
cat awrreport.sql | while read line
do
endd=`echo $line | awk ' { print $1 } '`
startd=`echo $line | awk ' { print $2 } '`
endt=`echo $line | awk ' { print $3 } '`
startt=`echo $line | awk ' { print $4 } '`
awrrp="awrrpt_"$startt"_"$endt".txt"
instid=`echo $instanceid`
export NLS_LANG=american_america.AL32UTF8
$ORACLE_HOME/bin/sqlplus -s "/ as sysdba" <
$reportformat
$databaseid
$instid
1
$startd
$endd
$awrrp
quit
EOF
done
echo "generate the awr report finish,please check..."
exit
exit
else
echo "error!!!please check the input parameters..."
fi
+++++++++++++++++++++++++++++++++++++++++
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22578826/viewspace-746931/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- awr的top sql分析SQL
- 獲取top N cpu pid的sql資訊指令碼SQL指令碼
- AWR TOP SQL實現SQL
- Oracle AWR Top SQL sectionOracleSQL
- AWR中的SQL StatisticsSQL
- 分析索引快速獲取索引資訊索引
- 【AWR】通過AWR報告中記錄的 SQL Id獲得SQL語句的執行計劃SQL
- MFC中獲取程式自身的版本資訊
- 利用statspack來獲取生成環境中top SQL及其執行計劃SQL
- Jquery中獲取iframe的程式碼(window.top.parent)jQuery
- MySQL 如何獲取執行中的Queries資訊?MySql
- SQL生成AWR中的SQL ordered by Elapsed TimeSQL
- Spring 中優雅的獲取泛型資訊Spring泛型
- 如何優雅獲的獲取不同系統版本中的程式資訊
- 從資料字典中獲取ash資訊
- Android中獲取當前位置資訊Android
- 【SQL】SQL解惑-如何從字串中獲取IP地址SQL字串
- 【轉】通過sql語句獲取資料庫的基本資訊SQL資料庫
- Oracle AWR報告分析之–SQL ordered byOracleSQL
- SQL 獲取SQL Server中兩個日期之間的所有日期SQLServer
- 觸發器中獲取SQL語句觸發器SQL
- v$sql_bind_capture 獲取繫結變數資訊SQLAPT變數
- 獲取sql server 2008表欄位資訊SQLServer
- SAP中關於使用者IP資訊的獲取
- 獲取AWR的指令碼,可以在crontab裡面部署指令碼
- 獲取Oracle資料庫awr報告方法Oracle資料庫
- java獲取前端頁面傳送的cookie中的資訊Java前端Cookie
- 獲取.crt證書的資訊
- mac獲取cpu資訊Mac
- 獲取資訊版本1
- SSIS中Sql任務中獲取系統變數的方式SQL變數
- 使用SQL語句獲取SQLite中的表定義SQLite
- 使用ttXactAdmin、ttSQLCmdCacheInfo、ttSQLCmdQueryPlan獲取SQL相關詳細資訊TTSSQL
- SQL解惑-如何從字串中獲取IP地址SQL字串
- 獲取SqlServer 2005中欄位的備註資訊SQLServer
- AWR中的主要事件分析精講事件
- awr中DB CPU過低的原因分析
- Laravel 中 $request 獲取請求資訊 用法 總結Laravel