• Oracle-通过(RECOVER STANDBY DATABASE FROM SERVICE)方式修复DataGuard


    前言:

    Oracle在18c对(RESTORE/RECOVER ...FROM SERVICE)功能进行了加强,推出了(RECOVER STANDBY DATABASE ... FROM SERVICE)通过网络服务直接增量恢复备库数据,这个新特性也大大简化了DataGuard主备的问题修复。

    修复主备gap

    1 当前备库缺失47-55个归档,并且没有归档日志备

    1. SQL> select open_mode,database_role from v$database;
    2. OPEN_MODE DATABASE_ROLE
    3. -------------------- ----------------
    4. READ ONLY WITH APPLY PHYSICAL STANDBY
    5. SQL> select * from v$archive_gap;
    6. THREAD# LOW_SEQUENCE# HIGH_SEQUENCE# CON_ID
    7. ---------- ------------- -------------- ----------
    8. 1 47 55 1
    9. SQL>

    2 关闭mrp进程

    1. alter database recover managed standby database cancel;
    2. ---注意在数据库open的时候,要把mrp进程关闭,否则会出现以下错误
    3. RMAN-00571: ===========================================================
    4. RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
    5. RMAN-00571: ===========================================================
    6. RMAN-03002: failure of recover command at 11/01/2022 17:35:51
    7. RMAN-05150: Managed Recovery Process must be disabled before running RECOVER STANDBY DATABASE.

    3 通过from service 进行recover的方式恢复

    1. rman target sys/oracle
    2. run
    3. {
    4. allocate channel c1 type disk connect '/@testdg';
    5. allocate channel c2 type disk connect '/@testdg';
    6. allocate channel c3 type disk connect '/@testdg';
    7. allocate channel c4 type disk connect '/@testdg';
    8. recover standby database from service 'testdb' ;
    9. }

    4 恢复的步骤

    1. 1 终止并重新启动实例到mount
    2. License high water mark = 12
    3. 2022-11-01T17:38:11.813430+08:00
    4. USER(prelim) (ospid: 24653): terminating the instance
    5. 2022-11-01T17:38:12.826936+08:00
    6. Instance terminated by USER(prelim), pid = 24653
    7. 2022-11-01T17:38:16.129260+08:00
    8. Starting ORACLE instance (normal) (OS id: 24658)
    9. 2022-11-01T17:38:16.138029+08:00
    10. 2 set standby_file_management=manual
    11. 3 重新从主库恢复新的standby control
    12. 4 切换控制文件路径到实际路径
    13. 5 进行增量recover恢复
    14. 6 set standby_file_management=auto

    5 恢复日志

    1. using target database control file instead of recovery catalog
    2. allocated channel: c1
    3. channel c1: SID=34 device type=DISK
    4. allocated channel: c2
    5. channel c2: SID=270 device type=DISK
    6. allocated channel: c3
    7. channel c3: SID=35 device type=DISK
    8. allocated channel: c4
    9. channel c4: SID=266 device type=DISK
    10. Starting recover at 2022/11/01 17:38:10
    11. Oracle instance started
    12. Total System Global Area 1543500144 bytes
    13. Fixed Size 8896880 bytes
    14. Variable Size 889192448 bytes
    15. Database Buffers 637534208 bytes
    16. Redo Buffers 7876608 bytes
    17. contents of Memory Script:
    18. {
    19. restore standby controlfile from service 'testdb';
    20. alter database mount standby database;
    21. }
    22. executing Memory Script
    23. Starting restore at 2022/11/01 17:38:23
    24. allocated channel: ORA_DISK_1
    25. channel ORA_DISK_1: SID=253 device type=DISK
    26. channel ORA_DISK_1: starting datafile backup set restore
    27. channel ORA_DISK_1: using network backup set from service testdb
    28. channel ORA_DISK_1: restoring control file
    29. channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
    30. output file name=/u01/app/oracle/oradata/TESTDG/controlfile/control01.ctl
    31. Finished restore at 2022/11/01 17:38:26
    32. released channel: ORA_DISK_1
    33. Statement processed
    34. Executing: alter system set standby_file_management=manual
    35. contents of Memory Script:
    36. {
    37. set newname for tempfile 1 to
    38. "/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_temp_kp1q02wb_.tmp";
    39. switch tempfile all;
    40. set newname for datafile 1 to
    41. "/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_system_kp1phykz_.dbf";
    42. set newname for datafile 3 to
    43. "/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_sysaux_kp1phyo1_.dbf";
    44. set newname for datafile 4 to
    45. "/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_undotbs1_kp1phyt2_.dbf";
    46. set newname for datafile 7 to
    47. "/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_users_kp1phz14_.dbf";
    48. catalog datafilecopy "/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_system_kp1phykz_.dbf",
    49. "/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_sysaux_kp1phyo1_.dbf",
    50. "/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_undotbs1_kp1phyt2_.dbf",
    51. "/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_users_kp1phz14_.dbf";
    52. switch datafile all;
    53. }
    54. executing Memory Script
    55. executing command: SET NEWNAME
    56. renamed tempfile 1 to /u01/app/oracle/oradata/TESTDG/datafile/o1_mf_temp_kp1q02wb_.tmp in control file
    57. executing command: SET NEWNAME
    58. executing command: SET NEWNAME
    59. executing command: SET NEWNAME
    60. executing command: SET NEWNAME
    61. cataloged datafile copy
    62. datafile copy file name=/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_system_kp1phykz_.dbf RECID=1 STAMP=1119634711
    63. cataloged datafile copy
    64. datafile copy file name=/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_sysaux_kp1phyo1_.dbf RECID=2 STAMP=1119634711
    65. cataloged datafile copy
    66. datafile copy file name=/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_undotbs1_kp1phyt2_.dbf RECID=3 STAMP=1119634711
    67. cataloged datafile copy
    68. datafile copy file name=/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_users_kp1phz14_.dbf RECID=4 STAMP=1119634711
    69. datafile 1 switched to datafile copy
    70. input datafile copy RECID=1 STAMP=1119634711 file name=/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_system_kp1phykz_.dbf
    71. datafile 3 switched to datafile copy
    72. input datafile copy RECID=2 STAMP=1119634711 file name=/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_sysaux_kp1phyo1_.dbf
    73. datafile 4 switched to datafile copy
    74. input datafile copy RECID=3 STAMP=1119634711 file name=/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_undotbs1_kp1phyt2_.dbf
    75. datafile 7 switched to datafile copy
    76. input datafile copy RECID=4 STAMP=1119634711 file name=/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_users_kp1phz14_.dbf
    77. contents of Memory Script:
    78. {
    79. recover database from service 'testdb';
    80. }
    81. executing Memory Script
    82. Starting recover at 2022/11/01 17:38:31
    83. allocated channel: ORA_DISK_1
    84. channel ORA_DISK_1: SID=260 device type=DISK
    85. RMAN-06900: warning: unable to generate V$RMAN_STATUS or V$RMAN_OUTPUT row
    86. RMAN-06901: warning: disabling update of the V$RMAN_STATUS and V$RMAN_OUTPUT rows
    87. Oracle error from target database:
    88. ORA-19922: there is no parent row with id 0 and level 2
    89. channel ORA_DISK_1: starting incremental datafile backup set restore
    90. channel ORA_DISK_1: using network backup set from service testdb
    91. destination for restore of datafile 00001: /u01/app/oracle/oradata/TESTDG/datafile/o1_mf_system_kp1phykz_.dbf
    92. channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
    93. channel ORA_DISK_1: starting incremental datafile backup set restore
    94. channel ORA_DISK_1: using network backup set from service testdb
    95. destination for restore of datafile 00003: /u01/app/oracle/oradata/TESTDG/datafile/o1_mf_sysaux_kp1phyo1_.dbf
    96. channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
    97. channel ORA_DISK_1: starting incremental datafile backup set restore
    98. channel ORA_DISK_1: using network backup set from service testdb
    99. destination for restore of datafile 00004: /u01/app/oracle/oradata/TESTDG/datafile/o1_mf_undotbs1_kp1phyt2_.dbf
    100. channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
    101. channel ORA_DISK_1: starting incremental datafile backup set restore
    102. channel ORA_DISK_1: using network backup set from service testdb
    103. destination for restore of datafile 00007: /u01/app/oracle/oradata/TESTDG/datafile/o1_mf_users_kp1phz14_.dbf
    104. channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
    105. starting media recovery
    106. media recovery complete, elapsed time: 00:00:00
    107. Finished recover at 2022/11/01 17:38:39
    108. Executing: alter system set standby_file_management=auto
    109. Finished recover at 2022/11/01 17:38:39

    6 重建standby log

    1. ---因为standby log的路径是主库的,可能跟实际的不一致
    2. select 'alter database drop standby logfile group '||group#||';'
    3. from v$standby_log;
    4. alter database ADD standby logfile thread 1 group 21 ('/u01/app/oracle/oradata/TESTDG/onlinelog/redo01.log') size 200M ;
    5. alter database ADD standby logfile thread 1 group 22 ('/u01/app/oracle/oradata/TESTDG/onlinelog/redo02.log') size 200M ;
    6. alter database ADD standby logfile thread 1 group 23 ('/u01/app/oracle/oradata/TESTDG/onlinelog/redo03.log') size 200M ;
    7. alter database ADD standby logfile thread 1 group 24 ('/u01/app/oracle/oradata/TESTDG/onlinelog/redo04.log') size 200M ;

    7 启动数据库恢复同步

    1. alter database open read ONLY;
    2. alter database recover managed standby database using current logfile disconnect from session;

    修复备库数据文件坏块问题

    1 备库有时会遇到由于主库没有设置force logging导致的坏块问题

    1. Errors in file /u01/app/oracle/diag/rdbms/testdg/testdg/trace/testdg_ora_4978.trc (incident=10025):
    2. ORA-01578: ORACLE data block corrupted (file # 5, block # 368)
    3. ORA-01110: data file 5: '/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_tbs_test_kp27r5t8_.dbf'
    4. ORA-26040: Data block was loaded using the NOLOGGING option
    5. Incident details in: /u01/app/oracle/diag/rdbms/testdg/testdg/incident/incdir_10025/testdg_ora_4978_i10025.trc

    2 关闭mrp进程

    alter database recover managed standby database cancel;

    3 将坏块问题文件手动转移到其他位置存放

    mv /u01/app/oracle/oradata/TESTDG/datafile/o1_mf_tbs_test_kp27r5t8_.dbf /tmp/

    4 通过from service 进行recover

    1. rman target sys/oracle
    2. run
    3. {
    4. allocate channel c1 type disk connect '/@testdg';
    5. allocate channel c2 type disk connect '/@testdg';
    6. allocate channel c3 type disk connect '/@testdg';
    7. allocate channel c4 type disk connect '/@testdg';
    8. recover standby database from service 'testdb' ;
    9. }

    5 恢复过程跟之前修改gap步骤完全一样,不需要人为的去干预

    6 恢复日志

    1. allocated channel: c1
    2. channel c1: SID=25 device type=DISK
    3. allocated channel: c2
    4. channel c2: SID=261 device type=DISK
    5. allocated channel: c3
    6. channel c3: SID=26 device type=DISK
    7. allocated channel: c4
    8. channel c4: SID=262 device type=DISK
    9. Starting recover at 2022/11/01 21:44:38
    10. Oracle instance started
    11. Total System Global Area 1543500144 bytes
    12. Fixed Size 8896880 bytes
    13. Variable Size 889192448 bytes
    14. Database Buffers 637534208 bytes
    15. Redo Buffers 7876608 bytes
    16. contents of Memory Script:
    17. {
    18. restore standby controlfile from service 'testdb';
    19. alter database mount standby database;
    20. }
    21. executing Memory Script
    22. Starting restore at 2022/11/01 21:44:51
    23. allocated channel: ORA_DISK_1
    24. channel ORA_DISK_1: SID=253 device type=DISK
    25. channel ORA_DISK_1: starting datafile backup set restore
    26. channel ORA_DISK_1: using network backup set from service testdb
    27. channel ORA_DISK_1: restoring control file
    28. channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
    29. output file name=/u01/app/oracle/oradata/TESTDG/controlfile/control01.ctl
    30. Finished restore at 2022/11/01 21:44:54
    31. released channel: ORA_DISK_1
    32. Statement processed
    33. Executing: alter system set standby_file_management=manual
    34. contents of Memory Script:
    35. {
    36. set newname for tempfile 1 to
    37. "/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_temp_kp1q02wb_.tmp";
    38. switch tempfile all;
    39. set newname for datafile 1 to
    40. "/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_system_kp1phykz_.dbf";
    41. set newname for datafile 3 to
    42. "/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_sysaux_kp1phyo1_.dbf";
    43. set newname for datafile 4 to
    44. "/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_undotbs1_kp1phyt2_.dbf";
    45. set newname for datafile 5 to new;
    46. set newname for datafile 7 to
    47. "/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_users_kp1phz14_.dbf";
    48. restore from service 'testdb' datafile
    49. 5;
    50. catalog datafilecopy "/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_system_kp1phykz_.dbf",
    51. "/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_sysaux_kp1phyo1_.dbf",
    52. "/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_undotbs1_kp1phyt2_.dbf",
    53. "/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_users_kp1phz14_.dbf";
    54. switch datafile all;
    55. }
    56. executing Memory Script
    57. executing command: SET NEWNAME
    58. renamed tempfile 1 to /u01/app/oracle/oradata/TESTDG/datafile/o1_mf_temp_kp1q02wb_.tmp in control file
    59. executing command: SET NEWNAME
    60. executing command: SET NEWNAME
    61. executing command: SET NEWNAME
    62. executing command: SET NEWNAME
    63. executing command: SET NEWNAME
    64. Starting restore at 2022/11/01 21:44:59
    65. allocated channel: ORA_DISK_1
    66. channel ORA_DISK_1: SID=260 device type=DISK
    67. channel ORA_DISK_1: starting datafile backup set restore
    68. channel ORA_DISK_1: using network backup set from service testdb
    69. channel ORA_DISK_1: specifying datafile(s) to restore from backup set
    70. channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/TESTDG/datafile/o1_mf_tbs_test_%u_.dbf
    71. channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
    72. Finished restore at 2022/11/01 21:45:01
    73. cataloged datafile copy
    74. datafile copy file name=/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_system_kp1phykz_.dbf RECID=2 STAMP=1119649501
    75. cataloged datafile copy
    76. datafile copy file name=/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_sysaux_kp1phyo1_.dbf RECID=3 STAMP=1119649501
    77. cataloged datafile copy
    78. datafile copy file name=/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_undotbs1_kp1phyt2_.dbf RECID=4 STAMP=1119649501
    79. cataloged datafile copy
    80. datafile copy file name=/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_users_kp1phz14_.dbf RECID=5 STAMP=1119649501
    81. datafile 5 switched to datafile copy
    82. input datafile copy RECID=1 STAMP=1119649500 file name=/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_tbs_test_kp28pw2t_.dbf
    83. datafile 1 switched to datafile copy
    84. input datafile copy RECID=2 STAMP=1119649501 file name=/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_system_kp1phykz_.dbf
    85. datafile 3 switched to datafile copy
    86. input datafile copy RECID=3 STAMP=1119649501 file name=/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_sysaux_kp1phyo1_.dbf
    87. datafile 4 switched to datafile copy
    88. input datafile copy RECID=4 STAMP=1119649501 file name=/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_undotbs1_kp1phyt2_.dbf
    89. datafile 7 switched to datafile copy
    90. input datafile copy RECID=5 STAMP=1119649501 file name=/u01/app/oracle/oradata/TESTDG/datafile/o1_mf_users_kp1phz14_.dbf
    91. contents of Memory Script:
    92. {
    93. recover database from service 'testdb';
    94. }
    95. executing Memory Script
    96. Starting recover at 2022/11/01 21:45:01
    97. using channel ORA_DISK_1
    98. skipping datafile 5; already restored to SCN 2174252
    99. channel ORA_DISK_1: starting incremental datafile backup set restore
    100. channel ORA_DISK_1: using network backup set from service testdb
    101. destination for restore of datafile 00001: /u01/app/oracle/oradata/TESTDG/datafile/o1_mf_system_kp1phykz_.dbf
    102. channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
    103. channel ORA_DISK_1: starting incremental datafile backup set restore
    104. channel ORA_DISK_1: using network backup set from service testdb
    105. destination for restore of datafile 00003: /u01/app/oracle/oradata/TESTDG/datafile/o1_mf_sysaux_kp1phyo1_.dbf
    106. channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
    107. channel ORA_DISK_1: starting incremental datafile backup set restore
    108. channel ORA_DISK_1: using network backup set from service testdb
    109. destination for restore of datafile 00004: /u01/app/oracle/oradata/TESTDG/datafile/o1_mf_undotbs1_kp1phyt2_.dbf
    110. channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
    111. channel ORA_DISK_1: starting incremental datafile backup set restore
    112. channel ORA_DISK_1: using network backup set from service testdb
    113. destination for restore of datafile 00007: /u01/app/oracle/oradata/TESTDG/datafile/o1_mf_users_kp1phz14_.dbf
    114. channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
    115. starting media recovery
    116. media recovery complete, elapsed time: 00:00:00
    117. Finished recover at 2022/11/01 21:45:08
    118. Executing: alter system set standby_file_management=auto
    119. Finished recover at 2022/11/01 21:45:08
    120. RMAN> exit

    7 重建standby log

    1. ---因为standby log的路径是主库的,可能跟实际的不一致
    2. select 'alter database drop standby logfile group '||group#||';'
    3. from v$standby_log;
    4. alter database ADD standby logfile thread 1 group 21 ('/u01/app/oracle/oradata/TESTDG/onlinelog/redo01.log') size 200M ;
    5. alter database ADD standby logfile thread 1 group 22 ('/u01/app/oracle/oradata/TESTDG/onlinelog/redo02.log') size 200M ;
    6. alter database ADD standby logfile thread 1 group 23 ('/u01/app/oracle/oradata/TESTDG/onlinelog/redo03.log') size 200M ;
    7. alter database ADD standby logfile thread 1 group 24 ('/u01/app/oracle/oradata/TESTDG/onlinelog/redo04.log') size 200M ;

    8 启动数据库恢复同步

    1. alter database open read ONLY;
    2. alter database recover managed standby database using current logfile disconnect from session;

    总结:

            通过(RECOVER STANDBY DATABASE ... FROM SERVICE)方式对备库问题进行修复,可以大大简化了备库问题的修复步骤以及时间。

  • 相关阅读:
    Java爬虫教程:从入门到精通
    MySQL (2)
    1534_TriCore编译器Tasking使用_汇编语言语法以及标识符
    记账对于个人的意义
    NAT地址转换,路由器作为出口设备,实现负载分担
    使用Docker 部署jenkins 实现自动化部署
    idea中把spring boot项目打成jar包
    Android-源码分析-MTK平台BUG解决:客户电池NTC功能(移植高低温报警,关机报警功能)---第二天分析与解决
    通过有序线性结构构造AVL树
    【Java】构造方法及类的初始化
  • 原文地址:https://blog.csdn.net/sinat_36757755/article/details/127643023