平时在查看数据库的问题时,会有种迷茫的感觉,如果没有任何人反馈问题,基本上没有主动查找问题的方向,awr,ash都是在得知问题发生的时间段或者一些时间戳来从历史记录中查找相关的信息,个人整理了如下的脚本,能够显示当天的时间段内数据库的负载信息,能够很好掌握数据库的忙闲情况。
来看一个简单的例子,比如我要查看早上6点到中午12点数据库的负载情况
脚本 showdbtime.sh 显示的是在制定的时间段内的 数据库负载的一个综合值。比如6点到7点个小时(60分钟),dbtime如果是120分钟,那么显示的负载就是200%
BEGIN_TIME END_TIME ELAPSED_TIME DBTIME WORKLOAD_PER
----------------------------------- ----------------------------------- ------------- ---------- --------------------
201 ** 21-MAY-14 06.07.33.893 PM 201 ** 21-MAY-14 07.07.33.893 PM 60 120 200%
脚本内容如下:
sqlplus -s $DB_CONN_STR@$SH_DB_SID <<EOF
set linesize 200
col begin_time format a35
col end_time format a35
col elapsed_time format 99999999.999
col workload_per format a20
SELECT
begin_time,end_time,
elapsed_time,
dbtime,
trunc(dbtime/decode(elapsed_time,0,1,elapsed_time),2)*100||'%' workload_per
from
(
select
B.SNAP_ID||' ** '||B.END_INTERVAL_TIME begin_time,
E.SNAP_ID||' ** '||E.END_INTERVAL_TIME end_time,
EXTRACT(DAY FROM E.END_INTERVAL_TIME - B.END_INTERVAL_TIME) * 1440 +
EXTRACT(HOUR FROM E.END_INTERVAL_TIME - B.END_INTERVAL_TIME)* 60 +
EXTRACT(MINUTE FROM E.END_INTERVAL_TIME -B.END_INTERVAL_TIME) +
EXTRACT(SECOND FROM E.END_INTERVAL_TIME -B.END_INTERVAL_TIME) / 60 elapsed_time,
db_time.dbtime
FROM DBA_HIST_SNAPSHOT B, DBA_HIST_SNAPSHOT E,
(
SELECT b.snap_id begin_snap, e.snap_id end_snap ,
round((sum(e.value) -
sum(b.value)) / 1000000 /60,2) dbtime
FROM DBA_HIST_SYS_TIME_MODEL e, DBA_HIST_SYS_TIME_MODEL b,
(
select min(snap_id) begin_snap,max(snap_id) end_snap from DBA_HIST_SNAPSHOT where begin_interval_time > sysdate -1
and EXTRACT(HOUR FROM END_INTERVAL_TIME) between $1 and $2
) temp_snap
WHERE
e.STAT_NAME = 'DB time'
and b.snap_id=temp_snap.begin_snap
and e.snap_id =temp_snap.end_snap
AND b.STAT_NAME = 'DB time'
group by e.snap_id,b.snap_id
) db_time
WHERE b.begin_interval_time > sysdate -1
and EXTRACT(HOUR FROM e.END_INTERVAL_TIME) between $1 and $2
and b.snap_id=db_time.begin_snap
and e.snap_id=db_time.end_snap
)
/