• oracle10g的dataguard测试


    sohu老博客的看不了了,只能重新发布记录:

    windows2003server+oracle10.2.0.1

    1.检查归档模式

    SQL> archive log list;
    数据库日志模式            存档模式
    自动存档             启用
    存档终点            USE_DB_RECOVERY_FILE_DEST
    最早的联机日志序列     1
    下一个存档日志序列   3
    当前日志序列           3
    SQL> select force_logging,flashback_on,db_unique_name from v$database;

    FOR FLASHBACK_ON       DB_UNIQUE_NAME
    --- ------------------ ------------------------------
    NO  NO                 jyc
    SQL> ALTER DATABASE FORCE LOGGING;

    数据库已更改。
    SQL> select force_logging,flashback_on,db_unique_name from v$database;

    FOR FLASHBACK_ON       DB_UNIQUE_NAME
    --- ------------------ ------------------------------
    YES NO                 jyc


    2.准备listener.ora和tnsnames.ora
    # listener.ora
    # Generated by Oracle configuration tools.

    SID_LIST_LISTENER =
      (SID_LIST =
        (SID_DESC =
          (SID_NAME = PLSExtProc)
          (ORACLE_HOME = d:\oracle\product\10.2.0\db_1)
          (PROGRAM = extproc)
        )
      )

    LISTENER =
      (DESCRIPTION_LIST =
        (DESCRIPTION =
          (ADDRESS = (PROTOCOL = TCP)(HOST = huasun)(PORT = 1521))
          (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
        )
      )
     
    #tnsnames.ora

    JYC =
      (DESCRIPTION =
        (ADDRESS_LIST =
          (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.205.251)(PORT = 1521))
        )
        (CONNECT_DATA =
          (SERVICE_NAME = jyc)
        )
      )
    DG =
      (DESCRIPTION =
        (ADDRESS_LIST =
          (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.205.251)(PORT = 1521))
        )
        (CONNECT_DATA =
          (SERVICE_NAME = dg)
        )
      )

    3.停库拷贝文件:
    SQL> shutdown immediate
    ORA-01109: 数据库未打开


    已经卸载数据库。
    ORACLE 例程已经关闭。
    SQL>


    准备windows服务(unix不需要):
    oradim -new -sid dg
    拷贝密码文件:将PWDjyc.ora拷贝为D:\oracle\product\10.2.0\db_1\database\PWDdg.ora
    从主库创建备库的控制文件,并复制3份。
    ALTER DATABASE CREATE STANDBY CONTROLFILE AS 'D:\oracle\product\10.2.0\ORADATA\DG\CONTROL01.CTL';

    主库的参数:
    #modify parameters
    *.DB_UNIQUE_NAME=jyc
    *.LOG_ARCHIVE_CONFIG='DG_CONFIG=(jyc,dg)'
    *.DB_FILE_NAME_CONVERT='dg','jyc'
    *.LOG_FILE_NAME_CONVERT='D:\oracle\product\10.2.0\oradata\dg\arch1\','D:\oracle\product\10.2.0\oradata\jyc\arch1\','D:\oracle\product\10.2.0\oradata\dg\arch2\','D:\oracle\product\10.2.0\oradata\jyc\arch2\'
    *.LOG_ARCHIVE_FORMAT=log%t_%s_%r.arc
    *.LOG_ARCHIVE_DEST_1=
     'LOCATION=D:\oracle\product\10.2.0\oradata\jyc\arch1\
      VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
      DB_UNIQUE_NAME=jyc'
    *.LOG_ARCHIVE_DEST_2=
     'SERVICE=dg LGWR ASYNC
      VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
      DB_UNIQUE_NAME=dg'
    *.LOG_ARCHIVE_DEST_STATE_1=ENABLE
    *.LOG_ARCHIVE_DEST_STATE_2=ENABLE
    *.STANDBY_ARCHIVE_DEST='D:\oracle\product\10.2.0\oradata\jyc\st\'
    *.STANDBY_FILE_MANAGEMENT=AUTO
    *.FAL_SERVER=dg
    *.FAL_CLIENT=jyc

    备库的参数:
    #modify parameters
    *.DB_UNIQUE_NAME=dg
    *.LOG_ARCHIVE_CONFIG='DG_CONFIG=(dg,jyc)'
    *.DB_FILE_NAME_CONVERT='jyc','dg'
    *.LOG_FILE_NAME_CONVERT='D:\oracle\product\10.2.0\oradata\jyc\arch1\','D:\oracle\product\10.2.0\oradata\dg\arch1\','D:\oracle\product\10.2.0\oradata\jyc\arch2\','D:\oracle\product\10.2.0\oradata\dg\arch2\'
    *.LOG_ARCHIVE_FORMAT=log%t_%s_%r.arc
    *.LOG_ARCHIVE_DEST_1=
     'LOCATION=D:\oracle\product\10.2.0\oradata\dg\arch1\
      VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
      DB_UNIQUE_NAME=dg'
    *.LOG_ARCHIVE_DEST_2=
     'SERVICE=jyc LGWR ASYNC
      VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
      DB_UNIQUE_NAME=jyc'
    *.LOG_ARCHIVE_DEST_STATE_1=ENABLE
    *.LOG_ARCHIVE_DEST_STATE_2=ENABLE
    *.STANDBY_ARCHIVE_DEST='D:\oracle\product\10.2.0\oradata\dg\st\'
    *.STANDBY_FILE_MANAGEMENT=AUTO
    *.FAL_SERVER=jyc
    *.FAL_CLIENT=dg

    建立相应的目录。


    4.准备数据
    启动备库到mount状态
    alter system set STANDBY_FILE_MANAGEMENT='MANUAL';
    alter database rename file 'D:\oracle\product\10.2.0\ORADATA\JYC\REDO01.LOG' to 'D:\oracle\product\10.2.0\ORADATA\DG\REDO01.LOG';
    alter database rename file 'D:\oracle\product\10.2.0\ORADATA\JYC\REDO02.LOG' to 'D:\oracle\product\10.2.0\ORADATA\DG\REDO02.LOG';
    alter database rename file 'D:\oracle\product\10.2.0\ORADATA\JYC\REDO03.LOG' to 'D:\oracle\product\10.2.0\ORADATA\DG\REDO03.LOG';
    alter system set STANDBY_FILE_MANAGEMENT='AUTO';


    主备库建standby日志(lgwr要求)
    alter database add standby LOGFILE GROUP 4 ('D:\oracle\product\10.2.0\ORADATA\DG\REDO04.log') size 4m;
    alter database add standby LOGFILE GROUP 5 ('D:\oracle\product\10.2.0\ORADATA\DG\REDO05.log') size 4m;
    alter database add standby LOGFILE GROUP 6 ('D:\oracle\product\10.2.0\ORADATA\DG\REDO06.log') size 4m;
    alter database add standby LOGFILE GROUP 7 ('D:\oracle\product\10.2.0\ORADATA\DG\REDO07.log') size 4m;

    alter database add standby LOGFILE GROUP 4 ('D:\oracle\product\10.2.0\ORADATA\JYC\REDO04.log') size 4m;
    alter database add standby LOGFILE GROUP 5 ('D:\oracle\product\10.2.0\ORADATA\JYC\REDO05.log') size 4m;
    alter database add standby LOGFILE GROUP 6 ('D:\oracle\product\10.2.0\ORADATA\JYC\REDO06.log') size 4m;
    alter database add standby LOGFILE GROUP 7 ('D:\oracle\product\10.2.0\ORADATA\JYC\REDO07.log') size 4m;

     

    5、检查主库和从库的状态:
    检查数据库角色和状态
    SQL> select database_role, switchover_status from v$database;

    检查archive log的应用状态
    SQL> SELECT SEQUENCE#, FIRST_TIME, NEXT_TIME, APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;
    SQL> select * from (SELECT SEQUENCE#,APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUEN
    CE# desc) t where rownum<5;

    检查archive log的遗失
    SQL> SELECT THREAD#, LOW_SEQUENCE#, HIGH_SEQUENCE# FROM V$ARCHIVE_GAP;

    检查archive log的路径是否可用
    SQL> select dest_name,status,error from v$archive_dest;

    检查进程状态
    select process,status from v$managed_standby;


    二、测试过程

    1、模式切换
    1.1 启动standby database到recover manage模式
    SQL>alter database recover managed standby database disconnect from session;

    1.2 启动到实时日志应用模式
    SQL>alter database recover managed standby database using current logfile disconnect from session;
    (之前需要先创建standby logfile,使用命令,同时还需要修改主库的参数LOG_ARCHIVE_DEST_2= 'SERVICE=ALUOCP LGWR',如果不加红色部分,那么就会一直hang住,见www.itpub.net - Database Error)

    1.3 切换standby database到read only模式
    SQL>alter database recover managed standby database cancel;
    SQL>alter database open read only;

    1.4 切换回recover manage模式
    SQL> alter database recover managed standby database disconnect from session;


    2、Switchover
    2.1 在主库上
    SQL>select switchover_status from v$database

    2.2 switchover_status的值如果是To standby,可以直接switchover:
    SQL> alter database commit to switchover to physical standby;
    SQL> shutdowm immediate;
    SQL> startup mount;

    如果是sessions active,则需要在switchover的命令后面加上with session shutdown:
    SQL> alter database commit to switchover to physical standby with session shutdown;
    SQL> shutdowm immediate;
    SQL> startup mount;

    2.3 在目标从库上
    SQL> select switchover_status from v$database
    switchover_status的值入股是To primary,可以直接switchover:
    SQL> alter database commit to switchover to primary;
    SQL> shutdown immediate;
    SQL> startup;

    如果是sessions active,则需要在switchover的命令后面加上with session shutdown:
    SQL> alter database commit to switchover to primary with session shutdown;
    SQL> shutdown immediate;
    SQL> startup;


    3、Failover
    3.1 在目标从库上,检查遗失的archive log:
    SQL> SELECT THREAD#, LOW_SEQUENCE#, HIGH_SEQUENCE# FROM V$ARCHIVE_GAP;

    3.2 如有遗失,Copy到从库目录并应用:
    SQL> ALTER DATABASE REGISTER PHYSICAL LOGFILE 'filespec1';

    3.3 再次检查遗失的archive log:
    SQL> SELECT UNIQUE THREAD# AS THREAD, MAX(SEQUENCE#) OVER (PARTITION BY thread#) AS LAST FROM V$ARCHIVED_LOG;

    3.4 关闭从库的recover模式:
    SQL> alter database recover managed standby database finish;
    OR
    SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH FORCE;
    OR
    SQL> alter database recover managed standby database finish skip standby logfile;

    3.5 切换从库为主库:
    SQL> alter database commit to switchover to primary;
    SQL> shutdown immediate;
    SQL> startup;


    4、使用Flashback恢复failover的主库
    4.1 在新的主库上查询切换时候的SCN号:
    SQL> SELECT standby_became_primary_scn FROM v$database;

    4.2 恢复旧主库后,Mount:
    SQL> STARTUP MOUNT;

    4.3 Flashback旧主库到步骤4.1查询得的SCN:
    SQL> FLASHBACK DATABASE TO SCN ;

    4.4 在旧主库上,转换control file为standby control file:
    SQL> ALTER DATABASE CONVERT TO PHYSICAL STANDBY;

    4.5 恢复旧主库为新从库:
    SQL> SHUTDOWN IMMEDIATE;
    SQL> STARTUP MOUNT;

    4.6 在新主库上,设置日志传输到旧主库(新从库),并确认状态:
    SQL> SELECT DEST_ID, DEST_NAME, STATUS, PROTECTION_MODE,DESTINATION, ERROR, SRL FROM V$ARCHIVE_DEST_STATUS;

    4.7 在新主库上,归档日志到新从库:
    SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;

    4.8 在新从库上开启recover模式:
    SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
    如果是real-time应用:
    SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT;

     

    ITPUB

    http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14239/create_ps.htm#i1225703

    Oracle10G Physical Standby Database笔记 - Oracle数据库管理 - ITPUB论坛-专业的IT技术社区

    http://tech.it168.com/db/2008-03-04/200803041243203.shtml(dg高级管理参考)
     

    可能出现的问题:
    当测试主备库切换后,在新主库执行切换日志,而在备库执行下面操作时,报错:
    SQL> alter database recover managed standby database using current logfile;
    alter database recover managed standby database using current logfile
    *
    第 1 行出现错误:
    ORA-00283: 恢复会话因错误而取消
    ORA-00314: 日志 4 (用于线程 1) 要求的序号 23 与 0 不匹配
    ORA-00312: 联机日志 4 线程 1: 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\JYC\REDO04.LOG'

    解决办法:
    SQL> alter database recover managed standby database disconnect from session;

    数据库已更改。

    SQL> alter database clear unarchived logfile group 4;
    alter database clear unarchived logfile group 4
    *
    第 1 行出现错误:
    ORA-01156: 进行中的恢复可能需要访问文件


    SQL> alter database recover managed standby database cancel;

    数据库已更改。

    SQL> alter database clear unarchived logfile group 4;

    数据库已更改。

    SQL> alter database recover managed standby database disconnect from session;

    数据库已更改。

    SQL> alter database recover managed standby database cancel;

    数据库已更改。

  • 相关阅读:
    如何检测和克服MLOps中的模型漂移
    13.计算机视觉
    JAVA毕设项目社区健康管理系统(java+VUE+Mybatis+Maven+Mysql)
    【第六部分 | JavaScript高级】3:正则表达式
    并网逆变器+VSG控制+预同步控制+电流电流双环控制(Simulink仿真实现)
    使用Gstreamer+OpenCV实现两路图像数据混合拉流推流
    知识增广的预训练语言模型K-BERT:将知识图谱作为训练语料
    Mysql80服务无法启动请输入Net helpMsg3534以获得更多的帮助
    小红书后端
    Python多进程开发
  • 原文地址:https://blog.csdn.net/jycjyc/article/details/139437507