利用RMAN在文件系统与ASM之间迁移数据库(3)

4.如果被迁移的数据库是备库,需要停止管理恢复模式
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;


执行一致性关闭
RMAN> SHUTDOWN IMMEDIATE;

5.在目录/u02/asm_backup中创建一个 pfile参数文件来引用新的SPFILE文件,并重新启动实例到nomount状态。
[Oracle@oracle11g asm_backup]$ vi inittest_temp.ora
spfile='/u02/asm_backup/spfiletest.ora'


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

SQL> startup nomount pfile='/u02/asm_backup/inittest_temp.ora'
ORACLE instance started.

Total System Global Area  167772160 bytes
Fixed Size                  1272600 bytes
Variable Size            109053160 bytes
Database Buffers          54525952 bytes
Redo Buffers                2920448 bytes


6.为了下一步将控制文件迁移到文件系统中,修改control_files参数:
SQL> alter system set control_files='/u02/asm_backup/control01.ctl' scope=spfile;

System altered.


7.通过设置db_recovery_file_dest和db_recovery_file_dest_size来指定闪回区,这里闪回区大小设置为2G(因为这里只是进行迁移测试实验)
SQL> alter system set db_recovery_file_dest_size=2G;

System altered.

SQL> alter system set db_recovery_file_dest='/u01/app/oracle/oradata/flash_recovery_area' scope=spfile;

System altered.

8.将实例重新启动到nomount状态,使用RMAN在文件系统中创建新的控制文件(使用原来控制文件来创建),切换数据文件,并执执恢复
SQL> shutdown immediate
ORA-01507: database not mounted


ORACLE instance shut down.
SSQL> startup nomount pfile='/u02/asm_backup/inittest_temp.ora'
ORACLE instance started.

Total System Global Area  167772160 bytes
Fixed Size                  1272600 bytes
Variable Size            109053160 bytes
Database Buffers          54525952 bytes
Redo Buffers                2920448 bytes

RMAN> restore controlfile from '+DISK1/control01.ctl';

Starting restore at 2015-04-01 21:17:54
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK

channel ORA_DISK_1: copied control file copy
output filename=/u02/asm_backup/control01.ctl
Finished restore at 2015-04-01 21:18:04


RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

RMAN> switch database to copy;

datafile 1 switched to datafile copy "/u02/asm_backup/data_D-TEST_I-2168949517_TS-SYSTEM_FNO-1_4rq3amf5"
datafile 2 switched to datafile copy "/u02/asm_backup/data_D-TEST_I-2168949517_TS-UNDOTBS1_FNO-2_4vq3amik"
datafile 3 switched to datafile copy "/u02/asm_backup/data_D-TEST_I-2168949517_TS-SYSAUX_FNO-3_4sq3amgj"
datafile 4 switched to datafile copy "/u02/asm_backup/data_D-TEST_I-2168949517_TS-USERS_FNO-4_50q3amin"
datafile 5 switched to datafile copy "/u02/asm_backup/data_D-TEST_I-2168949517_TS-EXAMPLE_FNO-5_4tq3amhm"
datafile 6 switched to datafile copy "/u02/asm_backup/data_D-TEST_I-2168949517_TS-TSPITR_FNO-6_4uq3ami5"
datafile 7 switched to datafile copy "/u02/asm_backup/data_D-TEST_I-2168949517_TS-TEST_FNO-7_51q3amio"
starting full resync of recovery catalog
full resync complete

RMAN> recover database;

Starting recover at 2015-04-01 21:18:38
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK

starting media recovery
media recovery complete, elapsed time: 00:00:02

Finished recover at 2015-04-01 21:18:41


8.将临时文件迁移到ASM,必须为每个临时文件执行set newname命令,然后执行switch命令
RMAN> run
2> {
3> set newname for tempfile '+DISK1/TEST/TEMPFILE/TEMP.256.875908789' to '/u02/asm_backup/temp01.dbf';
4> switch tempfile all;
5> }

executing command: SET NEWNAME

renamed temporary file 1 to /u02/asm_backup/temp01.dbf in control file
starting full resync of recovery catalog
full resync complete

9.禁用闪回数据库并重新启动闪回数据库让闪回日志创建在ASM中
SQL> alter database flashback off;

Database altered.

SQL> alter database flashback on;

Database altered.


10.如果迁移的是主库,打开数据库
SQL> alter database open;

Database altered.


如果是备库,恢复管理恢复模式
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE;

11.对于主库,要迁移联机重做日志文件是通过增加新的重做日志文件并存储在文件系统中并删除旧的重做日志文件。对于备库,就是删除旧的备重做日志并增加新的备重做日志并存储在文件系统中。

SQL> select * from v$log;

GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARCHIVED STATUS          FIRST_CHANGE# FIRST_TIME
---------- ---------- ---------- ---------- ---------- -------- ---------------- ------------- -----------
        1          1        99  52428800          1 NO      CURRENT                1292113 2015/4/1 20
        2          1        98  52428800          1 YES      INACTIVE              1290567 2015/4/1 20
        3          1          0  52428800          1 YES      UNUSED                      0


SQL> alter database drop logfile group 2;

Database altered.

SQL> alter database add logfile group 2 '/u02/asm_backup/redo02.log' size 50M;

Database altered.

SQL> alter database drop logfile group 3;

Database altered.

SQL> alter database add logfile group 3 '/u02/asm_backup/redo03.log' size 50M;

Database altered.

SQL> alter system switch logfile;

System altered.


SQL> alter database drop logfile group 1;
alter database drop logfile group 1
*
ERROR at line 1:
ORA-01623: log 1 is current log for instance test (thread 1) - cannot drop
ORA-00312: online log 1 thread 1: '+DISK1/redo01.log'

SQL> alter database clear logfile group 1;

Database altered.

SQL> alter database drop logfile group 1;

Database altered.

SQL> alter database add logfile group 1 '/u02/asm_backup/redo01.log' size 50M;

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/c0029ab565deb2079ed1e29ebe653229.html