• Oracle-通过(RESTORE/RECOVER FROM SERVICE)方式搭建DataGuard


    前言:

    Oracle在12c推出了新特性(RESTORE/RECOVER ...FROM SERVICE)通过网络服务方式恢复数据库,这个新特性也大大简化了DataGuard主备的搭建。

    测试环境:

    主库备库
    数据库版本19.3.0.019.3.0.0
    架构单实例单实例
    db_unique_nametestdbtestdg
    ip192.168.2.101192.168.2.201

    通过from service部署主备:

    1    检查数据库开启归档以及force_logging

    1. ---数据库开启归档模式
    2. archive log list
    3. ---检查开启force_logging
    4. select force_logging from v$database;
    5. alter database force logging;

    2    检查并开启SYS远程登录

    1. ---确认参数remote_login_passwordfile为EXCLUSIVE
    2. show parameter remote_login_passwordfile

    3    配置主备TNS

    1. ---配置主备TNS
    2. #主库tns
    3. testdb =
    4. (DESCRIPTION =
    5. (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.2.201)(PORT = 1521))
    6. (CONNECT_DATA =
    7. (SERVER = DEDICATED)
    8. (SERVICE_NAME = testdb)
    9. )
    10. )
    11. #备库tns
    12. testdg=
    13. (DESCRIPTION =
    14. (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.2.101)(PORT = 1521))
    15. (CONNECT_DATA =
    16. (SERVER = DEDICATED)
    17. (SERVICE_NAME = testdg)
    18. )
    19. )

    4    配置主库参数

    1. ---设置主库参数
    2. alter system set log_archive_dest_1='location=/u01/app/oracle/arch'scope=both sid='*';
    3. alter system set db_create_file_dest='/u01/app/oracle/oradata' scope=both sid='*';
    4. alter system set log_archive_config='dg_config=(testdb,testdg)' scope=both sid='*';
    5. alter system set log_archive_dest_2=
    6. 'service=testdg LGWR ASYNC NOAFFIRM delay=0 optional
    7. compression=disable max_failure=0 max_connections=1 reopen=30
    8. net_timeout=300 valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE)
    9. db_unique_name=testdg' scope=both sid='*';
    10. alter system set log_archive_dest_state_2=defer scope=both sid='*';
    11. alter system set fal_client=testdb scope=both sid='*';
    12. alter system set fal_server=testdg scope=both sid='*';
    13. alter system set standby_file_management=AUTO scope=both sid='*';

    5    主库添加standby log

    1. ---添加standby_log
    2. #查询当前log的设置
    3. select thread#,group#,bytes/1024/1024 SIZE_IN_GB, status from v$log;
    4. #创建需要保持一致
    5. alter database ADD standby logfile thread 1 group 21 ('/u01/app/oracle/oradata/TESTDB/onlinelog/redo01.log') size 200M ;
    6. alter database ADD standby logfile thread 1 group 22 ('/u01/app/oracle/oradata/TESTDB/onlinelog/redo02.log') size 200M ;
    7. alter database ADD standby logfile thread 1 group 23 ('/u01/app/oracle/oradata/TESTDB/onlinelog/redo03.log') size 200M ;
    8. alter database ADD standby logfile thread 1 group 24 ('/u01/app/oracle/oradata/

    6    拷贝密码文件到备库

    scp -rp $ORACLE_HOME/dbs/orapwtestdb 192.168.2.101:$ORACLE_HOME/dbs/orapwtestdg

    7   生成spfile文件拷贝到备库

    1. create pfile='/tmp/initstandby.ora' from spfile;
    2. scp -rp /tmp/initstandby.ora 192.168.2.101:$ORACLE_HOME/dbs/inittestdg.ora

    8   备库编辑参数

    1. ---参数需要根据实际环境进行修改,以下参数只是测试环境参数,不能作为生产使用
    2. *.audit_file_dest='/u01/app/oracle/admin/testdg/adump'
    3. *.audit_trail='db'
    4. *.compatible='19.0.0'
    5. *.control_files='/u01/app/oracle/oradata/TESTDG/controlfile/control01.ctl'
    6. *.db_block_size=8192
    7. *.db_create_file_dest='/u01/app/oracle/oradata'
    8. *.db_name='testdb'
    9. *.db_unique_name='testdg'
    10. *.diagnostic_dest='/u01/app/oracle'
    11. *.dispatchers='(PROTOCOL=TCP) (SERVICE=testdgXDB)'
    12. *.fal_client='TESTDG'
    13. *.fal_server='TESTDB'
    14. *.local_listener=''
    15. *.log_archive_config='dg_config=(testdb,testdg)'
    16. *.log_archive_dest_1='location=/u01/app/oracle/arch'
    17. *.log_archive_dest_2='service=testdb LGWR ASYNC NOAFFIRM delay=0 optional
    18. compression=disable max_failure=0 max_connections=1 reopen=30
    19. net_timeout=300 valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE)
    20. db_unique_name=testdb'
    21. *.log_archive_dest_state_2='DEFER'
    22. *.memory_target=1470m
    23. *.nls_language='AMERICAN'
    24. *.nls_territory='AMERICA'
    25. *.open_cursors=300
    26. *.processes=300
    27. *.remote_login_passwordfile='EXCLUSIVE'
    28. *.standby_file_management='AUTO'
    29. *.undo_tablespace='UNDOTBS1'
    30. ---创建spfile
    31. create spfile from pfile;

    9   备库创建审计,数据目录

    1. mkdir -p /u01/app/oracle/admin/testdg/adump
    2. mkdir -p /u01/app/oracle/oradata/TESTDG/controlfile
    3. mkdir -p /u01/app/oracle/oradata/TESTDG/datafile
    4. mkdir -p /u01/app/oracle/oradata/TESTDG/tempfile
    5. mkdir -p /u01/app/oracle/oradata/TESTDG/onlinelog
    6. mkdir -p /u01/app/oracle/oradata/arch

    10   启动备库实例到nomount

    startup nomount

    11   备库通过service远程恢复standby controlfile

    1. rman target /
    2. restore standby controlfile from service 'testdb';
    3. RMAN> restore standby controlfile from service 'testdb';
    4. Starting restore at 2022/11/01 15:46:02
    5. using target database control file instead of recovery catalog
    6. allocated channel: ORA_DISK_1
    7. channel ORA_DISK_1: SID=13 device type=DISK
    8. channel ORA_DISK_1: starting datafile backup set restore
    9. channel ORA_DISK_1: using network backup set from service testdb
    10. channel ORA_DISK_1: restoring control file
    11. channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
    12. output file name=/u01/app/oracle/oradata/TESTDG/controlfile/control01.ctl
    13. Finished restore at 2022/11/01 15:46:06
    14. RMAN>

    12   启动到mount

    1. RMAN> alter database mount;
    2. released channel: ORA_DISK_1
    3. Statement processed
    4. RMAN>

    13   备库通过from service恢复数据文件

    1. ---可以通过修改rman的默认配置,设置并行
    2. RMAN> CONFIGURE DEFAULT DEVICE TYPE TO DISK;
    3. RMAN> CONFIGURE DEVICE TYPE DISK PARALLELISM 8;
    4. ---恢复管道section size的大小参考以下公式算法
    5. On the primary, query the largest datafile size to determine the section size to be used for the recover command.
    6. SQL> select max(bytes)/1073741824 GB from v$datafile;
    7. If the largest file is:
    8. <15TB use section size of 64GB
    9. >15TB and <30TB used section size of 128G
    10. >30TB and <60TB used section size of 256G
    11. >60TB use section size of 512G
    12. ---进行恢复
    13. #注意使用sys/password方式登陆,不然会出现
    14. using target database control file instead of recovery catalog
    15. RMAN-00571: ===========================================================
    16. RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
    17. RMAN-00571: ===========================================================
    18. RMAN-12001: could not open channel c1
    19. RMAN-10008: could not create channel context
    20. RMAN-10003: unable to connect to target database
    21. ORA-01017: invalid username/password; logon denied
    22. rman target sys/oracle
    23. run
    24. {
    25. allocate channel c1 type disk connect '/@testdg';
    26. allocate channel c2 type disk connect '/@testdg';
    27. allocate channel c3 type disk connect '/@testdg';
    28. allocate channel c4 type disk connect '/@testdg';
    29. allocate channel c5 type disk connect '/@testdg';
    30. allocate channel c6 type disk connect '/@testdg';
    31. allocate channel c7 type disk connect '/@testdg';
    32. allocate channel c8 type disk connect '/@testdg';
    33. restore database from service 'testdb' section size 64G;
    34. release channel c1;
    35. release channel c2;
    36. release channel c3;
    37. release channel c4;
    38. release channel c5;
    39. release channel c6;
    40. release channel c7;
    41. release channel c8;
    42. }

    14   备库恢复日志

    1. using target database control file instead of recovery catalog
    2. allocated channel: c1
    3. channel c1: SID=13 device type=DISK
    4. allocated channel: c2
    5. channel c2: SID=258 device type=DISK
    6. allocated channel: c3
    7. channel c3: SID=20 device type=DISK
    8. allocated channel: c4
    9. channel c4: SID=259 device type=DISK
    10. allocated channel: c5
    11. channel c5: SID=21 device type=DISK
    12. allocated channel: c6
    13. channel c6: SID=260 device type=DISK
    14. allocated channel: c7
    15. channel c7: SID=22 device type=DISK
    16. allocated channel: c8
    17. channel c8: SID=261 device type=DISK
    18. Starting restore at 2022/11/01 16:34:06
    19. channel c1: starting datafile backup set restore
    20. channel c1: using network backup set from service testdb
    21. channel c1: specifying datafile(s) to restore from backup set
    22. channel c1: restoring datafile 00001 to /u01/app/oracle/oradata/TESTDG/datafile/o1_mf_system_kp1phykz_.dbf
    23. channel c1: restoring section 1 of 1
    24. channel c2: starting datafile backup set restore
    25. channel c2: using network backup set from service testdb
    26. channel c2: specifying datafile(s) to restore from backup set
    27. channel c2: restoring datafile 00003 to /u01/app/oracle/oradata/TESTDG/datafile/o1_mf_sysaux_kp1phyo1_.dbf
    28. channel c2: restoring section 1 of 1
    29. channel c3: starting datafile backup set restore
    30. channel c3: using network backup set from service testdb
    31. channel c3: specifying datafile(s) to restore from backup set
    32. channel c3: restoring datafile 00004 to /u01/app/oracle/oradata/TESTDG/datafile/o1_mf_undotbs1_kp1phyt2_.dbf
    33. channel c3: restoring section 1 of 1
    34. channel c4: starting datafile backup set restore
    35. channel c4: using network backup set from service testdb
    36. channel c4: specifying datafile(s) to restore from backup set
    37. channel c4: restoring datafile 00007 to /u01/app/oracle/oradata/TESTDG/datafile/o1_mf_users_kp1phz14_.dbf
    38. channel c4: restoring section 1 of 1
    39. channel c4: restore complete, elapsed time: 00:00:02
    40. channel c3: restore complete, elapsed time: 00:00:08
    41. channel c1: restore complete, elapsed time: 00:00:16
    42. channel c2: restore complete, elapsed time: 00:00:16
    43. Finished restore at 2022/11/01 16:34:22
    44. released channel: c1
    45. released channel: c2
    46. released channel: c3
    47. released channel: c4
    48. released channel: c5
    49. released channel: c6
    50. released channel: c7
    51. released channel: c8

    15   启动备库到open read only

    alter database open read only;

    16   备库添加standby log

    1. ---备库添加standby_log
    2. #查询当前log的设置
    3. select thread#,group#,bytes/1024/1024 SIZE_IN_GB, status from v$log;
    4. #创建需要保持一致
    5. alter database ADD standby logfile thread 1 group 21 ('/u01/app/oracle/oradata/TESTDG/onlinelog/redo01.log') size 200M ;
    6. alter database ADD standby logfile thread 1 group 22 ('/u01/app/oracle/oradata/TESTDG/onlinelog/redo02.log') size 200M ;
    7. alter database ADD standby logfile thread 1 group 23 ('/u01/app/oracle/oradata/TESTDG/onlinelog/redo03.log') size 200M ;
    8. alter database ADD standby logfile thread 1 group 24 ('/u01/app/oracle/oradata/TESTDG/onlinelog/redo04.log') size 200M ;

    17   备库启动mrp进程进行同步,完成DataGuard主备搭建

    1. ---启动mrp进程
    2. alter database recover managed standby database using current logfile disconnect from session;
    3. SQL> SQL> SQL>
    4. SOURCE_DBID SOURCE_DB_UNIQUE_NAME NAME VALUE UNIT
    5. ----------- -------------------------------- -------------------------------- -------------------------------------------------- ------------------------------
    6. TIME_COMPUTED DATUM_TIME CON_ID
    7. ------------------------------ ------------------------------ ----------
    8. 2902942490 testdb transport lag +00 00:00:00 day(2) to second(0) interval
    9. 11/01/2022 16:53:03 11/01/2022 16:53:03 0
    10. 2902942490 testdb apply lag +00 00:00:00 day(2) to second(0) interval
    11. 11/01/2022 16:53:03 11/01/2022 16:53:03 0
    12. 2902942490 testdb apply finish time day(2) to second(3) interval
    13. 11/01/2022 16:53:03 0
    14. 0 estimated startup time 9 second
    15. 11/01/2022 16:53:03 0

    总结:

            通过(RESTORE/RECOVER ...FROM SERVICE)方式进行备库DG的部署,可以提高备库数据初始化的速度以及简化部署的步骤。

  • 相关阅读:
    Uniapp 入门
    大数据之HBase部署
    【iOS】—— 响应者链和事件传递链
    【软件工程】山东大学软件工程复习提纲
    uboot 启动流程详细分析参考
    基础框架代码解释
    IP数据报格式
    Nacos服务注册与心跳机制源码分析
    是时候回答【我为什么要学习 Go 语言(golang)】这个问题了
    项目讲解:让你在IT行业面试中以开发、实施、产品更近一步
  • 原文地址:https://blog.csdn.net/sinat_36757755/article/details/127642651