oracle監控表空間,JOB,rman備份

aishu521發表於2013-03-18
1,表空間監控
begin
  sys.dbms_job.submit(job => :job,
                      what => 'begin
for v in
 (select aa.tablespace_name a1,aa.megs_alloc a2, aa.megs_free a3,aa.megs_used a4,aa.pct_free a5,aa.pct_used a6,aa.max a7 from
  (select a.tablespace_name,
       round(a.bytes_alloc / 1024 / 1024, 2) megs_alloc,
       round(nvl(b.bytes_free, 0) / 1024 / 1024, 2) megs_free,
       round((a.bytes_alloc - nvl(b.bytes_free, 0)) / 1024 / 1024, 2) megs_used,
       round((nvl(b.bytes_free, 0) / a.bytes_alloc) * 100,2) Pct_Free,
       100 - round((nvl(b.bytes_free, 0) / a.bytes_alloc) * 100,2) Pct_used,
       round(maxbytes/1048576,2) Max
from  ( select  f.tablespace_name,
               sum(f.bytes) bytes_alloc,
               sum(decode(f.autoextensible, ''YES'',f.maxbytes,''NO'', f.bytes)) maxbytes
        from dba_data_files f
        group by tablespace_name) a,
      ( select  f.tablespace_name,
               sum(f.bytes)  bytes_free
        from dba_free_space f
        group by tablespace_name) b
where a.tablespace_name = b.tablespace_name (+)and a.tablespace_name not in (''SYSTEM'',''SYSAUX'',''EXAMPLE'',
''USERS'',''UNDOTBS1'',''TEMP'' )
union all
select h.tablespace_name,
       round(sum(h.bytes_free + h.bytes_used) / 1048576, 2) megs_alloc,
       round(sum((h.bytes_free + h.bytes_used) - nvl(p.bytes_used, 0)) / 1048576, 2) megs_free,
       round(sum(nvl(p.bytes_used, 0))/ 1048576, 2) megs_used,
       round((sum((h.bytes_free + h.bytes_used) - nvl(p.bytes_used, 0)) / sum(h.bytes_used + h.bytes_free)) * 100,2) Pct_Free,
       100 - round((sum((h.bytes_free + h.bytes_used) - nvl(p.bytes_used, 0)) / sum(h.bytes_used + h.bytes_free)) * 100,2) pct_used,
       round(f.maxbytes / 1048576, 2) max
from   sys.v_$TEMP_SPACE_HEADER h, sys.v_$Temp_extent_pool p, dba_temp_files f
where  p.file_id(+) = h.file_id
and    p.tablespace_name(+) = h.tablespace_name
and    f.file_id = h.file_id
and    f.tablespace_name = h.tablespace_name
and h.tablespace_name not in (''SYSTEM'',''SYSAUX'',''EXAMPLE'',
''USERS'',''UNDOTBS1'',''TEMP'' )
group by h.tablespace_name, f.maxbytes
ORDER BY 1) aa) loop
insert into checktablespace_66@check_link(tablespace_name,megs_alloc,megs_free,megs_used,pct_free,pct_used,max)
values(v.a1,v.a2,v.a3,v.a4,v.a5,v.a6,v.a7);
end loop;
end;',
                      next_date => to_date('19-03-2013 08:00:00', 'dd-mm-yyyy hh24:mi:ss'),
                      interval => 'trunc(sysdate) + 1 + 8/24');
  commit;
end;
/
2,JOB 監控
begin
  sys.dbms_job.submit(job => :job,
                      what => 'insert into oscheck.check_job_1@check_link
select ''10.182.15.66'' as host, job,log_user,last_date,next_date,total_time,broken,interval,failures, what,sysdate as record_date
from dba_jobs where schema_user not in
(''SYSTEM'',
''SYS'',
''OUTLN'',
''DIP'',
''TSMSYS'',
''DBSNMP'',
''WMSYS '',
''EXFSYS'',
''DMSYS '',
''CTXSYS'',
''XDB'',
''ANONYMOUS'',
''ORDPLUGINS'',
''SI_INFORMTN_SCHEMA'',
''ORDSYS'',
''MDSYS'',
''OLAPSYS'',
''MDDATA'',
''SYSMAN'',
''MGMT_VIEW'',
''SCOTT'');',
                      next_date => to_date('18-03-2013 17:00:00', 'dd-mm-yyyy hh24:mi:ss'),
                      interval => 'trunc(sysdate,''HH'')+1/24');
  commit;
end;
3,備份監控
begin
  sys.dbms_job.submit(job => :job,
                      what => 'begin
for v in (select a.SESSION_RECID a1,a.row_type,a.operation a2,a.status a3,a.start_time a4,a.end_time a5,
round(a.OUTPUT_BYTES / 1024 / 1024, 2) output_bytes  from v$rman_status a
where trunc(start_time, ''DD'') = trunc(sysdate - 1, ''DD'')
 and peration=''BACKUP''order by start_time ) loop
 insert into checkbackup_66_1@check_link(operation,status,start_time,end_time,datasize)
 values(v.a2,v.a3,v.a4,v.a5,v.output_bytes);
end loop;
end;',
                      next_date => to_date('19-03-2013 06:00:00', 'dd-mm-yyyy hh24:mi:ss'),
                      interval => 'trunc(sysdate) +1 +6/(24)');
  commit;
end;
/

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

相關文章