oracle

[ORACLE] 오라클 성능분석 스크립트

둥구리둥둥 2023. 2. 3. 11:22
728x90


:DBID
:INSTANCE_NUMBER
:BEGIN_SNAP_ID
:END_SNAP_ID
값 설정후 스크립트 실행

 snap_id 찾기


select snap_id, to_char(min(begin_time),'dd hh24:mi') DTIME, to_char(min(end_time),'dd hh24:mi') ETIME
FROM DBA_HIST_SYSMETRIC_SUMMARY
WHERE begin_time > sysdate-2
and instance_number=1
group by snap_id
order by snap_id
/

 Operating System Statistics 1 


SQL> select to_char(min(begin_time),'dd hh24:mi') DTIME, 
       sum(case when metric_name = 'Host CPU Utilization (%)' and instance_number = 1 then average else 0 end) "Host CPU Utilization (%)"
  from DBA_HIST_SYSMETRIC_SUMMARY
 where INSTANCE_NUMBER =1 and metric_name='Host CPU Utilization (%)'
       and begin_time > sysdate-6
group by snap_id
order by snap_id
/




Operating System Statistics 2 


select
       case when BUSY_TIME+IDLE_TIME = 0 then null else round(100*USER_TIME  /(BUSY_TIME+IDLE_TIME),2) end "%user",
       case when BUSY_TIME+IDLE_TIME = 0 then null else round(100*SYS_TIME   /(BUSY_TIME+IDLE_TIME),2) end "%sys",
       case when BUSY_TIME+IDLE_TIME = 0 then null else round(100*IOWAIT_TIME/(BUSY_TIME+IDLE_TIME),2) end "%iowait",
       case when BUSY_TIME+IDLE_TIME = 0 then null else round(100*IDLE_TIME  /(BUSY_TIME+IDLE_TIME),2) end "%idle"
  from (select SNAP_ID, LOAD,
               case when lag(BUSY_TIME,1) over (order by SNAP_ID) is null then null
                    else BUSY_TIME - lag(BUSY_TIME,1, 0) over (order by SNAP_ID) end BUSY_TIME,
               case when lag(IDLE_TIME,1) over (order by SNAP_ID) is null then null
                    else IDLE_TIME - lag(IDLE_TIME,1, 0) over (order by SNAP_ID) end IDLE_TIME,
               case when lag(IOWAIT_TIME,1) over (order by SNAP_ID) is null then null
                    else IOWAIT_TIME - lag(IOWAIT_TIME,1, 0) over (order by SNAP_ID) end IOWAIT_TIME,
               case when lag(SYS_TIME,1) over (order by SNAP_ID) is null then null
                    else SYS_TIME - lag(SYS_TIME,1, 0) over (order by SNAP_ID) end SYS_TIME,
               case when lag(USER_TIME,1) over (order by SNAP_ID) is null then null
                    else USER_TIME - lag(USER_TIME,1, 0) over (order by SNAP_ID) end USER_TIME
          from (select SNAP_ID,
                       sum(case when STAT_NAME = 'LOAD'                   then VALUE else 0 end) LOAD,
                       sum(case when STAT_NAME = 'BUSY_TIME'              then VALUE else 0 end) BUSY_TIME,
                       sum(case when STAT_NAME = 'IDLE_TIME'              then VALUE else 0 end) IDLE_TIME,
                       sum(case when STAT_NAME = 'IOWAIT_TIME'            then VALUE else 0 end) IOWAIT_TIME,
                       sum(case when STAT_NAME = 'NICE_TIME'              then VALUE else 0 end) NICE_TIME,
                       sum(case when STAT_NAME = 'RSRC_MGR_CPU_WAIT_TIME' then VALUE else 0 end) RSRC_TIME,
                       sum(case when STAT_NAME = 'SYS_TIME'               then VALUE else 0 end) SYS_TIME,
                       sum(case when STAT_NAME = 'USER_TIME'              then VALUE else 0 end) USER_TIME
                  from DBA_HIST_OSSTAT
                 where INSTANCE_NUMBER = :INSTANCE_NUMBER and DBID = :DBID and SNAP_ID between :BEGIN_SNAP_ID and :END_SNAP_ID
                 group by SNAP_ID)) OS,
       DBA_HIST_SNAPSHOT S
 where os.SNAP_ID = s.SNAP_ID
   and s.INSTANCE_NUMBER = :INSTANCE_NUMBER and s.DBID = :DBID and s.SNAP_ID between :BEGIN_SNAP_ID and :END_SNAP_ID
   and BUSY_TIME is not null
 order by s.SNAP_ID
/

728x90