ORACLE 本地冷迁移

需求:把oracle数据库的数据文件,redo文件,控制文件迁移到本地的其它目录。

1.测试环境:

操作系统redhat 6.3,数据库oracle 11.2.0.1.0

[root@dbtest1 ~]# uname -a
Linux dbtest1 2.6.32-279.el6.x86_64 #1 SMP Wed Jun 13 18:24:36 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux

SQL
> select * from v$version; BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production PL/SQL Release 11.2.0.1.0 - Production CORE 11.2.0.1.0 Production TNS for Linux: Version 11.2.0.1.0 - Production NLSRTL Version 11.2.0.1.0 - Production

源数据文件位置:/home/data/oracle/dbtest/

目标数据文件位置:/oracle_data/

2.关闭数据库监听,禁止外部访问数据库

-bash-4.1$ lsnrctl stop

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 18-DEC-2014 13:22:05

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=dbtest)))
The command completed successfully

3.关闭oracle数据库

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

4.备份pfile,spfile,控制文件(至少备份一个)

-bash-4.1$ cd /$ORACLE_HOME/dbs
-bash-4.1$ cp initdbtest.ora initdbtest.ora.141218
-bash-4.1$ cp spfiledbtest.ora  spfiledbtest.ora.141218
-bash-4.1$ cd /home/data/oracle/dbtest/
-bash-4.1$ cp control01.ctl control01.ctl.141218

5.更新pfile,从spfile创建pfile

SQL> create pfile='$ORACLE_HOME/dbs/initdbtest.ora' from spfile='$ORACLE_HOME/dbs/spfiledbtest.ora';

注:默认位置的话,可以直接使用create pfile from spfile来创建的,创建后检查一下时间戳来确认。

6.修改pfile中的控制文件的位置

把/home/data/oracle/dbtest/control01.ctl修改为/oracle_data/control01.ctl

-bash-4.1$ cd /$ORACLE_HOME/dbs/
-bash-4.1$ ls
hc_dbtest.dat  initdbtest.ora  initdbtest.ora.141218  init.ora  lkDBTEST  orapwdbtest  spfiledbtest.ora  spfiledbtest.ora.141218
-bash-4.1$ cat initdbtest.ora |grep control
*.control_files='/home/data/oracle/dbtest/control01.ctl','/home/app/ora11g/flash_recovery_area/dbtest/control02.ctl'
使用vi编辑该文件
-bash-4.1$ cat initdbtest.ora |grep control
*.control_files='/oracle_data/control01.ctl','/home/app/ora11g/flash_recovery_area/dbtest/control02.ctl'

注:如果有多个要修改的话,方法是一样的。

7.复制源数据目录下的文件,包括控制文件,数据文件和redo文件

-bash-4.1$ cp /home/data/oracle/dbtest/*  /oracle_data/ 

8.使用pfile来启动数据库到mount状态

SQL> startup pfile='$ORACLE_HOME/dbs/initdbtest.ora' mount
ORACLE instance started.

Total System Global Area 1603411968 bytes
Fixed Size                  2213776 bytes
Variable Size            1241516144 bytes
Database Buffers          352321536 bytes
Redo Buffers                7360512 bytes
Database mounted.

9.重命名数据文件,redo文件的位置

SQL> ALTER DATABASE RENAME FILE '/home/data/oracle/dbtest/redo01.log' to '/oracle_data/redo01.log';

Database altered.

SQL>ALTER DATABASE RENAME FILE '/home/data/oracle/dbtest/system01.dbf' to '/oracle_data/system01.dbf';

Database altered.

......

10. 打开数据库

SQL> alter database open;

Database altered.

11.检查数据文件,redo等文件位置是否正确

SQL> select file_name from dba_data_files;

FILE_NAME
--------------------------------------------------------------------------------
/oracle_data/users01.dbf
/oracle_data/undotbs01.dbf
/oracle_data/sysaux01.dbf
/oracle_data/system01.dbf
/oracle_data/laputa_dat.dbf
/oracle_data/laputa_idx_01.dbf

6 rows selected.


SQL> select file_name from dba_temp_files;

FILE_NAME
--------------------------------------------------------------------------------
/oracle_data/temp01.dbf



SQL> select name from v$controlfile;

NAME
--------------------------------------------------------------------------------
/oracle_data/control01.ctl
/home/app/ora11g/flash_recovery_area/dbtest/control02.ctl

SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
/oracle_data/redo03.log
/oracle_data/redo02.log
/oracle_data/redo01.log

12.同步spfile到新的文件(简化写法)

SQL> create spfile from pfile;

File created.

13.重启一次数据库确认一切正常

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup
ORACLE instance started.

Total System Global Area 1603411968 bytes
Fixed Size                  2213776 bytes
Variable Size            1241516144 bytes
Database Buffers          352321536 bytes
Redo Buffers                7360512 bytes
Database mounted.
Database opened.
SQL> 

14.开启数据库监听

-bash-4.1$ lsnrctl start

注意问题:

1.在rename文件的时候,如果涉及到的文件比较多,建议把语句放在一个sql文件中,然后再在sqlplus中执行,否则可能会导致语句在中间断裂(一条语句被命令行看成2行,会报错)。如果发生了语句的断裂,重新把语句放在sql文件中执行即可,这些rename语句重复执行会报错,但是不影响最终的结果。

2.迁移redo文件可以在线执行,用添加redo group,删除redo group的办法。

3.非系统表空间可以在不关闭数据库的方法迁移,对表空间进行offline,移动对应数据文件,rename数据文件,online表空间。

原文地址:https://www.cnblogs.com/opalyao/p/4172137.html