天天看点

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

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

实验环境:

Oracle Version:11gR2                    System:IBM AIX 5L

Target Database:orcl                     Auxiliary Database:orcl

NOTE:

(1)RMAN 异机恢复的时候,db_name必须相同。如果说要想改成其他的实例名,可以在恢复成功后,用nid 命令修改。实例名的信息会记录到控制文件里,所以如果在恢复的时候,如果实例名不一致,恢复的时候会报错。                               

(2)如果恢复的路径和源库不一致,就需要在restore时用set 命令指定新位置。并且使用switch datafile all将信息更新到控制文件中。

在做duplicate的时候,RMAN 会自动根据pfile中的log_file_name_convert和db_file_name_convert来进行set 的转换。手工restore时,只能使用set 命令转换。

(3)异机恢复对相同目录和不同目录都做了说明。

(4)最后测试了NID 修改DBID 和DBNAME.

实验步骤:

一. Target库准备工作:

1. 查询DBID

$ sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on Mon Apr 11 19:56:08 2011

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

idle> conn /as sysdba

Connected.

[email protected]> select name,dbid from v$database;

NAME                                                     DBID

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

ORCL                                               1275959622

2. 备份Target Database

$ rman target sys/[email protected]

Recovery Manager: Release 11.2.0.1.0 - Production on Mon Apr 11 19:59:34 2011

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (DBID=1275959622)

准备一个0级和1级备份:

RMAN> RUN {

2> allocate channel c1 type disk;

3> allocate channel c2 type disk;

4> backup incremental level=0 skip inaccessible filesperset 5 database format='/u02/backup/orcl_lev0_%U_%T' tag='orcl_lev0';

5> sql 'alter system archive log current';

6> backup archivelog all tag='arc_bak' format='/u02/backup/arch_%U_%T' skip inaccessible filesperset 5 not backed up 1 times delete input;

7> backup current controlfile tag='bak_ctlfile' format='/u02/backup/ctl_file_%U_%T';

8> backup spfile tag='spfile' format='/u02/backup/ORCL_spfile_%U_%T';

9> release channel c2;

10> release channel c1;

11> }

allocated channel: c1

channel c1: SID=198 device type=DISK

allocated channel: c2

channel c2: SID=10 device type=DISK

Starting backup at 11-APR-11

channel c1: starting incremental level 0 datafile backup set

channel c1: specifying datafile(s) in backup set

input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf

input datafile file number=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf

input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf

channel c1: starting piece 1 at 11-APR-11

channel c2: starting incremental level 0 datafile backup set

channel c2: specifying datafile(s) in backup set

input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf

input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf

channel c2: starting piece 1 at 11-APR-11

channel c1: finished piece 1 at 11-APR-11

piece handle=/u02/backup/orcl_lev0_0km9hi1b_1_1_20110411 tag=ORCL_LEV0 comment=NONE

channel c1: backup set complete, elapsed time: 00:00:03

channel c2: finished piece 1 at 11-APR-11

piece handle=/u02/backup/orcl_lev0_0lm9hi1b_1_1_20110411 tag=ORCL_LEV0 comment=NONE

channel c2: backup set complete, elapsed time: 00:00:03

Finished backup at 11-APR-11

Starting Control File and SPFILE Autobackup at 11-APR-11

piece handle=/u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_11/o1_mf_s_748210222_6t79my7k_.bkp comment=NONE

Finished Control File and SPFILE Autobackup at 11-APR-11

sql statement: alter system archive log current

Starting backup at 11-APR-11

current log archived

channel c1: starting archived log backup set

channel c1: specifying archived log(s) in backup set

input archived log thread=1 sequence=11 RECID=6 STAMP=748188047

channel c1: starting piece 1 at 11-APR-11

channel c2: starting archived log backup set

channel c2: specifying archived log(s) in backup set

input archived log thread=1 sequence=12 RECID=7 STAMP=748210223

input archived log thread=1 sequence=13 RECID=8 STAMP=748210223

channel c2: starting piece 1 at 11-APR-11

channel c1: finished piece 1 at 11-APR-11

piece handle=/u02/backup/arch_0nm9hi1f_1_1_20110411 tag=ARC_BAK comment=NONE

channel c1: backup set complete, elapsed time: 00:00:01

channel c1: deleting archived log(s)

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_11/o1_mf_1_11_6t6myz6m_.arc RECID=6 STAMP=748188047

channel c2: finished piece 1 at 11-APR-11

piece handle=/u02/backup/arch_0om9hi1f_1_1_20110411 tag=ARC_BAK comment=NONE

channel c2: backup set complete, elapsed time: 00:00:01

channel c2: deleting archived log(s)

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_11/o1_mf_1_12_6t79mzb6_.arc RECID=7 STAMP=748210223

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_11/o1_mf_1_13_6t79mzg7_.arc RECID=8 STAMP=748210223

Finished backup at 11-APR-11

Starting backup at 11-APR-11

channel c1: starting full datafile backup set

channel c1: specifying datafile(s) in backup set

including current control file in backup set

channel c1: starting piece 1 at 11-APR-11

channel c1: finished piece 1 at 11-APR-11

piece handle=/u02/backup/ctl_file_0pm9hi1h_1_1_20110411 tag=BAK_CTLFILE comment=NONE

channel c1: backup set complete, elapsed time: 00:00:03

Finished backup at 11-APR-11

Starting backup at 11-APR-11

channel c1: starting full datafile backup set

channel c1: specifying datafile(s) in backup set

including current SPFILE in backup set

channel c1: starting piece 1 at 11-APR-11

channel c1: finished piece 1 at 11-APR-11

piece handle=/u02/backup/ORCL_spfile_0qm9hi1l_1_1_20110411 tag=SPFILE comment=NONE

channel c1: backup set complete, elapsed time: 00:00:01

Finished backup at 11-APR-11

Starting Control File and SPFILE Autobackup at 11-APR-11

piece handle=/u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_11/o1_mf_s_748210230_6t79n67d_.bkp comment=NONE

Finished Control File and SPFILE Autobackup at 11-APR-11

released channel: c2

released channel: c1

RMAN> list backup;

List of Backup Sets

===================

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

13      Incr 0  444.11M    DISK        00:00:02     11-APR-11      

        BP Key: 13   Status: AVAILABLE  Compressed: NO  Tag: ORCL_LEV0

        Piece Name: /u02/backup/orcl_lev0_0km9hi1b_1_1_20110411

  List of Datafiles in backup set 13

  File LV Type Ckp SCN    Ckp Time  Name

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

  2    0  Incr 1108663    11-APR-11 /u01/app/oracle/oradata/orcl/sysaux01.dbf

  3    0  Incr 1108663    11-APR-11 /u01/app/oracle/oradata/orcl/undotbs01.dbf

  5    0  Incr 1108663    11-APR-11 /u01/app/oracle/oradata/orcl/example01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

14      Incr 0  595.57M    DISK        00:00:02     11-APR-11      

        BP Key: 14   Status: AVAILABLE  Compressed: NO  Tag: ORCL_LEV0

        Piece Name: /u02/backup/orcl_lev0_0lm9hi1b_1_1_20110411

  List of Datafiles in backup set 14

  File LV Type Ckp SCN    Ckp Time  Name

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

  1    0  Incr 1108664    11-APR-11 /u01/app/oracle/oradata/orcl/system01.dbf

  4    0  Incr 1108664    11-APR-11 /u01/app/oracle/oradata/orcl/users01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

15      Full    7.42M      DISK        00:00:00     11-APR-11      

        BP Key: 15   Status: AVAILABLE  Compressed: NO  Tag: TAG20110411T201022

        Piece Name: /u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_11/o1_mf_s_748210222_6t79my7k_.bkp

  SPFILE Included: Modification time: 10-APR-11

  SPFILE db_unique_name: ORCL

  Control File Included: Ckp SCN: 1108671      Ckp time: 11-APR-11

BS Key  Size       Device Type Elapsed Time Completion Time

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

16      7.23M      DISK        00:00:00     11-APR-11      

        BP Key: 16   Status: AVAILABLE  Compressed: NO  Tag: ARC_BAK

        Piece Name: /u02/backup/arch_0om9hi1f_1_1_20110411

  List of Archived Logs in backup set 16

  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time

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

  1    12      1098341    11-APR-11 1108687    11-APR-11

  1    13      1108687    11-APR-11 1108695    11-APR-11

BS Key  Size       Device Type Elapsed Time Completion Time

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

17      29.52M     DISK        00:00:00     11-APR-11      

        BP Key: 17   Status: AVAILABLE  Compressed: NO  Tag: ARC_BAK

        Piece Name: /u02/backup/arch_0nm9hi1f_1_1_20110411

  List of Archived Logs in backup set 17

  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time

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

  1    11      1081833    11-APR-11 1098341    11-APR-11

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

18      Full    7.39M      DISK        00:00:03     11-APR-11      

        BP Key: 18   Status: AVAILABLE  Compressed: NO  Tag: BAK_CTLFILE

        Piece Name: /u02/backup/ctl_file_0pm9hi1h_1_1_20110411

  Control File Included: Ckp SCN: 1108711      Ckp time: 11-APR-11

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

19      Full    80.00K     DISK        00:00:00     11-APR-11      

        BP Key: 19   Status: AVAILABLE  Compressed: NO  Tag: SPFILE

        Piece Name: /u02/backup/ORCL_spfile_0qm9hi1l_1_1_20110411

  SPFILE Included: Modification time: 10-APR-11

  SPFILE db_unique_name: ORCL

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

20      Full    7.42M      DISK        00:00:00     11-APR-11      

        BP Key: 20   Status: AVAILABLE  Compressed: NO  Tag: TAG20110411T201030

        Piece Name: /u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_11/o1_mf_s_748210230_6t79n67d_.bkp

  SPFILE Included: Modification time: 10-APR-11

  SPFILE db_unique_name: ORCL

  Control File Included: Ckp SCN: 1108725      Ckp time: 11-APR-11

RMAN> RUN {

2> allocate channel c1 type disk;

3> allocate channel c2 type disk;

4> backup incremental level=1 skip inaccessible filesperset 5 database format='/u02/backup/orcl_lev1_%U_%T' tag='orcl_lev1';

5> sql 'alter system archive log current';

6> backup archivelog all tag='arc_bak' format='/u02/backup/arch_%U_%T' skip inaccessible filesperset 5 not backed up 1 times delete input;

7> backup current controlfile tag='bak_ctlfile' format='/u02/backup/ctl_file_%U_%T';

8> backup spfile tag='spfile' format='/u02/backup/ORCL_spfile_%U_%T';

9> release channel c2;

10> release channel c1;

11> }

allocated channel: c1

channel c1: SID=198 device type=DISK

allocated channel: c2

channel c2: SID=10 device type=DISK

Starting backup at 11-APR-11

channel c1: starting incremental level 1 datafile backup set

channel c1: specifying datafile(s) in backup set

input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf

input datafile file number=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf

input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf

channel c1: starting piece 1 at 11-APR-11

channel c2: starting incremental level 1 datafile backup set

channel c2: specifying datafile(s) in backup set

input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf

input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf

channel c2: starting piece 1 at 11-APR-11

channel c1: finished piece 1 at 11-APR-11

piece handle=/u02/backup/orcl_lev1_0sm9hj59_1_1_20110411 tag=ORCL_LEV1 comment=NONE

channel c1: backup set complete, elapsed time: 00:00:01

channel c2: finished piece 1 at 11-APR-11

piece handle=/u02/backup/orcl_lev1_0tm9hj59_1_1_20110411 tag=ORCL_LEV1 comment=NONE

channel c2: backup set complete, elapsed time: 00:00:01

Finished backup at 11-APR-11

Starting Control File and SPFILE Autobackup at 11-APR-11

piece handle=/u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_11/o1_mf_s_748211370_6t7bqtly_.bkp comment=NONE

Finished Control File and SPFILE Autobackup at 11-APR-11

sql statement: alter system archive log current

Starting backup at 11-APR-11

current log archived

channel c1: starting archived log backup set

channel c1: specifying archived log(s) in backup set

input archived log thread=1 sequence=14 RECID=9 STAMP=748211371

channel c1: starting piece 1 at 11-APR-11

channel c2: starting archived log backup set

channel c2: specifying archived log(s) in backup set

input archived log thread=1 sequence=15 RECID=10 STAMP=748211371

channel c2: starting piece 1 at 11-APR-11

channel c1: finished piece 1 at 11-APR-11

piece handle=/u02/backup/arch_0vm9hj5b_1_1_20110411 tag=ARC_BAK comment=NONE

channel c1: backup set complete, elapsed time: 00:00:01

channel c1: deleting archived log(s)

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_11/o1_mf_1_14_6t7bqvov_.arc RECID=9 STAMP=748211371

channel c2: finished piece 1 at 11-APR-11

piece handle=/u02/backup/arch_10m9hj5b_1_1_20110411 tag=ARC_BAK comment=NONE

channel c2: backup set complete, elapsed time: 00:00:01

channel c2: deleting archived log(s)

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_11/o1_mf_1_15_6t7bqvpr_.arc RECID=10 STAMP=748211371

Finished backup at 11-APR-11

Starting backup at 11-APR-11

channel c1: starting full datafile backup set

channel c1: specifying datafile(s) in backup set

including current control file in backup set

channel c1: starting piece 1 at 11-APR-11

channel c1: finished piece 1 at 11-APR-11

piece handle=/u02/backup/ctl_file_11m9hj5d_1_1_20110411 tag=BAK_CTLFILE comment=NONE

channel c1: backup set complete, elapsed time: 00:00:01

Finished backup at 11-APR-11

Starting backup at 11-APR-11

channel c1: starting full datafile backup set

channel c1: specifying datafile(s) in backup set

including current SPFILE in backup set

channel c1: starting piece 1 at 11-APR-11

channel c1: finished piece 1 at 11-APR-11

piece handle=/u02/backup/ORCL_spfile_12m9hj5f_1_1_20110411 tag=SPFILE comment=NONE

channel c1: backup set complete, elapsed time: 00:00:01

Finished backup at 11-APR-11

Starting Control File and SPFILE Autobackup at 11-APR-11

piece handle=/u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_11/o1_mf_s_748211376_6t7br0g7_.bkp comment=NONE

Finished Control File and SPFILE Autobackup at 11-APR-11

released channel: c2

released channel: c1

RMAN> list backup;

List of Backup Sets

===================

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

13      Incr 0  444.11M    DISK        00:00:02     11-APR-11      

        BP Key: 13   Status: AVAILABLE  Compressed: NO  Tag: ORCL_LEV0

        Piece Name: /u02/backup/orcl_lev0_0km9hi1b_1_1_20110411

  List of Datafiles in backup set 13

  File LV Type Ckp SCN    Ckp Time  Name

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

  2    0  Incr 1108663    11-APR-11 /u01/app/oracle/oradata/orcl/sysaux01.dbf

  3    0  Incr 1108663    11-APR-11 /u01/app/oracle/oradata/orcl/undotbs01.dbf

  5    0  Incr 1108663    11-APR-11 /u01/app/oracle/oradata/orcl/example01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

14      Incr 0  595.57M    DISK        00:00:02     11-APR-11      

        BP Key: 14   Status: AVAILABLE  Compressed: NO  Tag: ORCL_LEV0

        Piece Name: /u02/backup/orcl_lev0_0lm9hi1b_1_1_20110411

  List of Datafiles in backup set 14

  File LV Type Ckp SCN    Ckp Time  Name

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

  1    0  Incr 1108664    11-APR-11 /u01/app/oracle/oradata/orcl/system01.dbf

  4    0  Incr 1108664    11-APR-11 /u01/app/oracle/oradata/orcl/users01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

15      Full    7.42M      DISK        00:00:00     11-APR-11      

        BP Key: 15   Status: AVAILABLE  Compressed: NO  Tag: TAG20110411T201022

        Piece Name: /u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_11/o1_mf_s_748210222_6t79my7k_.bkp

  SPFILE Included: Modification time: 10-APR-11

  SPFILE db_unique_name: ORCL

  Control File Included: Ckp SCN: 1108671      Ckp time: 11-APR-11

BS Key  Size       Device Type Elapsed Time Completion Time

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

16      7.23M      DISK        00:00:00     11-APR-11      

        BP Key: 16   Status: AVAILABLE  Compressed: NO  Tag: ARC_BAK

        Piece Name: /u02/backup/arch_0om9hi1f_1_1_20110411

  List of Archived Logs in backup set 16

  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time

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

  1    12      1098341    11-APR-11 1108687    11-APR-11

  1    13      1108687    11-APR-11 1108695    11-APR-11

BS Key  Size       Device Type Elapsed Time Completion Time

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

17      29.52M     DISK        00:00:00     11-APR-11      

        BP Key: 17   Status: AVAILABLE  Compressed: NO  Tag: ARC_BAK

        Piece Name: /u02/backup/arch_0nm9hi1f_1_1_20110411

  List of Archived Logs in backup set 17

  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time

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

  1    11      1081833    11-APR-11 1098341    11-APR-11

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

18      Full    7.39M      DISK        00:00:03     11-APR-11      

        BP Key: 18   Status: AVAILABLE  Compressed: NO  Tag: BAK_CTLFILE

        Piece Name: /u02/backup/ctl_file_0pm9hi1h_1_1_20110411

  Control File Included: Ckp SCN: 1108711      Ckp time: 11-APR-11

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

19      Full    80.00K     DISK        00:00:00     11-APR-11      

        BP Key: 19   Status: AVAILABLE  Compressed: NO  Tag: SPFILE

        Piece Name: /u02/backup/ORCL_spfile_0qm9hi1l_1_1_20110411

  SPFILE Included: Modification time: 10-APR-11

  SPFILE db_unique_name: ORCL

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

20      Full    7.42M      DISK        00:00:00     11-APR-11      

        BP Key: 20   Status: AVAILABLE  Compressed: NO  Tag: TAG20110411T201030

        Piece Name: /u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_11/o1_mf_s_748210230_6t79n67d_.bkp

  SPFILE Included: Modification time: 10-APR-11

  SPFILE db_unique_name: ORCL

  Control File Included: Ckp SCN: 1108725      Ckp time: 11-APR-11

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

21      Incr 1  112.00K    DISK        00:00:01     11-APR-11      

        BP Key: 21   Status: AVAILABLE  Compressed: NO  Tag: ORCL_LEV1

        Piece Name: /u02/backup/orcl_lev1_0tm9hj59_1_1_20110411

  List of Datafiles in backup set 21

  File LV Type Ckp SCN    Ckp Time  Name

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

  1    1  Incr 1109206    11-APR-11 /u01/app/oracle/oradata/orcl/system01.dbf

  4    1  Incr 1109206    11-APR-11 /u01/app/oracle/oradata/orcl/users01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

22      Incr 1  272.00K    DISK        00:00:01     11-APR-11      

        BP Key: 22   Status: AVAILABLE  Compressed: NO  Tag: ORCL_LEV1

        Piece Name: /u02/backup/orcl_lev1_0sm9hj59_1_1_20110411

  List of Datafiles in backup set 22

  File LV Type Ckp SCN    Ckp Time  Name

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

  2    1  Incr 1109205    11-APR-11 /u01/app/oracle/oradata/orcl/sysaux01.dbf

  3    1  Incr 1109205    11-APR-11 /u01/app/oracle/oradata/orcl/undotbs01.dbf

  5    1  Incr 1109205    11-APR-11 /u01/app/oracle/oradata/orcl/example01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

23      Full    7.42M      DISK        00:00:00     11-APR-11      

        BP Key: 23   Status: AVAILABLE  Compressed: NO  Tag: TAG20110411T202930

        Piece Name: /u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_11/o1_mf_s_748211370_6t7bqtly_.bkp

  SPFILE Included: Modification time: 10-APR-11

  SPFILE db_unique_name: ORCL

  Control File Included: Ckp SCN: 1109213      Ckp time: 11-APR-11

BS Key  Size       Device Type Elapsed Time Completion Time

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

24      42.00K     DISK        00:00:00     11-APR-11      

        BP Key: 24   Status: AVAILABLE  Compressed: NO  Tag: ARC_BAK

        Piece Name: /u02/backup/arch_0vm9hj5b_1_1_20110411

  List of Archived Logs in backup set 24

  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time

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

  1    14      1108695    11-APR-11 1109229    11-APR-11

BS Key  Size       Device Type Elapsed Time Completion Time

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

25      2.00K      DISK        00:00:00     11-APR-11      

        BP Key: 25   Status: AVAILABLE  Compressed: NO  Tag: ARC_BAK

        Piece Name: /u02/backup/arch_10m9hj5b_1_1_20110411

  List of Archived Logs in backup set 25

  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time

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

  1    15      1109229    11-APR-11 1109237    11-APR-11

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

26      Full    7.39M      DISK        00:00:01     11-APR-11      

        BP Key: 26   Status: AVAILABLE  Compressed: NO  Tag: BAK_CTLFILE

        Piece Name: /u02/backup/ctl_file_11m9hj5d_1_1_20110411

  Control File Included: Ckp SCN: 1109253      Ckp time: 11-APR-11

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

27      Full    80.00K     DISK        00:00:00     11-APR-11      

        BP Key: 27   Status: AVAILABLE  Compressed: NO  Tag: SPFILE

        Piece Name: /u02/backup/ORCL_spfile_12m9hj5f_1_1_20110411

  SPFILE Included: Modification time: 10-APR-11

  SPFILE db_unique_name: ORCL

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

28      Full    7.42M      DISK        00:00:00     11-APR-11      

        BP Key: 28   Status: AVAILABLE  Compressed: NO  Tag: TAG20110411T202936

        Piece Name: /u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_11/o1_mf_s_748211376_6t7br0g7_.bkp

  SPFILE Included: Modification time: 10-APR-11

  SPFILE db_unique_name: ORCL

  Control File Included: Ckp SCN: 1109266      Ckp time: 11-APR-11

RMAN> 

3. 将备份集传到Auxiliary相同目录

$ mkdir -p /u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_11

$ scp [email protected]:/u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_11/o1_mf_s_748210222_6t79my7k_.bkp .

Enter passphrase for key '/home/oracle/.ssh/id_rsa': 

o1_mf_s_748210222_6t79my7k_.bkp                                                                                            100% 7616KB   7.4MB/s   00:00    

$ scp [email protected]:/u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_11/o1_mf_s_748210230_6t79n67d_.bkp .

Enter passphrase for key '/home/oracle/.ssh/id_rsa': 

o1_mf_s_748210230_6t79n67d_.bkp                                                                                            100% 7616KB   7.4MB/s   00:00    

$ scp [email protected]:/u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_11/o1_mf_s_748211370_6t7bqtly_.bkp .

Enter passphrase for key '/home/oracle/.ssh/id_rsa': 

o1_mf_s_748211370_6t7bqtly_.bkp                                                                                            100% 7616KB   7.4MB/s   00:00    

$ scp [email protected]:/u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_11/o1_mf_s_748211376_6t7br0g7_.bkp .

Enter passphrase for key '/home/oracle/.ssh/id_rsa': 

o1_mf_s_748211376_6t7br0g7_.bkp                                                                                            100% 7616KB   7.4MB/s   00:00    

$ cd /u02/backup/

$ scp [email protected]:/u02/backup/* .

Enter passphrase for key '/home/oracle/.ssh/id_rsa': 

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

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

arch_0nm9hi1f_1_1_20110411                                                                                                 100%   30MB  29.5MB/s   00:00    

arch_0om9hi1f_1_1_20110411                                                                                                 100% 7406KB   7.2MB/s   00:01    

arch_0vm9hj5b_1_1_20110411                                                                                                 100%   43KB  42.5KB/s   00:00    

arch_10m9hj5b_1_1_20110411                                                                                                 100% 2560     2.5KB/s   00:00    

ctl_file_0pm9hi1h_1_1_20110411                                                                                             100% 7584KB   7.4MB/s   00:00    

ctl_file_11m9hj5d_1_1_20110411                                                                                             100% 7584KB   7.4MB/s   00:00    

orcl_lev0_0km9hi1b_1_1_20110411                                                                                            100%  444MB  63.5MB/s   00:07    

orcl_lev0_0lm9hi1b_1_1_20110411                                                                                            100%  596MB  59.6MB/s   00:10    

orcl_lev1_0sm9hj59_1_1_20110411                                                                                            100%  280KB 280.0KB/s   00:00    

orcl_lev1_0tm9hj59_1_1_20110411                                                                                            100%  120KB 120.0KB/s   00:00    

传递备份集完成

二.Auxiliary库准备工作:

1. 创建口令文件

$ cd $ORACLE_HOME/bin

$ orapwd file=$ORACLE_HOME/dbs/orapworcl password=oracle entries=8

$ cd $ORACLE_HOME/dbs                                             

$ ls

init.ora      initorcl.ora  orapworcl

2. 构建辅助数据库目录结构

2.1 Oracle data 目录

$ mkdir -p /u01/oradata/orcl

2.2 其他目录

$ mkdir -p /u01/app/oracle/admin/orcl/adump

$ mkdir -p /u01/app/oracle/admin/orcl/dpdump

$ mkdir -p /u01/app/oracle/admin/orcl/pfile

$ mkdir -p /u01/app/oracle/admin/orcl/scripts

$ mkdir -p /u01/app/oracle/diag

$ mkdir -p /u01/app/oracle/flash_recovery_area/orcl

3. 创建初始化参数

将Target库的pfile文件copy过来。

也可以使用RMAN从我们Target库的备份集中恢复,因为我们之前备份过spfile。不过使用RMAN,DB要先启动到nomout状态。这个可以用默认的init.ora来启动。

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

ORACLE instance started.

Total System Global Area 6847938560 bytes

Fixed Size                  2219808 bytes

Variable Size            3539992800 bytes

Database Buffers         3288334336 bytes

Redo Buffers               17391616 bytes

SQL> quit

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Mon Apr 11 21:00:03 2011

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (not mounted)

RMAN> restore spfile to pfile '/u01/app/oracle/product/10.2.0/db_1/dbs/initorcl.ora' from '/u02/backup/ORCL_spfile_0qm9hi1l_1_1_20110411';

Starting restore at 11-APR-11

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=63 device type=DISK

channel ORA_DISK_1: restoring spfile from AUTOBACKUP /u02/backup/ORCL_spfile_0qm9hi1l_1_1_20110411

channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete

Finished restore at 11-APR-11

如果修改数据文件保存的位置,那么要修改控制文件的相关的参数:

*.control_files='/u01/oradata/control01.ctl','/u01/oradata/control02.ctl','/u01/oradata/control03.ctl'

*.db_name='mahee'

4. 将用pfile将Auxiliary库启动到nomout状态

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

ORACLE instance started.

Total System Global Area 6847938560 bytes

Fixed Size                  2219808 bytes

Variable Size            3539992800 bytes

Database Buffers         3288334336 bytes

Redo Buffers               17391616 bytes

SQL> quit

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Mon Apr 11 21:11:50 2011

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (not mounted)

RMAN> restore controlfile from '/u02/backup/ctl_file_11m9hj5d_1_1_20110411';

Starting restore at 11-APR-11

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=63 device type=DISK

channel ORA_DISK_1: restoring control file

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

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

output file name=/u01/app/oracle/flash_recovery_area/orcl/control02.ctl

Finished restore at 11-APR-11

restore的时候需要控制文件,控制文件恢复的位置,是我们在pfile中的control_files参数控制的。

6. 将Auxiliary DB启动到mout状态

RMAN> sql 'alter database mount';

sql statement: alter database mount

released channel: ORA_DISK_1

7.  restore数据库

7.1 恢复目录不同的情况:

因为我们的路径不同,所以我们需要使用set命令转换一下路径。

到Target库查询一下:

SQL> select file_id,file_name from dba_data_files order by 1;

   FILE_ID FILE_NAME

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

         1 /u01/app/oracle/oradata/orcl/system01.dbf

         2 /u01/app/oracle/oradata/orcl/sysaux01.dbf

         3 /u01/app/oracle/oradata/orcl/undotbs01.dbf

         4 /u01/app/oracle/oradata/orcl/users01.dbf

         5 /u01/app/oracle/oradata/orcl/example01.dbf

NOTE: restore的时候不会对temp表空间进行restore。所以restore之后,我们需要手工创建temp表空间。

RMAN> RUN {

2> set newname for datafile 1 to '/u01/oradata/orcl/system01.dbf';

3> set newname for datafile 2 to '/u01/oradata/orcl/sysaux01.dbf';

4> set newname for datafile 3 to '/u01/oradata/orcl/undotbs01.dbf';

5> set newname for datafile 4 to '/u01/oradata/orcl/users01.dbf';

6> set newname for datafile 5 to '/u01/oradata/orcl/example01.dbf';

7> restore database;

8> switch datafile all;

9> }

对switch datafile all的说明:

--对于nocatalog模式下,rman备份的信息是保存在控制文件里的,包括文件的路径信息。 这里的switch datafile all的作用,就是更新控制文件里的信息。 

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 11-APR-11

using channel ORA_DISK_1

datafile 1 is already restored to file /u01/oradata/orcl/system01.dbf

datafile 4 is already restored to file /u01/oradata/orcl/users01.dbf

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/oradata/orcl/sysaux01.dbf

channel ORA_DISK_1: restoring datafile 00003 to /u01/oradata/orcl/undotbs01.dbf

channel ORA_DISK_1: restoring datafile 00005 to /u01/oradata/orcl/example01.dbf

channel ORA_DISK_1: reading from backup piece /u02/backup/orcl_lev0_0km9hi1b_1_1_20110411

channel ORA_DISK_1: piece handle=/u02/backup/orcl_lev0_0km9hi1b_1_1_20110411 tag=ORCL_LEV0

channel ORA_DISK_1: restored backup piece 1

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

Finished restore at 11-APR-11

datafile 1 switched to datafile copy

input datafile copy RECID=8 STAMP=748214583 file name=/u01/oradata/orcl/system01.dbf

datafile 2 switched to datafile copy

input datafile copy RECID=9 STAMP=748214583 file name=/u01/oradata/orcl/sysaux01.dbf

datafile 3 switched to datafile copy

input datafile copy RECID=10 STAMP=748214583 file name=/u01/oradata/orcl/undotbs01.dbf

datafile 4 switched to datafile copy

input datafile copy RECID=11 STAMP=748214583 file name=/u01/oradata/orcl/users01.dbf

datafile 5 switched to datafile copy

input datafile copy RECID=12 STAMP=748214583 file name=/u01/oradata/orcl/example01.dbf

7.2 恢复目录相同

这种情况比较简单,直接:

RMAN> restore database

8. recover DB

RMAN> recover database;

Starting recover at 11-APR-11

using channel ORA_DISK_1

channel ORA_DISK_1: starting incremental datafile backup set restore

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

destination for restore of datafile 00001: /u01/oradata/orcl/system01.dbf

destination for restore of datafile 00004: /u01/oradata/orcl/users01.dbf

channel ORA_DISK_1: reading from backup piece /u02/backup/orcl_lev1_0tm9hj59_1_1_20110411

channel ORA_DISK_1: piece handle=/u02/backup/orcl_lev1_0tm9hj59_1_1_20110411 tag=ORCL_LEV1

channel ORA_DISK_1: restored backup piece 1

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

channel ORA_DISK_1: starting incremental datafile backup set restore

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

destination for restore of datafile 00002: /u01/oradata/orcl/sysaux01.dbf

destination for restore of datafile 00003: /u01/oradata/orcl/undotbs01.dbf

destination for restore of datafile 00005: /u01/oradata/orcl/example01.dbf

channel ORA_DISK_1: reading from backup piece /u02/backup/orcl_lev1_0sm9hj59_1_1_20110411

channel ORA_DISK_1: piece handle=/u02/backup/orcl_lev1_0sm9hj59_1_1_20110411 tag=ORCL_LEV1

channel ORA_DISK_1: restored backup piece 1

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

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=14

channel ORA_DISK_1: reading from backup piece /u02/backup/arch_0vm9hj5b_1_1_20110411

channel ORA_DISK_1: piece handle=/u02/backup/arch_0vm9hj5b_1_1_20110411 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/flash_recovery_area/ORCL/archivelog/2011_04_11/o1_mf_1_14_6t7g27t7_.arc thread=1 sequence=14

channel default: deleting archived log(s)

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_11/o1_mf_1_14_6t7g27t7_.arc RECID=11 STAMP=748214775

channel ORA_DISK_1: starting archived log restore to default destination

channel ORA_DISK_1: restoring archived log

archived log thread=1 sequence=15

channel ORA_DISK_1: reading from backup piece /u02/backup/arch_10m9hj5b_1_1_20110411

channel ORA_DISK_1: piece handle=/u02/backup/arch_10m9hj5b_1_1_20110411 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/flash_recovery_area/ORCL/archivelog/2011_04_11/o1_mf_1_15_6t7g2929_.arc thread=1 sequence=15

channel default: deleting archived log(s)

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_11/o1_mf_1_15_6t7g2929_.arc RECID=12 STAMP=748214777

unable to find archived log

archived log thread=1 sequence=16

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

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

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

RMAN-03002: failure of recover command at 04/11/2011 21:26:18

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

之后会报一个错误:

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

这里是提醒恢复到一个未知的scn号。在alter database mount之后,通过set until scn或者set until time命令设置恢复到的scn号或时间,就可以避免这个错误。

9. 用open resetlogs打开数据库

SQL> alter database open resetlogs;

Database altered.

我测试的平台是11gR2的版本,在open resetlogs之后,自动在原来默认的路径创建了temp表空间和3组redo文件。

如果恢复目录和原来相同,就不用修改。

如果目录不同,我们就需要把这些文件移到我们现在的data目录。

源目录:

$ cd /u01/app/oracle/oradata/orcl

$ ls

redo01.log  redo02.log  redo03.log  temp01.dbf

现在的目录:

$ cd /u01/oradata/orcl

$ ls

control01.ctl  example01.dbf  sysaux01.dbf   system01.dbf   undotbs01.dbf  users01.dbf

(1)处理online redo log

SQL> select group#,bytes/1024/1024||'M',status from v$log;

    GROUP# BYTES/1024/1024||'M'                      STATUS

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

         1 50M                                       CURRENT

         2 50M                                       UNUSED

         3 50M                                       UNUSED

SQL> select group#,member from v$logfile;

    GROUP# MEMBER

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

         3 /u01/app/oracle/oradata/orcl/redo03.log

         2 /u01/app/oracle/oradata/orcl/redo02.log

         1 /u01/app/oracle/oradata/orcl/redo01.log

oracle至少有2组redo log。所以我们可以将已经完成归档的redo drop掉,重新创建。

SQL> alter database drop logfile group 3;

SQL> alter database add logfile group 3 ('/u01/oradata/orcl/redo03.log') size 50m;

Database altered.

SQL> alter database drop logfile group 2;

Database altered.

SQL> alter database add logfile group 2 ('/u01/oradata/orcl/redo02.log') size 50m;

Database altered.

SQL> alter system switch logfile;

System altered.

SQL> alter system checkpoint;

System altered.

SQL> select group#,bytes/1024/1024||'M',status from v$log;

    GROUP# BYTES/1024/1024||'M'                      STATUS

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

         1 50M                                       INACTIVE

         2 50M                                       INACTIVE

         3 50M                                       CURRENT

SQL> alter database drop logfile group 1;

Database altered.

SQL> alter database add logfile group 1 ('/u01/oradata/orcl/redo01.log') size 50m;

Database altered.

SQL> select group#,bytes/1024/1024||'M',status from v$log;

    GROUP# BYTES/1024/1024||'M'                      STATUS

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

         1 50M                                       UNUSED

         2 50M                                       INACTIVE

         3 50M                                       CURRENT

SQL> select group#,member from v$logfile;

    GROUP# MEMBER

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

         3 /u01/oradata/orcl/redo03.log

         2 /u01/oradata/orcl/redo02.log

         1 /u01/oradata/orcl/redo01.log

(2)处理temp临时表空间

SQL> select name from v$tempfile;

NAME

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

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

--表空间offline

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

Database altered.

--在OS级别移动temp的数据文件

SQL> !mv /u01/app/oracle/oradata/orcl/temp01.dbf /u01/oradata/orcl/temp01.dbf;

--修改控制文件中temp文件的信息

SQL> alter database rename file '/u01/app/oracle/oradata/orcl/temp01.dbf' to '/u01/oradata/orcl/temp01.dbf';

Database altered.

--temp表空间online

SQL> alter database tempfile '/u01/oradata/orcl/temp01.dbf' online;

Database altered.

--验证

SQL> select name from v$tempfile;

NAME

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

/u01/oradata/orcl/temp01.dbf

10. NID修改DBID和DBNAME

先查看,这个和我们之前的一样

SQL> select name,dbid from v$database;

NAME                                                     DBID

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

ORCL                                               1275959622

NOTE:

(1)在修改DBID期间仍然可能会遇到不可恢复的错误,所以修改之前备份数据库,特别是控制文件,因为nid会修改控制文件中的信息。

(2)需要将DB启动到mount状态才能修改。

SQL> shutdown immediate

SQL> startup mount;

在执行NID命令之前:一定要关闭所有的session连接。

nid命令到执行的最后会关闭数据库,如果有session连接,就会阻止这个操作,修改dbid就会被挂死。如果中断这个操作,修改就会失败,数据库就不能mount,需要恢复。

(1)只改DBID,不改db_name

$ nid target=sys/oracle

DBNEWID: Release 11.2.0.1.0 - Production on Mon Apr 11 22:27:49 2011

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

Connected to database ORCL (DBID=1275959622)

Connected to server version 11.2.0

Control Files in database:

    /u01/oradata/orcl/control01.ctl

    /u01/app/oracle/flash_recovery_area/orcl/control02.ctl

Change database ID of database ORCL? (Y/[N]) => Y

Proceeding with operation

Changing database ID from 1275959622 to 1276002278

    Control File /u01/oradata/orcl/control01.ctl - modified

    Control File /u01/app/oracle/flash_recovery_area/orcl/control02.ctl - modified

    Datafile /u01/oradata/orcl/system01.db - dbid changed

    Datafile /u01/oradata/orcl/sysaux01.db - dbid changed

    Datafile /u01/oradata/orcl/undotbs01.db - dbid changed

    Datafile /u01/oradata/orcl/users01.db - dbid changed

    Datafile /u01/oradata/orcl/example01.db - dbid changed

    Datafile /u01/oradata/orcl/temp01.db - dbid changed

    Control File /u01/oradata/orcl/control01.ctl - dbid changed

    Control File /u01/app/oracle/flash_recovery_area/orcl/control02.ctl - dbid changed

    Instance shut down

Database ID for database ORCL changed to 1276002278.

All previous backups and archived redo logs for this database are unusable.

Database is not aware of previous backups and archived logs in Recovery Area.

Database has been shutdown, open database with RESETLOGS option.

Succesfully changed database ID.

DBNEWID - Completed succesfully.

重启打开数据库:

$ sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on Mon Apr 11 22:29:54 2011

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

SQL> conn /as sysdba

Connected to an idle instance.

SQL> startup

ORACLE instance started.

Total System Global Area 6847938560 bytes

Fixed Size                  2219808 bytes

Variable Size            3539992800 bytes

Database Buffers         3288334336 bytes

Redo Buffers               17391616 bytes

Database mounted.

ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

SQL> alter database open resetlogs;

Database altered.

SQL> select name,dbid from v$database;

NAME            DBID

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

ORCL      1276002278

(2)修改DBID和DB_NAME

注意一点,修改DB_NAME之前,要将spfile创建成pfile,因为修改dbname之后,原来的参数文件就没用了。所以要保证最新的参数。 还需要修改DB_NAME的值为最新值。修改完之后,然后用这个新参数启动DB.

SQL> create spfile from pfile='?/dbs/initorcl.ora';

File created.

SQL> create pfile='/u01/inittmp.ora' from spfile;

File created.

$ nid target=sys/oracle dbname=mahee

DBNEWID: Release 11.2.0.1.0 - Production on Mon Apr 11 22:38:15 2011

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

Connected to database ORCL (DBID=1276002278)

Connected to server version 11.2.0

Control Files in database:

    /u01/oradata/orcl/control01.ctl

    /u01/app/oracle/flash_recovery_area/orcl/control02.ctl

Change database ID and database name ORCL to MAHEE? (Y/[N]) => Y

Proceeding with operation

Changing database ID from 1276002278 to 3475057431

Changing database name from ORCL to MAHEE

    Control File /u01/oradata/orcl/control01.ctl - modified

    Control File /u01/app/oracle/flash_recovery_area/orcl/control02.ctl - modified

    Datafile /u01/oradata/orcl/system01.db - dbid changed, wrote new name

    Datafile /u01/oradata/orcl/sysaux01.db - dbid changed, wrote new name

    Datafile /u01/oradata/orcl/undotbs01.db - dbid changed, wrote new name

    Datafile /u01/oradata/orcl/users01.db - dbid changed, wrote new name

    Datafile /u01/oradata/orcl/example01.db - dbid changed, wrote new name

    Datafile /u01/oradata/orcl/temp01.db - dbid changed, wrote new name

    Control File /u01/oradata/orcl/control01.ctl - dbid changed, wrote new name

    Control File /u01/app/oracle/flash_recovery_area/orcl/control02.ctl - dbid changed, wrote new name

    Instance shut down

Database name changed to MAHEE.

Modify parameter file and generate a new password file before restarting.

Database ID for database MAHEE changed to 3475057431.

All previous backups and archived redo logs for this database are unusable.

Database is not aware of previous backups and archived logs in Recovery Area.

Database has been shutdown, open database with RESETLOGS option.

Succesfully changed database name and ID.

DBNEWID - Completed succesfully.

验证:

首先,更改刚才创建的那个inittmp.ora文件db_name为mahee

$ export ORACLE_SID=mahee

$ sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on Mon Apr 11 22:46:05 2011

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

SQL> conn /as sysdba

Connected to an idle instance.

SQL> startup mount pfile='/u01/inittmp.ora';

ORACLE instance started.

Total System Global Area 6847938560 bytes

Fixed Size                  2219808 bytes

Variable Size            3539992800 bytes

Database Buffers         3288334336 bytes

Redo Buffers               17391616 bytes

Database mounted.

SQL> alter database open resetlogs;

Database altered.

SQL> select name,dbid from v$database;

NAME            DBID

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

MAHEE     3475057431

到此,实验完成。