Oracle數(shù)據(jù)庫如何更改數(shù)據(jù)文件位置
一、概述
突然收到zabbix報(bào)警提示OA數(shù)據(jù)庫服務(wù)器磁盤不足,經(jīng)常查發(fā)現(xiàn)根目錄磁盤空間不足,由于無法添加磁盤來擴(kuò)容,需要將數(shù)據(jù)庫目錄從/oradata更改到/home/oracle/oradata。
由于數(shù)據(jù)庫文件和表空間具有不同的性質(zhì),將數(shù)據(jù)文件位置更改分為四個(gè)步驟:
- 控制文件位置更改
- 數(shù)據(jù)文件位置更改*(不包括臨時(shí)數(shù)據(jù)文件)*
- 臨時(shí)數(shù)據(jù)文件位置更改
- 日志文件位置更改
二、控制文件位置更改
停止數(shù)據(jù)庫監(jiān)聽,防止有應(yīng)用連接對(duì)數(shù)據(jù)庫進(jìn)行修改。
lsnrctl stop
數(shù)據(jù)庫open的狀態(tài)下
alter system set control_files='/home/oracle/oradata/oa/control01.ctl','/home/oracle/oradata/oa/control02.ctl','/home/oracle/oradata/oa/control03.ctl' scope=spfile;
然后將數(shù)據(jù)庫shutdown
shutdown immediate;
將控制文件移動(dòng)到新目錄/home/oracle/oradata/oa下
mv /oradata/oa/control* /home/oracle/oradata/oa/
將數(shù)據(jù)庫啟動(dòng)到mount狀態(tài),至此,控制文件位置更改結(jié)束。
三、數(shù)據(jù)文件位置更改(不包括臨時(shí)數(shù)據(jù)文件)
數(shù)據(jù)庫需要在open狀態(tài)下
將表空間全部offline,使用一下命令:
SELECT 'alter tablespace ' || DTS.Tablespace_Name || ' offline;' FROM Sys.Dba_Tablespaces DTS WHERE DTS.Contents <> 'TEMPORARY' AND DTS.Tablespace_Name <> 'UNDOTBS1' AND DTS.Tablespace_Name <> 'SYSTEM';
生成的SQL語句如下,使用sysdba賬戶執(zhí)行
alter tablespace SYSAUX offline; alter tablespace USERS offline; ...
將這些表空間的數(shù)據(jù)文件復(fù)制到新目錄/home/oracle/oradata目錄下,數(shù)據(jù)文件rename的時(shí)候,需要兩邊都有數(shù)據(jù)文件。
使用以下語句生成rename數(shù)據(jù)文件的SQL語句
SELECT 'alter tablespace ' || Ddf.Tablespace_Name || ' rename datafile ''' ||
Ddf.File_Name || ''' to ''' || '/home/oracle' || Ddf.File_Name ||
''';'
FROM Sys.Dba_Data_Files Ddf
WHERE Ddf.Tablespace_Name <> 'SYSTEM'
AND Ddf.Tablespace_Name <> 'UNDOTBS1';生成的SQL語句如下,使用sysdba賬戶執(zhí)行
alter tablespace USERS rename datafile '/oradata/ipcc/users01.dbf' to '/home/oracle/oradata/ipcc/users01.dbf'; alter tablespace SYSAUX rename datafile '/oradata/ipcc/sysaux01.dbf' to '/home/oracle/oradata/ipcc/sysaux01.dbf'; ......
執(zhí)行結(jié)束之后,將表空間全部**online,**使用以下語句生成表空間online的SQL語句
SELECT 'alter tablespace ' || Ds.Tablespace_Name || ' online;' FROM Sys.Dba_Tablespaces Ds WHERE Ds.Contents <> 'TEMPORARY' AND Ds.Tablespace_Name <> 'UNDOTBS1' AND Ds.Tablespace_Name <> 'SYSTEM';
生成的SQL語句如下,使用sysdba賬戶執(zhí)行
alter tablespace SYSAUX online; alter tablespace USERS online; ......
四、臨時(shí)數(shù)據(jù)文件位置更改
臨時(shí)表空間比較特殊,不能將臨時(shí)表空間offline,需要將臨時(shí)表空間的臨時(shí)數(shù)據(jù)文件offline。
數(shù)據(jù)庫在open狀態(tài)下,生成臨時(shí)數(shù)據(jù)文件offline的SQL語句如下:
SELECT 'alter database tempfile ''' || File_Name || ''' offline;' FROM Dba_Temp_Files ORDER BY File_Id;
生成的SQL語句如下,使用sysdba賬戶執(zhí)行
alter database tempfile '/oradata/ipcc/temp01.dbf' offline; alter database tempfile '/oradata/ricd_temp10' offline; ......
將臨時(shí)數(shù)據(jù)文件復(fù)制到/home/oracle/oradata目錄下
生成rename臨時(shí)數(shù)據(jù)文件的SQL語句如下:
SELECT 'alter database rename file ''' || File_Name || ''' to ''' ||
'/home/oracle' || File_Name || ''';'
FROM Dba_Temp_Files
ORDER BY File_Id;生成的SQL語句如下,使用sysdba賬戶執(zhí)行
alter database rename file '/oradata/oa/temp01.dbf' to '/home/oracle/oradata/oa/temp01.dbf'; alter database rename file '/oradata/oa_temp10' to '/home/oracle/oradata/oa_temp10'; ......
執(zhí)行結(jié)束之后,將臨時(shí)數(shù)據(jù)文件online,生成臨時(shí)數(shù)據(jù)文件online的SQL語句如下:
SELECT 'alter database tempfile ''' || File_Name ||
''' online;'
FROM Dba_Temp_Files
ORDER BY File_Id;生成的SQL語句如下,使用sysdba賬戶執(zhí)行
alter database tempfile '/home/oracle/oradata/oa/temp01.dbf' online; alter database tempfile '/home/oracle/oradata/oa_temp10' online; ......
至此,臨時(shí)數(shù)據(jù)文件位置更改結(jié)束
五、臨時(shí)數(shù)據(jù)文件位置更改
數(shù)據(jù)庫可以在mount狀態(tài)或open狀態(tài)下。
查看日志文件狀態(tài)
select group#,thread#,sequence#,members,archived,status from v$log; select member from v$logfile;
當(dāng)日志文件狀態(tài)不為current的時(shí)候,將日志文件復(fù)制到新目錄/home/oracle/oradata下,然后可以切換日志文件位置。也可以使用alter system switch logfile,切換日志文件狀態(tài)
SQL> alter database rename file '/oradata/oa/redo01.log' to '/home/oracle/oradata/oa/redo01.log'; SQL> alter database rename file '/oradata/oa/redo02.log' to '/home/oracle/oradata/oa/redo02.log';
至此,日志文件位置更改結(jié)束。當(dāng)所有文件位置均更改結(jié)束時(shí),測(cè)試數(shù)據(jù)庫的可用性;如果無問題,可以刪除舊數(shù)據(jù)目錄下的文件。
總結(jié)
到此這篇關(guān)于Oracle數(shù)據(jù)庫如何更改數(shù)據(jù)文件位置的文章就介紹到這了,更多相關(guān)Oracle更改數(shù)據(jù)文件位置內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Window下Oracle Database 11g 發(fā)行版2安裝教程
這篇文章主要為大家詳細(xì)介紹了Window下Oracle Database 11g 發(fā)行版2安裝教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-07-07
Win11系統(tǒng)下Oracle11g數(shù)據(jù)庫下載與安裝使用詳細(xì)教程(圖解)
Oracle11g是Oracle公司出的一個(gè)比較輕量版的數(shù)據(jù)庫,在window系統(tǒng)上安裝比較方便,這篇文章主要給大家介紹了關(guān)于Win11系統(tǒng)下Oracle11g數(shù)據(jù)庫下載與安裝使用的相關(guān)資料,需要的朋友可以參考下2023-12-12
Oracle 數(shù)據(jù)庫 臨時(shí)數(shù)據(jù)的處理方法
在Oracle數(shù)據(jù)庫中進(jìn)行排序、分組匯總、索引等到作時(shí),會(huì)產(chǎn)生很多的臨時(shí)數(shù)據(jù)。如有一張員工信息表,數(shù)據(jù)庫中是安裝記錄建立的時(shí)間來保存的。2009-06-06

