先假设一种情况,假设有一个数据库,数据量是2T。 如果要对这个数据库进行迁移,在不考虑磁盘空间的前提下,要求在最短的时间内完成切换操作。

 

       在不考虑磁盘空间前提下,备份时间,网络传输时间,恢复时间。 这个时间对于7*24*365的系统来说,肯定是没办法承受的。

       如果在考虑下备份空间+迁移后的空间。 这个对磁盘的开销也是非常大。

 

       在我的前一篇Blog里,提到了RMAN的异机恢复,这种方法可以缩短我们DB的迁移时间。 但是空间问题还没有解决。在这一篇,我们主要从迁移时间的角度来考虑这个问题。

       RMAN 备份异机恢复 并创建新DBID

​http://www.cndba.cn/Dave/article/1474​


在异机恢复中,我们最后对db 是用open resetlogs的方式打开的。

 

我们先看open resetlogs的影响:

(1)如果current online redo可以访问,那么对其进行归档操作。 然后清空所有online redo 的内容,并将日志的序列设置为1.

(2)如果online redo 不存在,就创建online redo。 这个位置是在控制文件里记录的。 我们在做RMAN 异机恢复的时候,验证过这点。

(3)开始一个新的incarnation,初始化redo thread和 online redo 在控制文件中的记录。

        比如:将redo thread 的状态设置为closed,在redo thread的记录中设置当前的log sequence 为1. 设置每个redo thread 的checkpoint 到log sequence 1。

从每个thread 选择一个redo log,并设置其sequence 为1.

(4)在控制文件中更新当前所有的datafile 和online redo logs,及以后的归档文件用新的resetlog SCN 和 time stamp。

       注意: open resetlogs 不会充值SCN.

 

一般用open resetlogs 打开数据库之后,建议立即对数据库进行一次备份。

 

下面是一个迁移的测试:

 

1. 在Target 库rman 备份数据库,并将备份copy到Auxiliary库的相同位置

       RMAN 的恢复对备份位置有讲究,对于nocatalog模式下,这些备份的位置是写在控制文件里的。所以目录结构要相同。

 

关于RMAN 的shell 备份脚本,参考:

Nocatalog 下的RMAN 增量备份 shell脚本

​http://www.cndba.cn/Dave/article/1476​


[oracle@qs-dmm-rh1 backup]$ scp * 192.168.2.43:/u01/backup

oracle@192.168.2.43's password:

arch_23m709vi_1_1_20110312                                        100% 6431KB   6.3MB/s   00:00   

ctl_file_24m709vn_1_1_20110312                                    100% 9568KB   9.3MB/s   00:01   

dave_lev0_1rm709u9_1_1_20110312                                   100%  610MB  12.0MB/s   00:51   

dave_lev0_1sm709u9_1_1_20110312                                   100%  399MB  11.7MB/s   00:34   

dave_lev0_1tm709u9_1_1_20110312                                   100% 4728KB   4.6MB/s   00:00   

dave_lev0_1vm709uk_1_1_20110312                                   100% 1344KB   1.3MB/s   00:01   

dave_spfile_25m709vp_1_1_20110312                                 100%   96KB  96.0KB/s   00:00  

 

2. 在Auxiliary库创建相关的目录,口令文件,和初始化文件。

       初始化文件可以直接从Target copy过来。如果目录结构相同的话,都不用修改参数。

 

3. 用初始化文件将数据库启动到noumout状态。

SQL> startup nomount pfile=?/dbs/initdave.ora

ORACLE instance started.

 

Total System Global Area  196681728 bytes

Fixed Size                  1335444 bytes

Variable Size              83890028 bytes

Database Buffers          109051904 bytes

Redo Buffers                2404352 bytes

 

4. 恢复控制文件

RMAN> restore controlfile from '/u01/backup/ctl_file_2qm72jcf_1_1_20110312';

 

Starting restore at 12-MAR-11

using channel ORA_DISK_1

 

channel ORA_DISK_1: restoring control file

channel ORA_DISK_1: restore complete, elapsed time: 00:00:02

output file name=/u01/oradata/control01.ctl

output file name=/u01/oradata/control02.ctl

output file name=/u01/oradata/control03.ctl

Finished restore at 12-MAR-11

 

5. 将数据库启动到mout状态

SQL> alter database mount;

Database altered.

 

6. restore 数据库

RMAN> restore database;

 

Starting restore at 12-MAR-11

released channel: ORA_DISK_1

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=20 device type=DISK

 

channel ORA_DISK_1: starting datafile backup set restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/dave/undotbs01.dbf

channel ORA_DISK_1: reading from backup piece /u01/backup/dave_lev0_28m70ar0_1_1_20110312

channel ORA_DISK_1: piece handle=/u01/backup/dave_lev0_28m70ar0_1_1_20110312 tag=DAVE_LEV0

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

channel ORA_DISK_1: starting datafile backup set restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/dave/users01.dbf

channel ORA_DISK_1: reading from backup piece /u01/backup/dave_lev0_2am70ara_1_1_20110312

channel ORA_DISK_1: piece handle=/u01/backup/dave_lev0_2am70ara_1_1_20110312 tag=DAVE_LEV0

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

channel ORA_DISK_1: starting datafile backup set restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/dave/sysaux01.dbf

channel ORA_DISK_1: reading from backup piece /u01/backup/dave_lev0_27m70ar0_1_1_20110312

channel ORA_DISK_1: piece handle=/u01/backup/dave_lev0_27m70ar0_1_1_20110312 tag=DAVE_LEV0

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:00:25

channel ORA_DISK_1: starting datafile backup set restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/dave/system01.dbf

channel ORA_DISK_1: reading from backup piece /u01/backup/dave_lev0_26m70ar0_1_1_20110312

channel ORA_DISK_1: piece handle=/u01/backup/dave_lev0_26m70ar0_1_1_20110312 tag=DAVE_LEV0

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:00:25

Finished restore at 12-MAR-11

 

7. recover 数据库

RMAN> recover database;

 

Starting recover at 12-MAR-11

using channel ORA_DISK_1

 

starting media recovery

 

channel ORA_DISK_1: starting archived log restore to default destination

channel ORA_DISK_1: restoring archived log

archived log thread=1 sequence=24

channel ORA_DISK_1: reading from backup piece /u01/backup/arch_2cm70as8_1_1_20110312

channel ORA_DISK_1: piece handle=/u01/backup/arch_2cm70as8_1_1_20110312 tag=ARC_BAK

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_24_745352047.dbf thread=1 sequence=24

channel ORA_DISK_1: starting archived log restore to default destination

channel ORA_DISK_1: restoring archived log

archived log thread=1 sequence=25

channel ORA_DISK_1: reading from backup piece /u01/backup/arch_2dm70as8_1_1_20110312

channel ORA_DISK_1: piece handle=/u01/backup/arch_2dm70as8_1_1_20110312 tag=ARC_BAK

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_25_745352047.dbf thread=1 sequence=25

unable to find archived log

archived log thread=1 sequence=26

RMAN-00571: ===========================================================

RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571: ===========================================================

RMAN-03002: failure of recover command at 03/12/2011 00:58:04

RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 26 and starting SCN of 1055401

 

8. 在主库进行一些事务操作

SQL> create table anhui as select * from all_tables;

Table created.

SQL> commit;

Commit complete.

SQL> alter system switch logfile;

System altered.

 

9. 关闭主库,迅速把主库的归档文件和online redo 复制到Auxiliary库

[oracle@qs-dmm-rh1 archivelog]$ scp * 192.168.2.43:/u01/archivelog

oracle@192.168.2.43's password:

1_26_745352047.dbf                                                100% 1509KB   1.5MB/s   00:00   

 

[oracle@qs-dmm-rh1 dave]$ scp redo* 192.168.2.43:/u01/app/oracle/oradata/dave/

oracle@192.168.2.43's password:

redo01.log                                                        100%   50MB  16.7MB/s   00:03   

redo02.log                                                        100%   50MB  12.5MB/s   00:04   

redo03.log                                                        100%   50MB  12.5MB/s   00:04   

[oracle@qs-dmm-rh1 dave]$

 

 

10. 再次recover database

RMAN> recover database;

 

Starting recover at 12-MAR-11

using channel ORA_DISK_1

 

starting media recovery

 

archived log for thread 1 with sequence 26 is already on disk as file /u01/app/oracle/oradata/dave/redo02.log

archived log for thread 1 with sequence 27 is already on disk as file /u01/app/oracle/oradata/dave/redo03.log

archived log file name=/u01/app/oracle/oradata/dave/redo02.log thread=1 sequence=26

archived log file name=/u01/app/oracle/oradata/dave/redo03.log thread=1 sequence=27

media recovery complete, elapsed time: 00:00:05

Finished recover at 12-MAR-11

 

11. 打开数据库

 

SQL>alter database open resetlogs;

 

SQL> select count(*) from dave;

 

  COUNT(*)

----------

     71157

 

 

12. 重建Temp 表空间

       在恢复的时候,会自动创建TEMP 表空间。但是和布豆聊到这个问题的时候,他说这个temp 文件好像没有起到作用。 尤其是数据量大的时候,所以他建议重建添加temp 数据文件。

 

SQL> select name from v$tempfile;

NAME

--------------------------------------------------------------------------------

/u01/app/oracle/oradata/dave/temp01.dbf

 

SQL> alter tablespace temp add tempfile '/u01/app/oracle/oradata/dave/temp02.dbf ' size 8192M;

Tablespace altered.

 

SQL> select name from v$tempfile;

 

NAME

--------------------------------------------------------------------------------

/u01/app/oracle/oradata/dave/temp01.dbf

/u01/app/oracle/oradata/dave/temp02.dbf

 

SQL> alter database tempfile '/u01/app/oracle/oradata/dave/temp01.dbf' offline;

Database altered.

 

SQL> alter database tempfile '/u01/app/oracle/oradata/dave/temp01.dbf' drop including datafiles;

Database altered.

 

SQL> select name from v$tempfile;

NAME

--------------------------------------------------------------------------------

/u01/app/oracle/oradata/dave/temp02.dbf