在線移動(dòng)oracle 數(shù)據(jù)文件
Oracle數(shù)據(jù)文件可以在數(shù)據(jù)庫(kù)OPEN的時(shí)候被重命名或移動(dòng),但此時(shí)表空間必須為只讀,這將允許用戶從表中查詢,但禁止他們這樣做的插入,更新和刪除,在表空間至于只讀狀態(tài)的時(shí)候,凍結(jié)數(shù)據(jù)文件塊頭。阻止更新數(shù)據(jù)文件塊頭,此時(shí)才能在線拷貝數(shù)據(jù)文件 《注:system表空間除外,system 表空間無(wú)法offline》
本測(cè)試以TEST表空間為例
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
1. 確定要移動(dòng)TEST表空間中所有的數(shù)據(jù)文件
SQL > SELECT FILE_NAME, STATUS FROM DBA_DATA_FILES
WHERE TABLESPACE_NAME = 'TEST';
FILE_NAME STATUS
-------------------------------------------------- ---------
/oracle/oradata/orcl/test.dbf AVAILABLE
/oracle/oradata/orcl/test03.dbf AVAILABLE
2. 確定所有TEST表空間中數(shù)據(jù)文件狀態(tài)為 AVAILABLE.
SQL> SELECT FILE_NAME,STATUS FROM DBA_DATA_FILES WHERE TABLESPACE_NAME='TEST
FILE_NAME STATUS
------------------------------------------------------------ ---------
/oracle/oradata/orcl/test.dbf AVAILABLE
/oracle/oradata/orcl/test03.dbf AVAILABLE
3. 將TEST表空間至于只讀模式.
SQL > ALTER TABLESPACE TEST READ ONLY;
Tablespace altered.
4. 查詢數(shù)據(jù)字典確定TEST表空間為只讀模式.
SQL > SELECT TABLESPACE_NAME, STATUS FROM DBA_TABLESPACES
WHERE TABLESPACE_NAME = 'TEST';
TABLESPACE_NAME STATUS
------------------------------ ---------
TEST READ ONLY
5. 拷貝TEST表空間所有數(shù)據(jù)文件到新的位置,拷貝完成后確定權(quán)限和大小與原數(shù)據(jù)文件相匹配
[oracle@oracle orcl]$ du -sh test.dbf
21M test.dbf
[oracle@oracle orcl]$ du -sh test03.dbf
41M test03.dbf
[oracle@oracle orcl]$ cp test.dbf /oracle/testdata/
[oracle@oracle orcl]$ cp test03.dbf /oracle/testdata/
[oracle@oracle orcl]$ cd /oracle/testdata/
[oracle@oracle testdata]$ ls
-rw-r----- 1 oracle oinstall 41951232 May 7 23:49 test03.dbf
-rw-r----- 1 oracle oinstall 20979712 May 7 23:49 test.dbf
[oracle@oracle testdata]$ du -sh test.dbf
21M test.dbf
[oracle@oracle testdata]$ du -sh test03.dbf
41M test03.dbf
[oracle@oracle testdata]$ ls -al
-rw-r----- 1 oracle oinstall 41951232 May 7 23:49 test03.dbf
-rw-r----- 1 oracle oinstall 20979712 May 7 23:49 test.dbf
6. 數(shù)據(jù)文件全部拷貝完成后,將TEST表空間offline,此時(shí)所有用戶都不能訪問test表空間.
SQL > ALTER TABLESPACE TEST OFFLINE;
Tablespace altered.
7. 更新控制文件信息.
SQL > ALTER DATABASE RENAME FILE '/oracle/oradata/orcl/test.dbf' TO '/oracle/testdata//test.dbf';
Database altered.
SQL > ALTER DATABASE RENAME FILE '/oracle/oradata/orcl/test03.dbf' TO '/oracle/testdata//test03.dbf';
Database altered.
8. 所有數(shù)據(jù)文件更新后,將TEST表空間ONLINE.
SQL > ALTER TABLESPACE TEST ONLINE;
9. 將TEST表空間至于讀寫模式.
SQL > ALTER TABLESPACE TEST READ WRITE;
10. 備份控制文件,查看控制文件信息
SQL > ALTER DATABASE BACKUP CONTROLFILE TO TRACE;
Database altered.
$cd /oracle/admin/orcl/udump
more orcl_ora_8453.trc
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "ORCL" NORESETLOGS NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/oracle/oradata/orcl/redo01.log' SIZE 50M,
GROUP 2 '/oracle/oradata/orcl/redo02.log' SIZE 50M,
GROUP 3 '/oracle/oradata/orcl/redo03.log' SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'/oracle/oradata/orcl/system01.dbf',
'/oracle/oradata/orcl/undotbs01.dbf',
'/oracle/oradata/orcl/sysaux01.dbf',
'/oracle/oradata/orcl/users01.dbf',
'/oracle/testdata/test.dbf',
'/oracle/oradata/orcl/system02.dbf',
'/oracle/oradata/orcl/test02.dbf',
'/oracle/testdata/test03.dbf',
'/oracle/oradata/orcl/jycq.dbf'
在更新的控制文件中, TEST表空間數(shù)據(jù)文件已經(jīng)換了位置
11. 查看數(shù)據(jù)字典中TEST信息
SQL> select file_name from dba_data_files where tablespace_name='TEST';
FILE_NAME
--------------------------------------------------------------------------------
/oracle/testdata/test.dbf
/oracle/testdata/test03.dbf
數(shù)據(jù)文件已經(jīng)移到指定位置,此時(shí)數(shù)據(jù)文件已經(jīng)移動(dòng)完成,可以將TEST表空間原來(lái)位置的數(shù)據(jù)文件刪除
本文標(biāo)題:在線移動(dòng)oracle數(shù)據(jù)文件位置
轉(zhuǎn)載注明:
http://weahome.cn/article/jsegji.html