ITPub博客

首页 > 数据库 > Oracle > 使用RMAN进行Oracle数据库迁移

使用RMAN进行Oracle数据库迁移

原创 Oracle 作者:forrest_itpub 时间:2016-12-11 17:34:42 0 删除 编辑
参考了: 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博客 ” ,链接:https://blog.itpub.net/25097694/viewspace-2130241/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: ping命令
请登录后发表评论 登录
全部评论

注册时间:2010-12-17

  • 博文量
    15
  • 访问量
    19246