创建一个JOB定期执行以下过程就可以自动添加数据文件
当表空间使用90%触发过程添加数据文件,数据文件时按日期生成
create or replace procedure auto_add_datafile is
ALL_file_name Varchar(500);
file_name Varchar(500);
tablespace_all varchar(500);
Vs_Sql Varchar2(500);
cursor c_tablespace is
select a.表空间名称,a.使用率,substr(b.FILE_NAME,0,INSTR (b.FILE_NAME, '/',1,5)) as FILE_NAME from (select t.tablespace_name "表空间名称",round((t.full_space-nvl
(f.free_space,0))/t.full_space*100,0) "使用率"from (select tablespace_name,round
(sum(bytes)/(1024*1024),2) free_space from dba_free_space group by tablespace_name) f ,
(select tablespace_name,round(sum(bytes)/(1024*1024),2) full_space from dba_data_files group by
tablespace_name) t where f.tablespace_name=t.tablespace_name(+)) a,dba_data_files b where a.表空间名称=b.TABLESPACE_NAME group by a.表空间名称,a.使用率,substr(b.FILE_NAME,0,INSTR (b.FILE_NAME, '/',1,5));
Begin
PRO_DATA_UPDATE_LOG('auto_add_datafile', '开始', null,null);
for tablespace_all in c_tablespace loop
If tablespace_all.使用率 >=80 Then
if tablespace_all.表空间名称='USERS' OR tablespace_all.表空间名称='SYSAUX' OR tablespace_all.表空间名称='SYSTEM' OR tablespace_all.表空间名称='UNDOTBS1' then
ALL_file_name := tablespace_all.file_name;
--ALL_file_name := substr(ALL_file_name,0,INSTR (ALL_file_name, '.')-1);
ALL_file_name := ALL_file_name||tablespace_all.表空间名称||'_'||to_char(sysdate,'yyyymmdd')||'.dbf';
Vs_Sql := 'alter tablespace '||tablespace_all.表空间名称||' add datafile '''||ALL_file_name||''' size 2G';
--dbms_output.put_line(Vs_Sql);
Execute Immediate Vs_Sql;
else
ALL_file_name := tablespace_all.file_name;
--ALL_file_name := substr(ALL_file_name,0,INSTR (ALL_file_name, '.')-1);
ALL_file_name := ALL_file_name||tablespace_all.表空间名称||'_'||to_char(sysdate,'yyyymmdd')||'.dbf';
Vs_Sql := 'alter tablespace '||tablespace_all.表空间名称||' add datafile '''||ALL_file_name||''' size 30G';
--dbms_output.put_line(Vs_Sql);
Execute Immediate Vs_Sql;
end if;
End If;
end loop;
PRO_DATA_UPDATE_LOG('auto_add_datafile', '结束', '正常',1);
exception
when others then
PRO_DATA_UPDATE_LOG('auto_add_datafile',SQLERRM, '异常',0);
End auto_add_datafile;
当表空间使用90%触发过程添加数据文件,数据文件时按日期生成
create or replace procedure auto_add_datafile is
ALL_file_name Varchar(500);
file_name Varchar(500);
tablespace_all varchar(500);
Vs_Sql Varchar2(500);
cursor c_tablespace is
select a.表空间名称,a.使用率,substr(b.FILE_NAME,0,INSTR (b.FILE_NAME, '/',1,5)) as FILE_NAME from (select t.tablespace_name "表空间名称",round((t.full_space-nvl
(f.free_space,0))/t.full_space*100,0) "使用率"from (select tablespace_name,round
(sum(bytes)/(1024*1024),2) free_space from dba_free_space group by tablespace_name) f ,
(select tablespace_name,round(sum(bytes)/(1024*1024),2) full_space from dba_data_files group by
tablespace_name) t where f.tablespace_name=t.tablespace_name(+)) a,dba_data_files b where a.表空间名称=b.TABLESPACE_NAME group by a.表空间名称,a.使用率,substr(b.FILE_NAME,0,INSTR (b.FILE_NAME, '/',1,5));
Begin
PRO_DATA_UPDATE_LOG('auto_add_datafile', '开始', null,null);
for tablespace_all in c_tablespace loop
If tablespace_all.使用率 >=80 Then
if tablespace_all.表空间名称='USERS' OR tablespace_all.表空间名称='SYSAUX' OR tablespace_all.表空间名称='SYSTEM' OR tablespace_all.表空间名称='UNDOTBS1' then
ALL_file_name := tablespace_all.file_name;
--ALL_file_name := substr(ALL_file_name,0,INSTR (ALL_file_name, '.')-1);
ALL_file_name := ALL_file_name||tablespace_all.表空间名称||'_'||to_char(sysdate,'yyyymmdd')||'.dbf';
Vs_Sql := 'alter tablespace '||tablespace_all.表空间名称||' add datafile '''||ALL_file_name||''' size 2G';
--dbms_output.put_line(Vs_Sql);
Execute Immediate Vs_Sql;
else
ALL_file_name := tablespace_all.file_name;
--ALL_file_name := substr(ALL_file_name,0,INSTR (ALL_file_name, '.')-1);
ALL_file_name := ALL_file_name||tablespace_all.表空间名称||'_'||to_char(sysdate,'yyyymmdd')||'.dbf';
Vs_Sql := 'alter tablespace '||tablespace_all.表空间名称||' add datafile '''||ALL_file_name||''' size 30G';
--dbms_output.put_line(Vs_Sql);
Execute Immediate Vs_Sql;
end if;
End If;
end loop;
PRO_DATA_UPDATE_LOG('auto_add_datafile', '结束', '正常',1);
exception
when others then
PRO_DATA_UPDATE_LOG('auto_add_datafile',SQLERRM, '异常',0);
End auto_add_datafile;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29065182/viewspace-1750374/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29065182/viewspace-1750374/