Oracle 12c DataGuard 出现GAP 增量恢复的处理方法

前端之家收集整理的这篇文章主要介绍了Oracle 12c DataGuard 出现GAP 增量恢复的处理方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

周末不忘写一篇文档!

DG出现故障基本上有两个方法,一个是全量备份恢复,一个是增量备份恢复,这里我们测试增量备份恢复方法

  1. 一、环境描述
  2. Oracle 12c ASM
  3. RHEL 7.0
  4. 单实例到单实例的DataGuard
  1. 二、问题描述
  2. 出现GAP
  3.  
  4. sql> select * from v$archive_gap;
  5.  
  6. THREAD# LOW_SEQUENCE# HIGH_SEQUENCE# CON_ID
  7. ---------- ------------- -------------- ----------
  8. 1 223 225 1
  9.  
  10. sql>
  11.  
  12.  
  13. sql> select message from v$dataguard_status;
  14.  
  15. MESSAGE
  16. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  17. ARC0: Archival started
  18. ARC1: Archival started
  19. ARC2: Archival started
  20. ARC1: Becoming the 'no FAL' ARCH
  21. ARC2: Becoming the heartbeat ARCH
  22. ARC2: Becoming the active heartbeat ARCH
  23. ARC3: Archival started
  24. Attempt to start background Managed Standby Recovery process
  25. MRP0: Background Managed Standby Recovery process started
  26. Primary database is in MAXIMUM PERFORMANCE mode
  27. RFS[1]: Assigned to RFS process (PID:3973)
  28.  
  29. MESSAGE
  30. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  31. RFS[2]: Assigned to RFS process (PID:3984)
  32. RFS[3]: Assigned to RFS process (PID:3986)
  33. ARC3: Beginning to archive thread 1 sequence 222 (7930074-7930162)
  34. RFS[4]: Assigned to RFS process (PID:3988)
  35. ARC3: Completed archiving thread 1 sequence 222 (0-0)
  36. Managed Standby Recovery starting Real Time Apply
  37. Media Recovery Log +DATADG/arch/log_1_222_961866198_585bafa7.arc
  38. Media Recovery Waiting for thread 1 sequence 223
  39. Fetching gap sequence in thread 1,gap sequence 223-225
  40.  
  41. 20 rows selected.
  42.  
  43. sql>
  44.  
  45.  
  46. sql> select name,value from v$dataguard_stats;
  47.  
  48. NAME VALUE
  49. -------------------------------- ----------------------------------------------------------------
  50. transport lag +00 00:07:57
  51. apply lag
  52. apply finish time
  53. estimated startup time 16
  54.  
  55. sql>
  1. 三、处理过程
  2.  
  3. 1、备库执行,查看最新scn,取最小值
  4. sql> col current_scn for 999999999
  5. sql> select current_scn from v$database;
  6.  
  7. CURRENT_SCN
  8. -----------
  9. 7930161
  10.  
  11. sql> select min(f.checkpoint_change#) from v$datafile_header f,v$datafile d where f.file# =d.file# and d.enabled != 'READ ONLY' ;
  12.  
  13. MIN(F.CHECKPOINT_CHANGE#)
  14. -------------------------
  15.  
  16.  
  17. 2.主库执行
  18.  
  19. --查看是否有新创建的数据文件
  20. sql> select FILE#,to_char(CREATION_TIME,'yyyy-mm-dd hh24:mi:ss') CREATION_TIME,STATUS,LAST_TIME,name from v$datafile where CREATION_CHANGE#>7930161;
  21.  
  22. no rows selected
  23.  
  24. 3.主库增量备份数据文件和控制文件
  25.  
  26. run
  27. {
  28. allocate channel t1 type disk;
  29. allocate channel t2 type disk;
  30. BACKUP as compressed backupset INCREMENTAL FROM SCN 7930161 DATABASE FORMAT '/home/oracle/dg_%U' tag 'FORSTANDBY';
  31. release channel t1;
  32. release channel t2;
  33. }
  34.  
  35. ALTER DATABASE CREATE standby controlfile AS '/home/oracle/standby_20171217.ctl';
  36.  
  37. RMAN>
  38.  
  39. RMAN> run
  40. 2> {
  41. 3> allocate channel t1 type disk;
  42. 4> allocate channel t2 type disk;
  43. 5> BACKUP as compressed backupset INCREMENTAL FROM SCN 7930161 DATABASE FORMAT '/home/oracle/dg_%U' tag 'FORSTANDBY';
  44. 6> release channel t1;
  45. 7> release channel t2;
  46. 8> }
  47.  
  48. allocated channel: t1
  49. channel t1: SID=76 device type=DISK
  50.  
  51. allocated channel: t2
  52. channel t2: SID=56 device type=DISK
  53.  
  54. Starting backup at 17-DEC-2017 08:07:54
  55. channel t1: starting compressed full datafile backup set
  56. channel t1: specifying datafile(s) in backup set
  57. input datafile file number=00001 name=+DATADG/ORCL/DATAFILE/system.258.954622821
  58. input datafile file number=00006 name=+DATADG/ORCL/DATAFILE/users.259.954622957
  59. channel t1: starting piece 1 at 17-DEC-2017 08:07:55
  60. channel t2: starting compressed full datafile backup set
  61. channel t2: specifying datafile(s) in backup set
  62. input datafile file number=00003 name=+DATADG/ORCL/DATAFILE/sysaux.257.954622639
  63. input datafile file number=00004 name=+DATADG/ORCL/DATAFILE/undotbs1.260.954622959
  64. channel t2: starting piece 1 at 17-DEC-2017 08:07:55
  65. channel t2: finished piece 1 at 17-DEC-2017 08:08:10
  66. piece handle=/home/oracle/dg_0msmb3ur_1_1 tag=FORSTANDBY comment=NONE
  67. channel t2: backup set complete,elapsed time: 00:00:15
  68. channel t2: starting compressed full datafile backup set
  69. channel t2: specifying datafile(s) in backup set
  70. including current control file in backup set
  71. channel t2: starting piece 1 at 17-DEC-2017 08:08:13
  72. channel t2: finished piece 1 at 17-DEC-2017 08:08:14
  73. piece handle=/home/oracle/dg_0nsmb3va_1_1 tag=FORSTANDBY comment=NONE
  74. channel t2: backup set complete,elapsed time: 00:00:01
  75. channel t1: finished piece 1 at 17-DEC-2017 08:08:38
  76. piece handle=/home/oracle/dg_0lsmb3ur_1_1 tag=FORSTANDBY comment=NONE
  77. channel t1: backup set complete,elapsed time: 00:00:43
  78. Finished backup at 17-DEC-2017 08:08:38
  79.  
  80. released channel: t1
  81.  
  82. released channel: t2
  83.  
  84. RMAN> ALTER DATABASE CREATE standby controlfile AS '/home/oracle/standby_20171217.ctl';
  85.  
  86. Statement processed
  87.  
  88. RMAN> exit
  89.  
  90.  
  91. Recovery Manager complete.
  92. <roidb01:orcl:/home/oracle>$ls
  93. dg_0lsmb3ur_1_1 dg_0msmb3ur_1_1 dg_0nsmb3va_1_1 standby_20171217.ctl
  94. <roidb01:orcl:/home/oracle>$scp /home/oracle/* oracle@192.168.1.112:/home/oracle
  95. dg_0lsmb3ur_1_1 100% 472KB 472.0KB/s 00:00
  96. dg_0msmb3ur_1_1 100% 1640KB 1.6MB/s 00:00
  97. dg_0nsmb3va_1_1 100% 1136KB 1.1MB/s 00:00
  98. standby_20171217.ctl 100% 11MB 11.1MB/s 00:00
  99. <roidb01:orcl:/home/oracle>$
  100.  
  101. 4.备库执行恢复数据库
  102.  
  103. sqlplus / as sysdba
  104. startup mount;
  105.  
  106. RMAN> backup current controlfile format '/home/oracle/standby_1217.ctl';
  107.  
  108. Starting backup at 17-DEC-2017 08:52:45
  109. using channel ORA_DISK_1
  110. channel ORA_DISK_1: starting full datafile backup set
  111. channel ORA_DISK_1: specifying datafile(s) in backup set
  112. including current control file in backup set
  113. channel ORA_DISK_1: starting piece 1 at 17-DEC-2017 08:52:46
  114. channel ORA_DISK_1: finished piece 1 at 17-DEC-2017 08:52:47
  115. piece handle=/home/oracle/standby_1217.ctl tag=TAG20171217T085245 comment=NONE
  116. channel ORA_DISK_1: backup set complete,elapsed time: 00:00:01
  117. Finished backup at 17-DEC-2017 08:52:47
  118.  
  119. RMAN> catalog start with '/home/oracle';
  120.  
  121. searching for all files that match the pattern /home/oracle
  122. ....省略...........
  123.  
  124. 报错
  125. RMAN> recover database noredo;
  126.  
  127. Starting recover at 17-DEC-2017 08:57:40
  128. using channel ORA_DISK_1
  129. channel ORA_DISK_1: starting incremental datafile backup set restore
  130. channel ORA_DISK_1: specifying datafile(s) to restore from backup set
  131. destination for restore of datafile 00001: +DATADG/ORCLDG/DATAFILE/system.258.954626559
  132. destination for restore of datafile 00006: +DATADG/ORCLDG/DATAFILE/users.261.954626717
  133. channel ORA_DISK_1: reading from backup piece /home/oracle/dg_0lsmb3ur_1_1
  134. RMAN-00571: ===========================================================
  135. RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
  136. RMAN-00571: ===========================================================
  137. RMAN-03002: failure of recover command at 12/17/2017 08:57:41
  138. ORA-19870: error while restoring backup piece /home/oracle/dg_0lsmb3ur_1_1
  139. ORA-19573: cannot obtain exclusive enqueue for datafile 1
  140. 解决
  141. --备库取消实时同步进程
  142. sql> alter database recover managed standby database cancel;
  143.  
  144. Database altered.
  145.  
  146.  
  147.  
  148. 重新执行恢复
  149. RMAN> recover database noredo;
  150.  
  151. Starting recover at 17-DEC-2017 08:58:23
  152. using channel ORA_DISK_1
  153. channel ORA_DISK_1: starting incremental datafile backup set restore
  154. channel ORA_DISK_1: specifying datafile(s) to restore from backup set
  155. destination for restore of datafile 00001: +DATADG/ORCLDG/DATAFILE/system.258.954626559
  156. destination for restore of datafile 00006: +DATADG/ORCLDG/DATAFILE/users.261.954626717
  157. channel ORA_DISK_1: reading from backup piece /home/oracle/dg_0lsmb3ur_1_1
  158. channel ORA_DISK_1: piece handle=/home/oracle/dg_0lsmb3ur_1_1 tag=FORSTANDBY
  159. channel ORA_DISK_1: restored backup piece 1
  160. channel ORA_DISK_1: restore complete,elapsed time: 00:00:01
  161. channel ORA_DISK_1: starting incremental datafile backup set restore
  162. channel ORA_DISK_1: specifying datafile(s) to restore from backup set
  163. destination for restore of datafile 00003: +DATADG/ORCLDG/DATAFILE/sysaux.259.954626615
  164. destination for restore of datafile 00004: +DATADG/ORCLDG/DATAFILE/undotbs1.260.954626701
  165. channel ORA_DISK_1: reading from backup piece /home/oracle/dg_0msmb3ur_1_1
  166. channel ORA_DISK_1: piece handle=/home/oracle/dg_0msmb3ur_1_1 tag=FORSTANDBY
  167. channel ORA_DISK_1: restored backup piece 1
  168. channel ORA_DISK_1: restore complete,elapsed time: 00:00:01
  169.  
  170. Finished recover at 17-DEC-2017 08:58:26
  171.  
  172. RMAN>
  173.  
  174. 备库恢复完数据库后,备库使用当前的控制文件收集备库的数据文件路径信息
  175. sql> col name for a50
  176. sql> select file#,name from v$datafile;
  177.  
  178. FILE# NAME
  179. ---------- --------------------------------------------------
  180. 1 +DATADG/ORCLDG/DATAFILE/system.258.954626559
  181. 3 +DATADG/ORCLDG/DATAFILE/sysaux.259.954626615
  182. 4 +DATADG/ORCLDG/DATAFILE/undotbs1.260.954626701
  183. 6 +DATADG/ORCLDG/DATAFILE/users.261.954626717
  184.  
  185. sql>
  186.  
  187. 恢复控制文件
  188. RMAN> shutdown immediate;
  189.  
  190. database dismounted
  191. Oracle instance shut down
  192.  
  193. RMAN> exit
  194.  
  195.  
  196. Recovery Manager complete.
  197. <roidb02:orcldg:/home/oracle>$ls
  198. dg_0lsmb3ur_1_1 dg_0msmb3ur_1_1 dg_0nsmb3va_1_1 standby_1217.ctl standby_20171217.ctl
  199. <roidb02:orcldg:/home/oracle>$ls -l
  200. total 25056
  201. -rw-r----- 1 oracle oinstall 483328 Dec 17 08:09 dg_0lsmb3ur_1_1
  202. -rw-r----- 1 oracle oinstall 1679360 Dec 17 08:09 dg_0msmb3ur_1_1
  203. -rw-r----- 1 oracle oinstall 1163264 Dec 17 08:09 dg_0nsmb3va_1_1
  204. -rw-r----- 1 oracle asmadmin 10682368 Dec 17 08:52 standby_1217.ctl
  205. -rw-r----- 1 oracle oinstall 11649024 Dec 17 08:09 standby_20171217.ctl
  206. <roidb02:orcldg:/home/oracle>$rman target /
  207.  
  208. Recovery Manager: Release 12.1.0.2.0 - Production on Sun Dec 17 09:06:25 2017
  209.  
  210. Copyright (c) 1982,2014,Oracle and/or its affiliates. All rights reserved.
  211.  
  212. connected to target database (not started)
  213.  
  214. RMAN> startup nomount;
  215.  
  216. Oracle instance started
  217.  
  218. Total System Global Area 1241513984 bytes
  219.  
  220. Fixed Size 2923872 bytes
  221. Variable Size 452985504 bytes
  222. Database Buffers 771751936 bytes
  223. Redo Buffers 13852672 bytes
  224.  
  225. --恢复控制文件
  226. RMAN> restore controlfile from '/home/oracle/standby_20171217.ctl';
  227.  
  228. Starting restore at 17-DEC-2017 09:07:06
  229. using target database control file instead of recovery catalog
  230. allocated channel: ORA_DISK_1
  231. channel ORA_DISK_1: SID=1 device type=DISK
  232.  
  233. channel ORA_DISK_1: copied control file copy
  234. output file name=+DATADG/orcldg/standby.ctl
  235. Finished restore at 17-DEC-2017 09:07:07
  236.  
  237. --加载控制文件
  238. RMAN> alter database mount;
  239.  
  240. Statement processed
  241. released channel: ORA_DISK_1
  242.  
  243. RMAN>
  244.  
  245. --注册数据文件
  246. RMAN> catalog start with '+DATADG/ORCLDG/DATAFILE/';
  247.  
  248. Starting implicit crosscheck backup at 17-DEC-2017 09:09:16
  249. allocated channel: ORA_DISK_1
  250. channel ORA_DISK_1: SID=46 device type=DISK
  251. Crosschecked 11 objects
  252. Finished implicit crosscheck backup at 17-DEC-2017 09:09:17
  253.  
  254. Starting implicit crosscheck copy at 17-DEC-2017 09:09:17
  255. using channel ORA_DISK_1
  256. Finished implicit crosscheck copy at 17-DEC-2017 09:09:17
  257.  
  258. searching for all files in the recovery area
  259. cataloging files...
  260. cataloging done
  261.  
  262. List of Cataloged Files
  263. =======================
  264. ...省略.....
  265. File Name: +DATADG/ORCLDG/ARCHIVELOG/2017_11_29/thread_1_seq_273.314.961336961
  266. File Name: +DATADG/ORCLDG/DATAFILE/system.258.954626559
  267. File Name: +DATADG/ORCLDG/DATAFILE/sysaux.259.954626615
  268. File Name: +DATADG/ORCLDG/DATAFILE/undotbs1.260.954626701
  269. File Name: +DATADG/ORCLDG/DATAFILE/users.261.954626717
  270.  
  271. searching for all files that match the pattern +DATADG/ORCLDG/DATAFILE/
  272. no files found to be unknown to the database
  273.  
  274.  
  275.  
  276. RMAN> SWITCH DATABASE TO COPY;
  277.  
  278. datafile 1 switched to datafile copy "+DATADG/ORCLDG/DATAFILE/system.258.954626559"
  279. datafile 3 switched to datafile copy "+DATADG/ORCLDG/DATAFILE/sysaux.259.954626615"
  280. datafile 4 switched to datafile copy "+DATADG/ORCLDG/DATAFILE/undotbs1.260.954626701"
  281. datafile 6 switched to datafile copy "+DATADG/ORCLDG/DATAFILE/users.261.954626717"
  282.  
  283. RMAN>
  284. RMAN> alter database recover managed standby database using current logfile disconnect from session;
  285.  
  286. Statement processed
  287.  
  288.  
  289. 日志有报错
  290. Errors in file /u01/app/oracle/diag/rdbms/orcldg/orcldg/trace/orcldg_ora_22731.trc:
  291. ORA-00313: open Failed for members of log group 14 of thread 1
  292. ORA-00312: online log 14 thread 1: '+DATADG/ORCL/ONLINELOG/group_14.270.954625683'
  293. ORA-17503: ksfdopn:2 Failed to open file +DATADG/ORCL/ONLINELOG/group_14.270.954625683
  294. ORA-15173: entry 'ORCL' does not exist in directory '/'
  295. 2017-12-17 11:45:52.647000 +08:00
  296. Completed: alter database clear logfile group 14
  297. 2017-12-17 11:46:02.748000 +08:00
  298. alter database clear logfile group 15
  299.  
  300. 处理过程
  301. sql> select group# from v$standby_log;
  302.  
  303. GROUP#
  304. ----------
  305. 11
  306. 12
  307. 13
  308. 14
  309.  
  310.  
  311. --初始化standby redo log
  312. sql> alter database recover managed standby database cancel;
  313.  
  314. Database altered.
  315.  
  316. sql> alter database clear logfile group 11;
  317.  
  318. Database altered.
  319.  
  320. sql> alter database clear logfile group 12;
  321.  
  322. Database altered.
  323.  
  324. sql> alter database clear logfile group 13;
  325.  
  326. Database altered.
  327.  
  328. sql> alter database clear logfile group 14;
  329.  
  330. Database altered.
  331.  
  332. --启动实时应用
  333. sql> alter database recover managed standby database using current logfile disconnect from session;
  334.  
  335. Database altered.
  336.  
  337.  
  338. 5.验证
  339. DGMGRL> show configuration;
  340.  
  341. Configuration - dg_config
  342.  
  343. Protection Mode: MaxPerformance
  344. Members:
  345. orcl - Primary database
  346. orcldg - Physical standby database
  347.  
  348. Fast-Start Failover: DISABLED
  349.  
  350. Configuration Status:
  351. SUCCESS (status updated 57 seconds ago)
  352.  
  353. DGMGRL>

猜你在找的Oracle相关文章