• Oracle-CDB容器数据库主备切换步骤


    前言:

            Oracle12c之后推出了CDB容器数据库,CDB容器数据库包含根容器root以及多个PDB数据库,与之前Oracle11g的非容器数据库架构存在不同,那么如何进行CDB容器数据库的主备切换?本文接下来将讲述CDB容器数据库的主备切换步骤

    数据库环境:

    ​db_roleipuniq_nameroot_dbpdb
    primary(19.3)192.168.146.2orclCDB$ROOT

    PDB$SEED

    pdb

    pdb1

    pdb3

    standby(19.3)192.168.146.3orcldgCDB$ROOTpdb1

    注:数据库环境为单实例的DG主备,主备之间只同步CDB$ROOT,pdb1

    主备切换步骤:

    注:切换的命令使用Oracle12c之后新的命令,只需要在主库执行,不需要像11G之前需要分步在主备库执行切换命令

    1 在主库(146.2)验证主备是否具备切换条件

    1. ALTER DATABASE SWITCHOVER TO ORCLDG VERIFY;
    2. ERROR at line 1:
    3. ORA-16475: succeeded with warnings, check alert log for more details

     2 验证命令执行完成,但有warnings,检查主库alert log

    1. ---warnings的内容为备库存在offline的pluggable database,由于主备之间只同步pdb1,所以warning忽略
    2. ALTER DATABASE SWITCHOVER TO ORCLDG VERIFY
    3. 2022-08-20T16:16:25.211657+08:00
    4. SWITCHOVER VERIFY WARNING: no standby redo logfiles configured. Standby redo logfiles are recommended configuration for physical standby database.
    5. SWITCHOVER VERIFY: Send VERIFY request to switchover target ORCLDG
    6. SWITCHOVER VERIFY WARNING: switchover target has offline datafiles. Verify that those datafiles should remain offline.
    7. SWITCHOVER VERIFY WARNING: switchover target has offline pluggable databases.
    8. ORA-16475 signalled during: ALTER DATABASE SWITCHOVER TO ORCLDG VERIFY...

    3 在主库(146.2)执行主备切换命令

    1. ---命令执行完成,就代表主备切换完成
    2. ALTER DATABASE SWITCHOVER TO ORCLDG;
    3. Database altered.

    4 检查主库(146.2)的alert切换日志

    1. ---主库开始切换为备库
    2. TMI: kcv_switchover_to_target convert to physical BEGIN 2022-08-20 16:17:39.750147
    3. 2022-08-20T16:17:39.750491+08:00
    4. ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY [Process Id: 5068] (orcl)
    5. NET (PID:5068): Waiting for target standby to receive all redo
    6. 2022-08-20T16:17:39.752467+08:00
    7. NET (PID:5068): Waiting for all non-current ORLs to be archived
    8. 2022-08-20T16:17:39.752550+08:00
    9. NET (PID:5068): All non-current ORLs have been archived
    10. 2022-08-20T16:17:39.752618+08:00
    11. NET (PID:5068): Waiting for all FAL entries to be archived
    12. 2022-08-20T16:17:39.752661+08:00
    13. NET (PID:5068): All FAL entries have been archived
    14. 2022-08-20T16:17:39.752714+08:00
    15. NET (PID:5068): Waiting for LAD:2 to become synchronized
    16. 2022-08-20T16:17:40.753270+08:00
    17. NET (PID:5068): Active, synchronized Physical Standby switchover target has been identified
    18. NET (PID:5068): Preventing updates and queries at the Primary
    19. 2022-08-20T16:17:42.755914+08:00
    20. NET (PID:5068): Generating and shipping final logs to target standby
    21. Switchover End-Of-Redo Log thread 1 sequence 39 has been fixed
    22. Switchover: Primary highest seen SCN set to 0x000000000032f541
    23. NET (PID:5068): Noswitch archival of T-1.S-39
    24. NET (PID:5068): End-Of-Redo Branch archival of T-1.S-39
    25. NET (PID:5068): LGWR is scheduled to archive to LAD:2 after log switch
    26. NET (PID:5068): SRL selected for T-1.S-39 for LAD:2
    27. NET (PID:5068): Archiving is disabled due to current logfile archival
    28. Primary will check for some target standby to have received all redo
    29. NET (PID:5068): Waiting for target standby to apply all redo
    30. Backup controlfile written to trace file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_5068.trc
    31. NET (PID:5068): Converting the primary database to a new standby database
    32. Clearing standby activation ID 1640651983 (0x61ca5ccf)
    33. The primary database controlfile was created using the
    34. 'MAXLOGFILES 16' clause.
    35. There is space for up to 13 standby redo logfiles
    36. Use the following SQL commands on the standby database to create
    37. standby redo logfiles that match the primary database:
    38. ALTER DATABASE ADD STANDBY LOGFILE 'srl1.f' SIZE 209715200;
    39. ALTER DATABASE ADD STANDBY LOGFILE 'srl2.f' SIZE 209715200;
    40. ALTER DATABASE ADD STANDBY LOGFILE 'srl3.f' SIZE 209715200;
    41. ALTER DATABASE ADD STANDBY LOGFILE 'srl4.f' SIZE 209715200;
    42. Archivelog for thread 1 sequence 39 required for standby recovery
    43. Offline data file 5 marked as online during convert to standby or switchover to standby.
    44. Restore of backup may be required if the file is not physically accessible.
    45. Offline data file 6 marked as online during convert to standby or switchover to standby.
    46. Restore of backup may be required if the file is not physically accessible.
    47. Offline data file 8 marked as online during convert to standby or switchover to standby.
    48. Restore of backup may be required if the file is not physically accessible.
    49. Offline data file 9 marked as online during convert to standby or switchover to standby.
    50. Restore of backup may be required if the file is not physically accessible.
    51. Offline data file 10 marked as online during convert to standby or switchover to standby.
    52. Restore of backup may be required if the file is not physically accessible.
    53. Offline data file 11 marked as online during convert to standby or switchover to standby.
    54. Restore of backup may be required if the file is not physically accessible.
    55. Offline data file 12 marked as online during convert to standby or switchover to standby.
    56. Restore of backup may be required if the file is not physically accessible.
    57. Offline data file 13 marked as online during convert to standby or switchover to standby.
    58. Restore of backup may be required if the file is not physically accessible.
    59. Offline data file 14 marked as online during convert to standby or switchover to standby.
    60. Restore of backup may be required if the file is not physically accessible.
    61. Offline data file 15 marked as online during convert to standby or switchover to standby.
    62. Restore of backup may be required if the file is not physically accessible.
    63. Offline data file 16 marked as online during convert to standby or switchover to standby.
    64. Restore of backup may be required if the file is not physically accessible.
    65. Offline data file 28 marked as online during convert to standby or switchover to standby.
    66. Restore of backup may be required if the file is not physically accessible.
    67. Offline data file 29 marked as online during convert to standby or switchover to standby.
    68. Restore of backup may be required if the file is not physically accessible.
    69. Offline data file 30 marked as online during convert to standby or switchover to standby.
    70. Restore of backup may be required if the file is not physically accessible.
    71. Switchover: Primary controlfile converted to standby controlfile succesfully.
    72. Switchover: Complete - Database shutdown required
    73. TMI: kcv_switchover_to_target convert to physical END 2022-08-20 16:17:42.953878
    74. NET (PID:5068): Sending request(convert to primary database) to switchover target ORCLDG
    75. 2022-08-20T16:17:48.890626+08:00
    76. NET (PID:5068): Switchover complete. Database shutdown required
    77. USER (ospid: 5068): terminating the instance
    78. 2022-08-20T16:17:49.905701+08:00
    79. Instance terminated by USER, pid = 5068
    80. TMI: dbsdrv switchover to target END 2022-08-20 16:17:49.905742
    81. ---主库切换为备库完成

    5 检查备库(146.3)的alert切换日志

    1. ---备库切换为主库
    2. 2022-08-20T16:17:44.564127+08:00
    3. Background Media Recovery process shutdown (orcldg)
    4. 2022-08-20T16:17:45.353980+08:00
    5. rmi (PID:5261): Role Change: Canceled MRP
    6. TMI: kcv_commit_to_so_to_primary wait for MRP to finish END 2022-08-20 16:17:45.354132
    7. TMI: kcv_commit_to_so_to_primary Switchover from physical BEGIN 2022-08-20 16:17:45.354291
    8. rmi (PID:5261): Killing 2 processes (PIDS:5253,4753) (all RFS) in order to disallow current and future RFS connections. Requested by OS process 5261
    9. 2022-08-20T16:17:45.355342+08:00

    6 主备切换完成,打开新主库(146.3)

    1. ---打开root根容器
    2. alter database open;
    3. ---打开pdb1,因为只同步了pdb1,其他pdb没有同步,所以无法打开
    4. alter pluggable database pdb1 open;
    5. ---当前为主库
    6. SQL> select database_role from v$database;
    7. DATABASE_ROLE
    8. ----------------
    9. PRIMARY

    7 打开新备库(146.2),主备切换结束

    1. ---新备库之前的全部pdb都可以打开,只不过,PDB$SEED,PDB,PDB3新主库没有
    2. SQL> startup
    3. SQL> alter pluggable database all open;
    4. Pluggable database altered.
    5. SQL> alter database recover managed standby database using current logfile disconnect from session parallel 8;
    6. Database altered.
    7. SQL> SQL> SQL> SQL> show pdbs;
    8. CON_ID CON_NAME OPEN MODE RESTRICTED
    9. ---------- ------------------------------ ---------- ----------
    10. 2 PDB$SEED READ ONLY NO
    11. 3 PDB READ ONLY NO
    12. 4 PDB1 READ ONLY NO
    13. 6 PDB3 READ ONLY NO
    14. SQL> select database_role from v$database;
    15. DATABASE_ROLE
    16. ----------------
    17. PHYSICAL STANDBY
    18. SQL>

  • 相关阅读:
    【SpringMVC】SpringMVC的视图
    太速科技-基于XC7V690T的12路光纤PCIe接口卡
    酷开科技以酷开系统的力量让电视机“活”起来
    程序员面试金典 - 面试题 17.24. 最大子矩阵
    Spring Cloud Alibaba+saas企业架构技术选型+架构全景业务图 + 架构典型部署方案
    (带教程)商业版SEO关键词按天计费系统:关键词排名优化、代理服务、手机自适应及搭建教程
    golang pprof
    效果最大化广告系列的优势所在!
    [Kotlin Tutorials 21] 协程的取消
    关于软件设计师考试中的算法
  • 原文地址:https://blog.csdn.net/sinat_36757755/article/details/126432977