监控或统计多套数据库的存储容量与备份
短信预约 -IT技能 免费直播动态提醒
为了减少监控或同级多套数据库存储容量或者备份检查的工作量,可以考虑使用一个专门做监控服务器,
通过配置一些需要到的配置表,然后以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,''mmddhh34'') from I,BC)';
--dbms_output.put_line(v_sql);
execute immediate v_sql;
commit;
end loop;
end;
注:这些脚本当中,with子句的作用非常关键。
通过配置一些需要到的配置表,然后以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,''mmddhh34'') from I,BC)';
--dbms_output.put_line(v_sql);
execute immediate v_sql;
commit;
end loop;
end;
注:这些脚本当中,with子句的作用非常关键。
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341