oracle_DBA 管理之歸檔日誌管理sql

查當天每小時的歸檔日誌生成量

select logtime,
       count(*),
       round(sum(blocks * block_size) / 1024 / 1024) mbsize
  from (select trunc(first_time, 'hh') as logtime, a.BLOCKS, a.BLOCK_SIZE
          from v$archived_log a
         where a.DEST_ID = 1
           and a.FIRST_TIME > trunc(sysdate))
 group by logtime
 order by logtime desc;

查最近一週每天的歸檔日誌生成量

select logtime,
       count(*),
       round(sum(blocks * block_size) / 1024 /1024) MBsize
  from (select trunc(first_time, 'dd') as logtime, a.BLOCKS, a.BLOCK_SIZE
          from v$archived_log a
         where a.DEST_ID = 1
           and a.FIRST_TIME > trunc(sysdate - 15))
 group by logtime
 order by logtime desc;
如果你需要知道RAC下各個節點的歸檔日誌情況,我將上面腳本略作修改,增加thread#列。

 select to_char(COMPLETION_TIME,'yyyy-mm-dd') tt,
       round(sum(blocks * block_size) / 1024 /1024/1024) GBsize
  from  v$archived_log a
         where  a.COMPLETION_TIME > date '2017-11-15'
 group by to_char(COMPLETION_TIME,'yyyy-mm-dd')
 order by to_char(COMPLETION_TIME,'yyyy-mm-dd') ;


查當天每小時的各個實例的歸檔日誌生成量
select THREAD#,
       logtime,
       count(*),
       round(sum(blocks * block_size) / 1024 / 1024/1024,2) gb_size
  from (select a.THREAD#,
               trunc(first_time, 'hh') as logtime,
               a.BLOCKS,
               a.BLOCK_SIZE
          from v$archived_log a
         where a.DEST_ID = 1
           and a.FIRST_TIME > trunc(sysdate))
 group by THREAD#, logtime
 order by THREAD#, logtime desc;

查最近一週每天的各個實例的歸檔日誌生成量 
select THREAD#,
       logtime,
       count(*),
       round(sum(blocks * block_size) / 1024 / 1024) mbsize
  from (select THREAD#,
               trunc(first_time, 'dd') as logtime,
               a.BLOCKS,
               a.BLOCK_SIZE
          from v$archived_log a
         where a.DEST_ID = 1
           and a.FIRST_TIME > trunc(sysdate - 7))
 group by THREAD#, logtime
 order by THREAD#, logtime desc;


歸檔頻率

 set line 200
select b.SEQUENCE#, b.FIRST_TIME,a.SEQUENCE#,a.FIRST_TIME,round(((a.FIRST_TIME-b.FIRST_TIME)*24)*60,2) from v$log_history a, v$log_history b where a.SEQUENCE#=b.SEQUENCE#+1 and b.THREAD#=1 order by a.SEQUENCE# desc;

-----查看REDO產生量情況
select a.sid,value/1024/1024/1024,c.sql_id,c.status,C.EVENT,c.username,d.SQL_FULLTEXT from v$sesstat a, v$statname b ,v$session c ,v$sql d
where a.statistic#=b.statistic#
and a.sid=c.sid
and c.sql_id=d.sql_id(+)
and b.name = 'redo size'
and c.wait_class<>'idle'
order by 2 desc;



FRA 歸檔 

Flash back 日誌量很大分析
select INST_ID,OLDEST_FLASHBACK_SCN,OLDEST_FLASHBACK_TIME,RETENTION_TARGET,FLASHBACK_SIZE/1024/1024/1024 GB  ,ESTIMATED_FLASHBACK_SIZE/1024/1024/1024 ESTF_GB from gv$flashback_database_log ;
 

select a.BEGIN_TIME,a.END_TIME,round(a.FLASHBACK_DATA/1024/1024/1024,2) FLASHBACK_DATA_GB,round(a.DB_DATA/1024/1024/1024,2 )DB_DATA_GB,
a.REDO_DATA,round(a.ESTIMATED_FLASHBACK_SIZE/1024/1024/1024 ,2)est_size_GB from V$FLASHBACK_DATABASE_STAT a;  2  



    select to_char(first_time,'yyyy-mm-dd') archive_date,
           cast((sum(blocks*block_size)/1024/1024/1024) as number(10,2)) day_size_gb,
           cast((sum(case when to_char(first_time,'hh24')=00 then blocks*block_size else 0 end)/1024/1024/1024) as number(10,2)) h_00_size,
           cast((sum(case when to_char(first_time,'hh24')=01 then blocks*block_size else 0 end)/1024/1024/1024) as number(10,2)) h_01_size,
           cast((sum(case when to_char(first_time,'hh24')=02 then blocks*block_size else 0 end)/1024/1024/1024) as number(10,2)) h_02_size,
           cast((sum(case when to_char(first_time,'hh24')=03 then blocks*block_size else 0 end)/1024/1024/1024) as number(10,2)) h_03_size,
           cast((sum(case when to_char(first_time,'hh24')=04 then blocks*block_size else 0 end)/1024/1024/1024) as number(10,2)) h_04_size,
           cast((sum(case when to_char(first_time,'hh24')=05 then blocks*block_size else 0 end)/1024/1024/1024) as number(10,2)) h_05_size,
           cast((sum(case when to_char(first_time,'hh24')=06 then blocks*block_size else 0 end)/1024/1024/1024) as number(10,2)) h_06_size,
           cast((sum(case when to_char(first_time,'hh24')=07 then blocks*block_size else 0 end)/1024/1024/1024) as number(10,2)) h_07_size,
           cast((sum(case when to_char(first_time,'hh24')=08 then blocks*block_size else 0 end)/1024/1024/1024) as number(10,2)) h_08_size,
           cast((sum(case when to_char(first_time,'hh24')=09 then blocks*block_size else 0 end)/1024/1024/1024) as number(10,2)) h_09_size,
           cast((sum(case when to_char(first_time,'hh24')=10 then blocks*block_size else 0 end)/1024/1024/1024) as number(10,2)) h_10_size,
           cast((sum(case when to_char(first_time,'hh24')=11 then blocks*block_size else 0 end)/1024/1024/1024) as number(10,2)) h_11_size,
           cast((sum(case when to_char(first_time,'hh24')=12 then blocks*block_size else 0 end)/1024/1024/1024) as number(10,2)) h_12_size,
           cast((sum(case when to_char(first_time,'hh24')=13 then blocks*block_size else 0 end)/1024/1024/1024) as number(10,2)) h_13_size,
           cast((sum(case when to_char(first_time,'hh24')=14 then blocks*block_size else 0 end)/1024/1024/1024) as number(10,2)) h_14_size,
           cast((sum(case when to_char(first_time,'hh24')=15 then blocks*block_size else 0 end)/1024/1024/1024) as number(10,2)) h_15_size,
           cast((sum(case when to_char(first_time,'hh24')=16 then blocks*block_size else 0 end)/1024/1024/1024) as number(10,2)) h_16_size,
           cast((sum(case when to_char(first_time,'hh24')=17 then blocks*block_size else 0 end)/1024/1024/1024) as number(10,2)) h_17_size,
           cast((sum(case when to_char(first_time,'hh24')=18 then blocks*block_size else 0 end)/1024/1024/1024) as number(10,2)) h_18_size,
           cast((sum(case when to_char(first_time,'hh24')=19 then blocks*block_size else 0 end)/1024/1024/1024) as number(10,2)) h_19_size,
           cast((sum(case when to_char(first_time,'hh24')=20 then blocks*block_size else 0 end)/1024/1024/1024) as number(10,2)) h_20_size,
           cast((sum(case when to_char(first_time,'hh24')=21 then blocks*block_size else 0 end)/1024/1024/1024) as number(10,2)) h_21_size,
           cast((sum(case when to_char(first_time,'hh24')=22 then blocks*block_size else 0 end)/1024/1024/1024) as number(10,2)) h_22_size,
           cast((sum(case when to_char(first_time,'hh24')=23 then blocks*block_size else 0 end)/1024/1024/1024) as number(10,2)) h_23_size,
           sum(case when to_char(first_time,'hh24')=00 then 1 else 0 end) h00_logs,
           sum(case when to_char(first_time,'hh24')=01 then 1 else 0 end) h01_logs,
           sum(case when to_char(first_time,'hh24')=02 then 1 else 0 end) h02_logs,
           sum(case when to_char(first_time,'hh24')=03 then 1 else 0 end) h03_logs,
           sum(case when to_char(first_time,'hh24')=04 then 1 else 0 end) h04_logs,
           sum(case when to_char(first_time,'hh24')=05 then 1 else 0 end) h05_logs,
           sum(case when to_char(first_time,'hh24')=06 then 1 else 0 end) h06_logs,
           sum(case when to_char(first_time,'hh24')=07 then 1 else 0 end) h07_logs,
           sum(case when to_char(first_time,'hh24')=08 then 1 else 0 end) h08_logs,
           sum(case when to_char(first_time,'hh24')=09 then 1 else 0 end) h09_logs,
           sum(case when to_char(first_time,'hh24')=10 then 1 else 0 end) h10_logs,
           sum(case when to_char(first_time,'hh24')=11 then 1 else 0 end) h11_logs,
           sum(case when to_char(first_time,'hh24')=12 then 1 else 0 end) h12_logs,
           sum(case when to_char(first_time,'hh24')=13 then 1 else 0 end) h13_logs,
           sum(case when to_char(first_time,'hh24')=14 then 1 else 0 end) h14_logs,
           sum(case when to_char(first_time,'hh24')=15 then 1 else 0 end) h15_logs,
           sum(case when to_char(first_time,'hh24')=16 then 1 else 0 end) h16_logs,
           sum(case when to_char(first_time,'hh24')=17 then 1 else 0 end) h17_logs,
           sum(case when to_char(first_time,'hh24')=18 then 1 else 0 end) h18_logs,
           sum(case when to_char(first_time,'hh24')=19 then 1 else 0 end) h19_logs,
           sum(case when to_char(first_time,'hh24')=20 then 1 else 0 end) h20_logs,
           sum(case when to_char(first_time,'hh24')=21 then 1 else 0 end) h21_logs,
           sum(case when to_char(first_time,'hh24')=22 then 1 else 0 end) h22_logs,
           sum(case when to_char(first_time,'hh24')=23 then 1 else 0 end) h23_logs 
      from v$archived_log 
     where standby_dest='NO' 
       and first_time > trunc(sysdate)-60 
     group by to_char(first_time,'yyyy-mm-dd') 
     order by archive_date desc;

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章