Oracle自動新增資料檔案過程
建立一個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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle 新增儲存自動擴充套件資料檔案流程(auto)Oracle套件
- Oracle DG備庫手動管理新增資料檔案Oracle
- 非OMF管理 自動新增資料檔案add_datafiles.sh
- OMF管理自動新增資料檔案指令碼add_datafile.sh指令碼
- oracle11g啟動過程中載入配置檔案Oracle
- 達夢資料庫資料檔案遷移過程資料庫
- DG備庫手動管理 新增資料檔案
- Oracle 資料檔案回收Oracle
- oracle 修改資料檔案位置(路徑)(移動)Oracle
- maven外掛執行過程中自動執行sql檔案MavenSQL
- Oracle資料庫啟動過程及狀態詳解Oracle資料庫
- SQL Server資料庫還原過程記錄,bak檔案+mdf檔案SQLServer資料庫
- ORACLE for windows 審計檔案xml檔案過多導致資料庫啟動報錯ORA-09925OracleWindowsXML資料庫
- Sql Server 資料庫中呼叫dll檔案的過程SQLServer資料庫
- 微信公眾號自動回覆新增檔案
- oracle 控制檔案及引數檔案何時自動備份Oracle
- MySQL8.0.18資料庫新增資料檔案MySql資料庫
- Oracle資料檔案和臨時檔案的管理Oracle
- Oracle 業務資料unload恢復過程Oracle
- oracle資料庫的配置檔案Oracle資料庫
- oracle 線上rename資料檔案Oracle
- Mysql使用儲存過程快速新增百萬資料MySql儲存過程
- 修改Oracle資料檔名及資料檔案存放路徑Oracle
- 達夢資料庫系統表空間資料檔案遷移過程資料庫
- 【資料庫資料恢復】透過恢復NDF檔案修復資料庫的資料恢復過程資料庫資料恢復
- oracle 12c 新增的LREG程式及其動態註冊的過程Oracle
- 4 配置Oracle資料庫自動啟動Oracle資料庫
- Oracle資料庫SQL語句執行過程Oracle資料庫SQL
- 【資料庫資料恢復】Sql Server資料庫檔案丟失的資料恢復過程資料庫資料恢復SQLServer
- oracle徹底刪除資料檔案Oracle
- oracle uncatalog資料庫備份檔案Oracle資料庫
- Oracle RAC+ADG新增資料檔案失敗處理(db_create_file_dest)Oracle
- oracle批量新增更新資料Oracle
- 每天自動備份Oracle資料庫Oracle資料庫
- 伺服器斷電Oracle資料庫修復資料過程伺服器Oracle資料庫
- Oracle 叢集的自啟動,OLR與套接字檔案Oracle
- Ueditor上傳圖片自動新增水印(通用圖片檔案)
- oracle dg庫資料檔案空間不足Oracle
- Oracle10g刪除資料檔案Oracle