使用RMAN進行Oracle資料庫遷移

forrest_itpub發表於2016-12-11
參考了: http://blog.itpub.net/29654823/viewspace-1252777/ Oracle 利用RMAN 完成資料遷移

run
{
allocate channel ch1 device type disk format '/opt/oracle/bakdatabase/%U';
allocate channel ch2 device type disk format '/opt/oracle/bakdatabase/%U';
backup as backupset database include current controlfile plus archivelog delete all input;
}

整體流程:對A機的資料庫來一個熱備,並且是一個全備(備份了資料檔案、控制檔案、歸檔日誌檔案:backup as backupset database include current controlfile plus archivelog delete all input;),然後透過scp命令把備份傳到B機,
之後再把伺服器引數檔案的備份和redo線上日誌從A傳給B機,最後再在B庫上 restore 和recover。

根據資料庫的啟動流程:
   可以知道最先讀取引數檔案,所以應該先還原引數檔案,
   然後會讀控制檔案,所以你要再修復控制檔案,
   最後再修復資料檔案。

環境資訊

CentOS 6.5
Oracle database 12C
源端A機:主機名:centhost2,IP:192.168.1.146,資料庫例項orcl
目的端B機:主機名:centhost3,IP:192.168.1.147,且目的端已經存在一個資料庫例項orclrman


具體操作流程:

一:對A庫做一個熱全備。

點選(此處)摺疊或開啟

  1. [laolv@centhost3 admin]$ rman
  2. Recovery Manager: Release 12.1.0.2.0 - Production on Tue Dec 6 23:52:04 2016
  3. Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.
  4. RMAN> connect target sys/forrest@orcl
  5. connected to target database: ORCL (DBID=1429293327)
  6. RMAN> connect catalog rman/forrest@orclrman
  7. connected to recovery catalog database
  8. RMAN> register database;
  9. database registered in recovery catalog
  10. starting full resync of recovery catalog
  11. full resync complete
  12. RMAN> resync catalog; --如果目標資料庫的表空間和資料檔案等發生變化,則會帶動目標資料庫的控制檔案被改寫,此時,可以執行如下命令進行恢復目錄與目標資料庫控制檔案同步
  13. starting full resync of recovery catalog
  14. full resync complete
  15. RMAN>
  16. RMAN> run
  17. 2> {
  18. 3> allocate channel ch1 device type disk format '/opt/oracle/bakdatabase/%U';
  19. 4> allocate channel ch2 device type disk format '/opt/oracle/bakdatabase/%U';
  20. 5> backup as backupset database include current controlfile plus archivelog delete all input; --注意沒有伺服器引數檔案
  21. 6> }
  22. released channel: ORA_DISK_1
  23. allocated channel: ch1
  24. channel ch1: SID=32 device type=DISK
  25. allocated channel: ch2
  26. channel ch2: SID=266 device type=DISK
  27. Starting backup at 10-DEC-16
  28. current log archived
  29. channel ch1: starting archived log backup set
  30. channel ch1: specifying archived log(s) in backup set
  31. input archived log thread=1 sequence=257 RECID=51 STAMP=930255168
  32. channel ch1: starting piece 1 at 10-DEC-16
  33. channel ch1: finished piece 1 at 10-DEC-16
  34. piece handle=/opt/oracle/bakdatabase/1nrn54a1_1_1( 這個是備份的archive log ) tag=TAG20161210T201249 comment=NONE
  35. channel ch1: backup set complete, elapsed time: 00:00:01
  36. channel ch1: deleting archived log(s)
  37. archived log file name=/opt/oracle/myarchive/1_257_901512594.dbf RECID=51 STAMP=930255168 (備份完archive log後,會刪除目的資料庫的自己的archive log)
  38. Finished backup at 10-DEC-16
  39. Starting backup at 10-DEC-16
  40. channel ch1: starting full datafile backup set
  41. channel ch1: specifying datafile(s) in backup set
  42. input datafile file number=00003 name=/opt/oracle/oradata/orcl/sysaux01.dbf
  43. input datafile file number=00004 name=/opt/oracle/oradata/orcl/undotbs01.dbf
  44. channel ch1: starting piece 1 at 10-DEC-16
  45. channel ch2: starting full datafile backup set
  46. channel ch2: specifying datafile(s) in backup set
  47. input datafile file number=00011 name=/opt/oracle/oradata/orcl/pdborcl/example01.dbf
  48. input datafile file number=00010 name=/opt/oracle/oradata/orcl/pdborcl/SAMPLE_SCHEMA_users01.dbf
  49. channel ch2: starting piece 1 at 10-DEC-16
  50. channel ch1: finished piece 1 at 10-DEC-16
  51. piece handle=/opt/oracle/bakdatabase/1orn54a4_1_1 tag=TAG20161210T201251 comment=NONE
  52. channel ch1: backup set complete, elapsed time: 00:00:45
  53. channel ch1: starting full datafile backup set
  54. channel ch1: specifying datafile(s) in backup set
  55. input datafile file number=00009 name=/opt/oracle/oradata/orcl/pdborcl/sysaux01.dbf
  56. input datafile file number=00008 name=/opt/oracle/oradata/orcl/pdborcl/system01.dbf
  57. channel ch1: starting piece 1 at 10-DEC-16
  58. channel ch2: finished piece 1 at 10-DEC-16
  59. piece handle=/opt/oracle/bakdatabase/1prn54a4_1_1 tag=TAG20161210T201251 comment=NONE
  60. channel ch2: backup set complete, elapsed time: 00:00:53
  61. channel ch2: starting full datafile backup set
  62. channel ch2: specifying datafile(s) in backup set
  63. input datafile file number=00001 name=/opt/oracle/oradata/orcl/system01.dbf
  64. input datafile file number=00006 name=/opt/oracle/oradata/orcl/users01.dbf
  65. channel ch2: starting piece 1 at 10-DEC-16
  66. channel ch1: finished piece 1 at 10-DEC-16
  67. piece handle=/opt/oracle/bakdatabase/1qrn54bi_1_1 tag=TAG20161210T201251 comment=NONE
  68. channel ch1: backup set complete, elapsed time: 00:01:23
  69. channel ch1: starting full datafile backup set
  70. channel ch1: specifying datafile(s) in backup set
  71. input datafile file number=00007 name=/opt/oracle/oradata/orcl/pdbseed/sysaux01.dbf
  72. channel ch1: starting piece 1 at 10-DEC-16
  73. channel ch2: finished piece 1 at 10-DEC-16
  74. piece handle=/opt/oracle/bakdatabase/1rrn54bq_1_1 tag=TAG20161210T201251 comment=NONE
  75. channel ch2: backup set complete, elapsed time: 00:01:15
  76. channel ch2: starting full datafile backup set
  77. channel ch2: specifying datafile(s) in backup set
  78. input datafile file number=00005 name=/opt/oracle/oradata/orcl/pdbseed/system01.dbf
  79. channel ch2: starting piece 1 at 10-DEC-16
  80. channel ch1: finished piece 1 at 10-DEC-16
  81. piece handle=/opt/oracle/bakdatabase/1srn54e5_1_1 tag=TAG20161210T201251 comment=NONE
  82. channel ch1: backup set complete, elapsed time: 00:00:26
  83. channel ch1: starting full datafile backup set
  84. channel ch1: specifying datafile(s) in backup set
  85. channel ch2: finished piece 1 at 10-DEC-16
  86. piece handle=/opt/oracle/bakdatabase/1trn54e5_1_1 tag=TAG20161210T201251 comment=NONE
  87. channel ch2: backup set complete, elapsed time: 00:00:26
  88. including current control file in backup set
  89. channel ch1: starting piece 1 at 10-DEC-16
  90. channel ch1: finished piece 1 at 10-DEC-16
  91. piece handle=/opt/oracle/bakdatabase/1urn54ev_1_1 tag=TAG20161210T201251 comment=NONE
  92. channel ch1: backup set complete, elapsed time: 00:00:01
  93. Finished backup at 10-DEC-16
  94. Starting backup at 10-DEC-16
  95. current log archived
  96. starting full resync of recovery catalog
  97. full resync complete
  98. channel ch1: starting archived log backup set
  99. channel ch1: specifying archived log(s) in backup set
  100. input archived log thread=1 sequence=258 RECID=52 STAMP=930255329
  101. channel ch1: starting piece 1 at 10-DEC-16
  102. channel ch1: finished piece 1 at 10-DEC-16
  103. piece handle=/opt/oracle/bakdatabase/1vrn54f4_1_1 (這個是備份的archive log)tag=TAG20161210T201532 comment=NONE
  104. channel ch1: backup set complete, elapsed time: 00:00:01
  105. channel ch1: deleting archived log(s)
  106. archived log file name=/opt/oracle/myarchive/1_258_901512594.dbf RECID=52 STAMP=930255329 (備份完archive log後,會刪除目的資料庫的自己的archive log)
  107. Finished backup at 10-DEC-16
  108. Starting Control File and SPFILE Autobackup at 10-DEC-16
  109. piece handle=/opt/oracle/fast_recovery_area/ORCL/autobackup/2016_12_10/o1_mf_s_930255335_d4qwh7mx_.bkp comment=NONE
  110. Finished Control File and SPFILE Autobackup at 10-DEC-16
  111. released channel: ch1
  112. released channel: ch2
  113. RMAN>
由以上輸出資訊可得:
  資料檔案datafile+控制檔案current control file+歸檔日誌檔案archive log,是在backup set中的,存放在指定的/opt/oracle/bakdatabase目錄下;
  歸檔日誌檔案備份完後,會刪除目的資料庫自己的歸檔日誌檔案。

 手動備份完後,目的資料庫會自動備份其自己的Control File和SPFILE。

二:把所做的備份用scp傳給B機。

1. 
[laolv@centhost3 bakfromcenthost2]$ scp -r laolv@192.168.1.146:/opt/oracle/bakdatabase .
laolv@192.168.1.146's password: 
1orn54a4_1_1                                                                                                                                                 100%  770MB   2.4MB/s   05:18    
1nrn54a1_1_1                                                                                                                                                 100% 7222KB   7.1MB/s   00:01    
1srn54e5_1_1                                                                                                                                                 100%  456MB  12.7MB/s   00:36    
1qrn54bi_1_1                                                                                                                                                 100%  672MB  14.6MB/s   00:46    
1urn54ev_1_1                                                                                                                                                 100%   17MB  17.2MB/s   00:00    
1trn54e5_1_1                                                                                                                                                 100%  205MB  15.8MB/s   00:13    
1vrn54f4_1_1                                                                                                                                                 100%   26KB  26.0KB/s   00:00    
1rrn54bq_1_1                                                                                                                                                 100%  694MB  21.0MB/s   00:33    
1prn54a4_1_1                                                                                                                                                 100%   97MB  32.5MB/s   00:03 

2.將正在使用的redo日誌複製到目標端
檢視redo日誌的資訊:
1) SQL> select * from v$log; 
    GROUP#    THREAD#  SEQUENCE#      BYTES  BLOCKSIZE  MEMBERS ARC
---------- ---------- ---------- ---------- ---------- ---------- ---
STATUS FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME     CON_ID
---------------- ------------- --------- ------------ --------- ----------
1    1     259   52428800   512 1 NO
CURRENT       6430035 10-DEC-16   2.8147E+14 0  --GROUP#=1的正在被使用,所以只傳它就行(因為別的已經被歸檔,)

2    1     257   52428800   512 1 YES
INACTIVE       6424841 10-DEC-16      6429930 10-DEC-16 0

3    1     258   52428800   512 1 YES
INACTIVE       6429930 10-DEC-16      6430035 10-DEC-16 0

2) SQL>  select * from v$logfile;  #檢視日誌的具體位置

    GROUP# STATUS  TYPE
---------- ------- -------
MEMBER
--------------------------------------------------------------------------------
IS_ CON_ID
--- ----------
3   ONLINE
/opt/oracle/oradata/orcl/redo03.log
NO     0

2   ONLINE
/opt/oracle/oradata/orcl/redo02.log
NO     0

    GROUP# STATUS  TYPE
---------- ------- -------
MEMBER
--------------------------------------------------------------------------------
IS_ CON_ID
--- ----------

1   ONLINE
/opt/oracle/oradata/orcl/redo01.log
NO     0

3)將正在使用的redo日誌複製到目標端


至於歸檔嘛  我在測試的時候沒有切換日誌+不存在日誌組寫滿的情況=>所以沒有產生歸檔;
又因為我在備份的時候加上了delete all input 所以會把已經備份的歸檔刪掉,所以你不會看到新的歸檔也就不用傳了。

三、將自動備份的引數檔案也複製到B機



四、在B機操作

1.開啟偽例項,注意可不要把B機的資料庫例項給開啟了因為我的測試B機也有資料庫。

--先停掉B機上已經有的資料庫例項


--啟動偽例項orcl
[laolv@centhost3 admin]$ export ORACLE_SID=orcl
[laolv@centhost3 admin]$ echo $ORACLE_SID
orcl
[laolv@centhost3 admin]$ rman target /
Recovery Manager: Release 12.1.0.2.0 - Production on Sat Dec 10 21:47:30 2016
Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.
connected to target database (not started)
RMAN>  startup nomount;  #啟動偽例項 
startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/opt/oracle/product/12.1.0/dbhome_1/dbs/initorcl.ora'
starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started

Total System Global Area    1073741824 bytes
Fixed Size                     2932632 bytes
Variable Size                281018472 bytes
Database Buffers             784334848 bytes
Redo Buffers                   5455872 bytes

RMAN> 

2.恢復服務引數檔案spfile,然後再關閉偽例項orcl


3.然後再起真正的例項,恢復控制檔案

1)參看恢復的引數檔案

要先建立audit_file_dest對應的目錄,然後啟動例項orcl


2)根據前面的備份資訊,可知控制問價記憶體放在1urn54ev_1_1備份中:
channel ch1: starting full datafile backup set
channel ch1: specifying datafile(s) in backup set
(channel ch2: finished piece 1 at 10-DEC-16
piece handle=/opt/oracle/bakdatabase/1trn54e5_1_1 tag=TAG20161210T201251 comment=NONE
channel ch2: backup set complete, elapsed time: 00:00:26)
including current control file in backup set
channel ch1: starting piece 1 at 10-DEC-16
channel ch1: finished piece 1 at 10-DEC-16
piece handle=/opt/oracle/bakdatabase/1urn54ev_1_1 tag=TAG20161210T201251 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:01
Finished backup at 10-DEC-16
[laolv@centhost3 bakfromcenthost2]$ ll /opt/oracle/bakfromcenthost2/bakdatabase/1urn54ev_1_1
-rw-rw----. 1 laolv laolv 18055168 Dec 10 20:51 /opt/oracle/bakfromcenthost2/bakdatabase/1urn54ev_1_1

3)另外還需要建立目錄
/opt/oracle/oradata/orcl
/opt/oracle/fast_recovery_area/orcl,且oracle的安裝使用者具有讀寫許可權



4)恢復控制檔案

4.把資料庫開到mount狀態,修復資料檔案

--指定備份集,catalog start with '備份集目錄'

點選(此處)摺疊或開啟

  1. RMAN>
  2. RMAN> catalog start with '/opt/oracle/bakfromcenthost2/bakdatabase'; --重新指定備份集,catalog start with '備份集目錄'

  3. searching for all files that match the pattern /opt/oracle/bakfromcenthost2/bakdatabase

  4. List of Files Unknown to the Database
  5. =====================================
  6. File Name: /opt/oracle/bakfromcenthost2/bakdatabase/1orn54a4_1_1
  7. File Name: /opt/oracle/bakfromcenthost2/bakdatabase/1prn54a4_1_1
  8. File Name: /opt/oracle/bakfromcenthost2/bakdatabase/1trn54e5_1_1
  9. File Name: /opt/oracle/bakfromcenthost2/bakdatabase/1vrn54f4_1_1
  10. File Name: /opt/oracle/bakfromcenthost2/bakdatabase/1rrn54bq_1_1
  11. File Name: /opt/oracle/bakfromcenthost2/bakdatabase/1srn54e5_1_1
  12. File Name: /opt/oracle/bakfromcenthost2/bakdatabase/1qrn54bi_1_1
  13. File Name: /opt/oracle/bakfromcenthost2/bakdatabase/1urn54ev_1_1
  14. File Name: /opt/oracle/bakfromcenthost2/bakdatabase/1nrn54a1_1_1

  15. Do you really want to catalog the above files (enter YES or NO)? YES
  16. cataloging files...
  17. cataloging done

  18. List of Cataloged Files
  19. =======================
  20. File Name: /opt/oracle/bakfromcenthost2/bakdatabase/1orn54a4_1_1
  21. File Name: /opt/oracle/bakfromcenthost2/bakdatabase/1prn54a4_1_1
  22. File Name: /opt/oracle/bakfromcenthost2/bakdatabase/1trn54e5_1_1
  23. File Name: /opt/oracle/bakfromcenthost2/bakdatabase/1vrn54f4_1_1
  24. File Name: /opt/oracle/bakfromcenthost2/bakdatabase/1rrn54bq_1_1
  25. File Name: /opt/oracle/bakfromcenthost2/bakdatabase/1srn54e5_1_1
  26. File Name: /opt/oracle/bakfromcenthost2/bakdatabase/1qrn54bi_1_1
  27. File Name: /opt/oracle/bakfromcenthost2/bakdatabase/1urn54ev_1_1
  28. File Name: /opt/oracle/bakfromcenthost2/bakdatabase/1nrn54a1_1_1

  29. RMAN>
恢復資料庫

點選(此處)摺疊或開啟

  1. Starting restore at 10-DEC-16
  2. allocated channel: ORA_DISK_1
  3. channel ORA_DISK_1: SID=12 device type=DISK

  4. channel ORA_DISK_1: starting datafile backup set restore
  5. channel ORA_DISK_1: specifying datafile(s) to restore from backup set
  6. channel ORA_DISK_1: restoring datafile 00003 to /opt/oracle/oradata/orcl/sysaux01.dbf
  7. channel ORA_DISK_1: restoring datafile 00004 to /opt/oracle/oradata/orcl/undotbs01.dbf
  8. channel ORA_DISK_1: reading from backup piece /opt/oracle/bakfromcenthost2/bakdatabase/1orn54a4_1_1
  9. channel ORA_DISK_1: piece handle=/opt/oracle/bakfromcenthost2/bakdatabase/1orn54a4_1_1 tag=TAG20161210T201251
  10. channel ORA_DISK_1: restored backup piece 1
  11. channel ORA_DISK_1: restore complete, elapsed time: 00:04:45
  12. channel ORA_DISK_1: starting datafile backup set restore
  13. channel ORA_DISK_1: specifying datafile(s) to restore from backup set
  14. channel ORA_DISK_1: restoring datafile 00010 to /opt/oracle/oradata/orcl/pdborcl/SAMPLE_SCHEMA_users01.dbf
  15. channel ORA_DISK_1: restoring datafile 00011 to /opt/oracle/oradata/orcl/pdborcl/example01.dbf
  16. channel ORA_DISK_1: reading from backup piece /opt/oracle/bakfromcenthost2/bakdatabase/1prn54a4_1_1
  17. channel ORA_DISK_1: ORA-19870: error while restoring backup piece /opt/oracle/bakfromcenthost2/bakdatabase/1prn54a4_1_1
  18. ORA-19504: failed to create file "/opt/oracle/oradata/orcl/pdborcl/example01.dbf"
  19. ORA-27040: file create error, unable to create file
  20. Linux-x86_64 Error: 2: No such file or directory
  21. Additional information: 1

  22. channel ORA_DISK_1: starting datafile backup set restore
  23. channel ORA_DISK_1: specifying datafile(s) to restore from backup set
  24. channel ORA_DISK_1: restoring datafile 00008 to /opt/oracle/oradata/orcl/pdborcl/system01.dbf
  25. channel ORA_DISK_1: restoring datafile 00009 to /opt/oracle/oradata/orcl/pdborcl/sysaux01.dbf
  26. channel ORA_DISK_1: reading from backup piece /opt/oracle/bakfromcenthost2/bakdatabase/1qrn54bi_1_1
  27. channel ORA_DISK_1: ORA-19870: error while restoring backup piece /opt/oracle/bakfromcenthost2/bakdatabase/1qrn54bi_1_1
  28. ORA-19504: failed to create file "/opt/oracle/oradata/orcl/pdborcl/sysaux01.dbf"
  29. ORA-27040: file create error, unable to create file
  30. Linux-x86_64 Error: 2: No such file or directory
  31. Additional information: 1

  32. channel ORA_DISK_1: starting datafile backup set restore
  33. channel ORA_DISK_1: specifying datafile(s) to restore from backup set
  34. channel ORA_DISK_1: restoring datafile 00001 to /opt/oracle/oradata/orcl/system01.dbf
  35. channel ORA_DISK_1: restoring datafile 00006 to /opt/oracle/oradata/orcl/users01.dbf
  36. channel ORA_DISK_1: reading from backup piece /opt/oracle/bakfromcenthost2/bakdatabase/1rrn54bq_1_1
  37. channel ORA_DISK_1: piece handle=/opt/oracle/bakfromcenthost2/bakdatabase/1rrn54bq_1_1 tag=TAG20161210T201251
  38. channel ORA_DISK_1: restored backup piece 1
  39. channel ORA_DISK_1: restore complete, elapsed time: 00:05:03
  40. channel ORA_DISK_1: starting datafile backup set restore
  41. channel ORA_DISK_1: specifying datafile(s) to restore from backup set
  42. channel ORA_DISK_1: restoring datafile 00005 to /opt/oracle/oradata/orcl/pdbseed/system01.dbf
  43. channel ORA_DISK_1: reading from backup piece /opt/oracle/bakfromcenthost2/bakdatabase/1trn54e5_1_1
  44. channel ORA_DISK_1: ORA-19870: error while restoring backup piece /opt/oracle/bakfromcenthost2/bakdatabase/1trn54e5_1_1
  45. ORA-19504: failed to create file "/opt/oracle/oradata/orcl/pdbseed/system01.dbf"
  46. ORA-27040: file create error, unable to create file
  47. Linux-x86_64 Error: 2: No such file or directory
  48. Additional information: 1

  49. channel ORA_DISK_1: starting datafile backup set restore
  50. channel ORA_DISK_1: specifying datafile(s) to restore from backup set
  51. channel ORA_DISK_1: restoring datafile 00007 to /opt/oracle/oradata/orcl/pdbseed/sysaux01.dbf
  52. channel ORA_DISK_1: reading from backup piece /opt/oracle/bakfromcenthost2/bakdatabase/1srn54e5_1_1
  53. channel ORA_DISK_1: ORA-19870: error while restoring backup piece /opt/oracle/bakfromcenthost2/bakdatabase/1srn54e5_1_1
  54. ORA-19504: failed to create file "/opt/oracle/oradata/orcl/pdbseed/sysaux01.dbf"
  55. ORA-27040: file create error, unable to create file
  56. Linux-x86_64 Error: 2: No such file or directory
  57. Additional information: 1

  58. failover to previous backup

  59. RMAN-00571: ===========================================================
  60. RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
  61. RMAN-00571: ===========================================================
  62. RMAN-03002: failure of restore command at 12/10/2016 22:49:20
  63. RMAN-06026: some targets not found - aborting restore
  64. RMAN-06023: no backup or copy of datafile 11 found to restore
  65. RMAN-06023: no backup or copy of datafile 10 found to restore
  66. RMAN-06023: no backup or copy of datafile 9 found to restore
  67. RMAN-06023: no backup or copy of datafile 8 found to restore
  68. RMAN-06023: no backup or copy of datafile 7 found to restore
  69. RMAN-06023: no backup or copy of datafile 5 found to restore

  70. RMAN>
根據源環境,在目標端建立對應的目錄


重新恢復資料檔案

點選(此處)摺疊或開啟

  1. RMAN> restore database;

  2. Starting restore at 10-DEC-16
  3. using channel ORA_DISK_1

  4. skipping datafile 1; already restored to file /opt/oracle/oradata/orcl/system01.dbf
  5. skipping datafile 6; already restored to file /opt/oracle/oradata/orcl/users01.dbf
  6. skipping datafile 3; already restored to file /opt/oracle/oradata/orcl/sysaux01.dbf
  7. skipping datafile 4; already restored to file /opt/oracle/oradata/orcl/undotbs01.dbf
  8. channel ORA_DISK_1: starting datafile backup set restore
  9. channel ORA_DISK_1: specifying datafile(s) to restore from backup set
  10. channel ORA_DISK_1: restoring datafile 00010 to /opt/oracle/oradata/orcl/pdborcl/SAMPLE_SCHEMA_users01.dbf
  11. channel ORA_DISK_1: restoring datafile 00011 to /opt/oracle/oradata/orcl/pdborcl/example01.dbf
  12. channel ORA_DISK_1: reading from backup piece /opt/oracle/bakfromcenthost2/bakdatabase/1prn54a4_1_1
  13. channel ORA_DISK_1: piece handle=/opt/oracle/bakfromcenthost2/bakdatabase/1prn54a4_1_1 tag=TAG20161210T201251
  14. channel ORA_DISK_1: restored backup piece 1
  15. channel ORA_DISK_1: restore complete, elapsed time: 00:00:25
  16. channel ORA_DISK_1: starting datafile backup set restore
  17. channel ORA_DISK_1: specifying datafile(s) to restore from backup set
  18. channel ORA_DISK_1: restoring datafile 00008 to /opt/oracle/oradata/orcl/pdborcl/system01.dbf
  19. channel ORA_DISK_1: restoring datafile 00009 to /opt/oracle/oradata/orcl/pdborcl/sysaux01.dbf
  20. channel ORA_DISK_1: reading from backup piece /opt/oracle/bakfromcenthost2/bakdatabase/1qrn54bi_1_1
  21. channel ORA_DISK_1: piece handle=/opt/oracle/bakfromcenthost2/bakdatabase/1qrn54bi_1_1 tag=TAG20161210T201251
  22. channel ORA_DISK_1: restored backup piece 1
  23. channel ORA_DISK_1: restore complete, elapsed time: 00:00:25
  24. channel ORA_DISK_1: starting datafile backup set restore
  25. channel ORA_DISK_1: specifying datafile(s) to restore from backup set
  26. channel ORA_DISK_1: restoring datafile 00005 to /opt/oracle/oradata/orcl/pdbseed/system01.dbf
  27. channel ORA_DISK_1: reading from backup piece /opt/oracle/bakfromcenthost2/bakdatabase/1trn54e5_1_1
  28. channel ORA_DISK_1: piece handle=/opt/oracle/bakfromcenthost2/bakdatabase/1trn54e5_1_1 tag=TAG20161210T201251
  29. channel ORA_DISK_1: restored backup piece 1
  30. channel ORA_DISK_1: restore complete, elapsed time: 00:00:07
  31. channel ORA_DISK_1: starting datafile backup set restore
  32. channel ORA_DISK_1: specifying datafile(s) to restore from backup set
  33. channel ORA_DISK_1: restoring datafile 00007 to /opt/oracle/oradata/orcl/pdbseed/sysaux01.dbf
  34. channel ORA_DISK_1: reading from backup piece /opt/oracle/bakfromcenthost2/bakdatabase/1srn54e5_1_1
  35. channel ORA_DISK_1: piece handle=/opt/oracle/bakfromcenthost2/bakdatabase/1srn54e5_1_1 tag=TAG20161210T201251
  36. channel ORA_DISK_1: restored backup piece 1
  37. channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
  38. Finished restore at 10-DEC-16

  39. RMAN>

5. 放置線上日誌檔案redo.log,然後恢復資料庫

將我前面從源目標資料庫複製的STATUS=CURRENT的線上日誌檔案redo01.log 放到 目的目錄下



6. 啟動資料庫例項orcl

[laolv@centhost3 admin]$ echo $ORACLE_SID
orcl
[laolv@centhost3 admin]$ sqlplus / as sysdba
SQL*Plus: Release 12.1.0.2.0 Production on Sat Dec 10 23:21:39 2016
Copyright (c) 1982, 2014, Oracle.  All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> shutdown immediate;
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down
SQL> startup;
ORACLE instance started.
Total System Global Area 1493172224 bytes
Fixed Size    2924592 bytes
Variable Size  486543312 bytes
Database Buffers  989855744 bytes
Redo Buffers   13848576 bytes
Database mounted.
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
SQL> select * from dual;   
ADDR       INDX    INST_ID   CON_ID D
---------------- ---------- ---------- ---------- -
000000000E07DD5C  0     1 0 X
SQL> desc dba_users;
ERROR:
ORA-04043: object dba_users does not exist

SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
SQL> alter database open NORESETLOGS;
alter database open NORESETLOGS
*
ERROR at line 1:
ORA-01588: must use RESETLOGS option for database open
SQL> alter database open RESETLOGS;
Database altered.
SQL>
SQL> desc dba_users;
 Name   Null?    Type
 ----------------------------------------- -------- ----------------------------
 USERNAME   NOT NULL VARCHAR2(128)
 USER_ID   NOT NULL NUMBER
 PASSWORD    VARCHAR2(4000)
 ACCOUNT_STATUS   NOT NULL VARCHAR2(32)
 LOCK_DATE    DATE
 EXPIRY_DATE    DATE
 DEFAULT_TABLESPACE   NOT NULL VARCHAR2(30)
 TEMPORARY_TABLESPACE   NOT NULL VARCHAR2(30)
 CREATED   NOT NULL DATE
 PROFILE   NOT NULL VARCHAR2(128)
 INITIAL_RSRC_CONSUMER_GROUP    VARCHAR2(128)
 EXTERNAL_NAME    VARCHAR2(4000)
 PASSWORD_VERSIONS    VARCHAR2(12)
 EDITIONS_ENABLED    VARCHAR2(1)
 AUTHENTICATION_TYPE    VARCHAR2(8)
 PROXY_ONLY_CONNECT    VARCHAR2(1)
 COMMON    VARCHAR2(3)
 LAST_LOGIN    TIMESTAMP(9) WITH TIME ZONE
 ORACLE_MAINTAINED    VARCHAR2(1)

五.測試

tnsnames.ora和listener.ora檔案的資訊


可是資料庫例項orcl就是不能成功向B機本地的監聽器,動態註冊資料庫例項服務
[laolv@centhost3 admin]$ lsnrctl status
LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 10-DEC-2016 23:14:50
Copyright (c) 1991, 2014, Oracle.  All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=centhost3)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.1.0.2.0 - Production
Start Date                06-DEC-2016 22:34:05
Uptime                    4 days 0 hr. 40 min. 45 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /opt/oracle/product/12.1.0/dbhome_1/network/admin/listener.ora
Listener Log File         /opt/oracle/diag/tnslsnr/centhost3/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=centhost3)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
The listener supports no services
The command completed successfully

資料庫例項服務動態註冊:
資料庫例項服務動態註冊的動作是監聽器所在主機上資料庫例項完成。
動態註冊是Oracle上一個不能關閉的功能。例項的background process PMON,每隔一段時間(一到兩分鐘)就會將例項的引數資訊註冊到監聽器上,實現動態註冊。
註冊的資訊是資料庫引數service_names和instance_name。可以透過Show Parameter命令檢視。

一般資料庫在建立的時候,這兩個引數都是已經設定好的,不會輕易的發生變化。
如果instance_name引數沒設定,則系統會取引數db_name作為例項名稱返回。
如果service_names沒設定,則會將db_name和db_domain兩個引數組合成服務名實現註冊。

值得注意的一個問題是,service_names引數是一個可以指定多個服務名稱的引數,以逗號分隔。也就是說,一個Oracle例項時可以同時作為多個服務名向外提供服務的。Service_name是Oracle在新近版本中提出,替代SID_NAME的概念。使用Service的指定方式,多個Oracle例項就可以統一提供一致的資料訪問服務(也就是RAC)。


instance_name和service_names引數資訊都對,還是動態註冊不了資料庫服務!
[laolv@centhost3 bakfromcenthost2]$ tailf /opt/oracle/diag/tnslsnr/centhost3/listener/trace/listener.log --沒有service_register和service_update動作


原因:資料庫例項的PMON去向監聽動態註冊資料庫服務時,依據的簡體器是local_listener指定的監聽器,而解析listener引數指定的監聽器依據的是tnsnames.ora檔案。
參考了:http://blog.sina.com.cn/s/blog_4bde435b01015jnf.html Oracle引數—local_listener引數作用



向tnsnames.ora加入LISTENER_ORCL後,重新alter system register

點選(此處)摺疊或開啟

  1. export ORACLE_SID=orcl
  2. sqlplus / as sysdba
  3. SQL>alter system register
照樣
[laolv@centhost3 admin]$ lsnrctl stat LISTENER
LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 11-DEC-2016 15:08:59
Copyright (c) 1991, 2014, Oracle.  All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=centhost3)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.1.0.2.0 - Production
Start Date                11-DEC-2016 13:44:10
Uptime                    0 days 1 hr. 24 min. 49 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /opt/oracle/product/12.1.0/dbhome_1/network/admin/listener.ora
Listener Log File         /opt/oracle/diag/tnslsnr/centhost3/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=centhost3)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
The listener supports no services
The command completed successfully

重啟資料庫例項,並在另外的視窗[laolv@centhost3 bakfromcenthost2]$ tailf /opt/oracle/diag/tnslsnr/centhost3/listener/trace/listener.log


可以看到service_register * orcl 和service_update * orcl了
必須要重啟,在tnsnames.ora中新增了LISTENR_ORCL解析記錄,alter system register都不會在listner.log中看到註冊資訊;  
說明=>LISTENR_ORCL解析記錄,只是在資料庫例項啟動的時候才使用到的/生效的

登入orcl,查詢表t1,進行測試:





來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25097694/viewspace-2130241/,如需轉載,請註明出處,否則將追究法律責任。

相關文章