監控或統計多套資料庫的儲存容量與備份

skyin_1603發表於2017-07-29
    為了減少監控或同級多套資料庫儲存容量或者備份檢查的工作量,可以考慮使用一個專門做監控伺服器,
透過配置一些需要到的配置表,然後以sh指令碼或者儲存過程形式固化採集多套庫的儲存容量情況或者備份情況的
方式,形成簡易的採集流程,大大簡化了重複而繁瑣的資料庫管理工作

配置方法:
1、監控伺服器;
2、監控伺服器通往各個被監控伺服器dblink的配置表,(如下 suxing.conf11g_dblink_tab或者suxing.CONF_BACKUPCHECK_DBLINK_TAB
----由於兩個配置表的功能有所差異,所以分開兩個配置表;
3、專門作監控的使用者;
4、指令碼或者儲存過程(如下多個伺服器容量統計指令碼和多個伺服器備份檢查結果採集指令碼);
5、存放採集資料的表(如下 suxing.space_gather11G_tab或者 suxing.db_backup_check_alltab)。

#####多個伺服器容量統計指令碼:
declare
 v_sql varchar2(4000);
begin
  for rec in (select * from suxing.conf11g_dblink_tab) loop
  v_sql :='insert into suxing.space_gather11G_tab              
select * from (               
with
I as (select instance_name from v$instance@'||rec.db_link||'),
A as (select round(sum(bytes)/1024/1024/1024,2) aa from dba_data_files@'||rec.db_link||'),
B as (select round(sum(bytes)/1024/1024/1024,2) bb from dba_free_space@'||rec.db_link||'),
C as (select round(sum(BYTES / 1024 / 1024 / 1024), 2) cc
          from v$datafile@'||rec.db_link||' a, v$tablespace@'||rec.db_link||' b
         where a.TS# = b.TS#
           and a.CREATION_TIME <
               to_date(''2017-07-15 10:00:00'', ''YYYY-MM-DD HH24:MI:SS'')),
D as (select round(sum(BYTES / 1024 / 1024 / 1024), 2) dd
          from v$datafile@'||rec.db_link||' a, v$tablespace@'||rec.db_link||' b
         where a.TS# = b.TS#
           and a.CREATION_TIME <
               to_date(''2017-04-15 00:00:00'', ''YYYY-MM-DD HH24:MI:SS'')),
E as (select round(sum(BYTES / 1024 / 1024 / 1024), 2) ee
          from v\$datafile@'||rec.db_link||' a, v\$tablespace@'||rec.db_link||' b
         where a.TS# = b.TS#
           and a.CREATION_TIME <
               to_date(''2017-06-15 00:00:00'', ''YYYY-MM-DD HH24:MI:SS'')),
G as (select GROUP_NUMBER,NAME,TOTAL_MB/1024 totalGB,FREE_MB/1024 freeGB
      from v$asm_diskgroup@'||rec.db_link||' where name like ''DATA%'')               
select I.instance_name,A.aa Total_G,A.aa-B.bb Used_G,B.bb Free_G,G.totalGB,G.freeGB,(C.cc - D.dd)/3 AVRG3,C.cc - E.ee,sysdate,to_char(sysdate,''yymmdd'')
from I,A,B,C,D,E,G
)';
   --dbms_output.put_line(v_sql);
   execute immediate v_sql;
   commit;
   end loop;
end; 

#####多個伺服器備份檢查結果採集指令碼:
declare
 v_sql varchar2(4000);
begin
  for rec in (select * from suxing.CONF_BACKUPCHECK_DBLINK_TAB) loop
  v_sql :='insert into suxing.db_backup_check_alltab              
select * from (
with
I  as (select instance_name from v$instance@'||rec.db_link||'),
BC as (
select start_time, t.INPUT_TYPE, status
  from v$rman_backup_job_details@'||rec.db_link||' t
 where t.start_time in (select max(start_time)
  from v$rman_backup_job_details@'||rec.db_link||')
   and t.INPUT_TYPE = ''ARCHIVELOG''
 group by t.start_time, t.INPUT_TYPE, t.STATUS
union all
select start_time, t.INPUT_TYPE, status
  from v$rman_backup_job_details@'||rec.db_link||' t
     where t.start_time in (select max(start_time)
   from v$rman_backup_job_details@'||rec.db_link||' t
      where t.INPUT_TYPE = ''DB INCR'')
 group by t.start_time, t.INPUT_TYPE, t.STATUS)
select I.instance_name,BC.*,to_char(sysdate,''mmddhh24'') from I,BC)';
   --dbms_output.put_line(v_sql);
   execute immediate v_sql;
   commit;
   end loop;
end; 

注:這些指令碼當中,with子句的作用非常關鍵。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31392094/viewspace-2142760/,如需轉載,請註明出處,否則將追究法律責任。

相關文章