数据文件的迁移

  • Post author:
  • Post category:其他


现有数据文件

SYS@testdb>select file#,name from v$datafile;

FILE# NAME

———- ————————————————–

1 /oracle/ora10g/oradata/system01.dbf

2 /oracle/ora10g/oradata/undotbs01.dbf

3 /oracle/ora10g/oradata/sysaux01.dbf

4 /oracle/ora10g/oradata/users01.dbf

5 /oracle/ora10g/oradata/leo1_01.dbf

6 /oracle/ora10g/oradata/mssm01.dbf

7 /oracle/ora10g/oradata/assm01.dbf

8 /oracle/ora10g/oradata/users02.dbf

9 /oracle/ora10g/product/10.2.0/db_1/dbs/oracleora10

goradatatest01.dbf

FILE# NAME

———- ————————————————–

10 /oracle/ora10g/product/10.2.0/db_1/dbs/wangche.bdf

11 /ora_data/wangche1.bdf

计划将数据文件迁移到/ora_data/10g_data,下面我们将使用rman copy 命令来完成这个测试实验。

tempapp@ora10g[#/ora_data/10g_data]rman target /

RMAN> startup mount;

RMAN> copy datafile 1 to ‘/ora_data/10g_data/system01.dbf’;

RMAN> copy datafile 2 to ‘/ora_data/10g_data/undotbs01.dbf’;

RMAN> copy datafile 3 to ‘/ora_data/10g_data/sysaux01.dbf’;

RMAN> copy datafile 4 to ‘/ora_data/10g_data/users01.dbf’;

RMAN> copy datafile 5 to ‘/ora_data/10g_data/leo1_01.dbf’;

RMAN> copy datafile 6 to ‘/ora_data/10g_data/mssm01.dbf’;

RMAN> copy datafile 7 to ‘/ora_data/10g_data/assm01.dbf’ ;

RMAN> copy datafile 8 to ‘/ora_data/10g_data/users02.dbf’;

RMAN> copy datafile 9 to ‘/ora_data/10g_data/aaa9.dbf’;

RMAN> copy datafile 10 to ‘/ora_data/10g_data/wangche.bdf’;

RMAN> copy datafile 11 to ‘/ora_data/10g_data/wangche1.bdf’;

run{

set newname for datafile 1 to ‘/ora_data/10g_data/system01.dbf’;

set newname for datafile 2 to ‘/ora_data/10g_data/undotbs01.dbf’;

set newname for datafile 3 to ‘/ora_data/10g_data/sysaux01.dbf’;

set newname for datafile 4 to ‘/ora_data/10g_data/users01.dbf’;

set newname for datafile 5 to ‘/ora_data/10g_data/leo1_01.dbf’;

set newname for datafile 6 to ‘/ora_data/10g_data/mssm01.dbf’;

set newname for datafile 7 to ‘/ora_data/10g_data/assm01.dbf’ ;

set newname for datafile 8 to ‘/ora_data/10g_data/users02.dbf’;

set newname for datafile 9 to ‘/ora_data/10g_data/aaa9.dbf’;

set newname for datafile 10 to ‘/ora_data/10g_data/wangche.bdf’;

set newname for datafile 11 to ‘/ora_data/10g_data/wangche1.bdf’;

switch datafile all;

}

RMAN> alter database open;

检查数据文件

SYS@testdb>select tablespace_name,file_name from dba_data_files;

TABLESPACE_NAME                FILE_NAME

—————————— ————————————————–

SYSTEM                         /ora_data/10g_data/system01.dbf

UNDOTBS                        /ora_data/10g_data/undotbs01.dbf

SYSAUX                         /ora_data/10g_data/sysaux01.dbf

USERS                          /ora_data/10g_data/users01.dbf

LEO1                           /ora_data/10g_data/leo1_01.dbf

MSSM                           /ora_data/10g_data/mssm01.dbf

ASSM                           /ora_data/10g_data/assm01.dbf

SYSTEM                         /ora_data/10g_data/users02.dbf

TEST                           /ora_data/10g_data/aaa9.dbf

WANGCHE                        /ora_data/10g_data/wangche.bdf

WANGCHE1                       /ora_data/10g_data/wangche1.bdf

11 rows selected.

检查没有问题后,删除原来的数据文件

rm -f /oracle/ora10g/oradata/system01.dbf

rm -f /oracle/ora10g/oradata/undotbs01.dbf

rm -f /oracle/ora10g/oradata/sysaux01.dbf

rm -f /oracle/ora10g/oradata/users01.dbf

rm -f /oracle/ora10g/oradata/leo1_01.dbf

rm -f /oracle/ora10g/oradata/mssm01.dbf

rm -f /oracle/ora10g/oradata/assm01.dbf

rm -f /oracle/ora10g/oradata/users02.dbf

rm -f /oracle/ora10g/product/10.2.0/db_1/dbs/oracleora10goradatatest01.dbf

rm -f /oracle/ora10g/product/10.2.0/db_1/dbs/wangche.bdf

rm -f /ora_data/wangche1.bdf

下面使用alter database rename file 命令来修改数据文件名称

SYS@testdb>select tablespace_name,file_name from dba_data_files;

TABLESPACE_NAME                FILE_NAME

—————————— ————————————————–

SYSTEM                         /ora_data/10g_data/system01.dbf

UNDOTBS                        /ora_data/10g_data/undotbs01.dbf

SYSAUX                         /ora_data/10g_data/sysaux01.dbf

USERS                          /ora_data/10g_data/users01.dbf

LEO1                           /ora_data/10g_data/leo1_01.dbf

MSSM                           /ora_data/10g_data/mssm01.dbf

ASSM                           /ora_data/10g_data/assm01.dbf

SYSTEM                         /ora_data/10g_data/users02.dbf

TEST                           /ora_data/10g_data/aaa9.dbf

WANGCHE                        /ora_data/10g_data/wangche.bdf

WANGCHE1                       /ora_data/10g_data/wangche1.bdf

11 rows selected.

计划将 /ora_data/10g_data/users02.dbf 修改为 /ora_data/10g_data/system02.dbf

计划将 /ora_data/10g_data/aaa9.dbf 修改为 /ora_data/10g_data/test01.dbf

SYS@testdb>shutdown immediate

Database closed.

Database dismounted.

ORACLE instance shut down.

将数据文件使用操作系统命令重命名。这里需要注意,我这个是测试系统,正式系统建议使用cp命令

tempapp@ora10g[#/ora_data/10g_data]mv users02.dbf system02.dbf

tempapp@ora10g[#/ora_data/10g_data]mv aaa9.dbf test01.dbf

将数据库启动到mount状态

SYS@testdb>startup mount;

SYS@testdb>alter database rename file ‘/ora_data/10g_data/users02.dbf’ to ‘/ora_data/10g_data/system02.dbf’;

SYS@testdb>alter database rename file ‘/ora_data/10g_data/aaa9.dbf’ to ‘/ora_data/10g_data/test01.dbf’;

启动数据库

SYS@testdb>alter database open;

检查数据文件迁移情况

SYS@testdb>select tablespace_name,file_name from dba_data_files;

TABLESPACE_NAME                FILE_NAME

—————————— ————————————————–

SYSTEM                         /ora_data/10g_data/system01.dbf

UNDOTBS                        /ora_data/10g_data/undotbs01.dbf

SYSAUX                         /ora_data/10g_data/sysaux01.dbf

USERS                          /ora_data/10g_data/users01.dbf

LEO1                           /ora_data/10g_data/leo1_01.dbf

MSSM                           /ora_data/10g_data/mssm01.dbf

ASSM                           /ora_data/10g_data/assm01.dbf

SYSTEM                         /ora_data/10g_data/system02.dbf

TEST                           /ora_data/10g_data/test01.dbf

WANGCHE                        /ora_data/10g_data/wangche.bdf

WANGCHE1                       /ora_data/10g_data/wangche1.bdf

11 rows selected.

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/11590946/viewspace-1102877/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/11590946/viewspace-1102877/