天天看點

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

到此,實驗完成。