zoukankan      html  css  js  c++  java
  • 转:Windows平台之Oracle10g DG配置

    Windows平台之Oracle10g DG配置

    DataGuard简称DG,是一种数据库级别的HA方案,最主要功能是冗灾、数据保护、故障恢复,DG是生产数据库的"事务一致性copy",创建时,使用生产库的物理copy,创建完成后,备库会通过生产库传输过来的归档日志(或重做条目)自动维护备用数据库。将重做数据应用到备用库。DG分为"物理standby""逻辑standby" 。本实例是采用“物理standby”。DGOracle企业版专有特性,因此标准版是没有的。
    操作系统
    主从关系
    IP地址
    数据文件路径
    win2003server
    Primary
    192.168.48.101
    D:\oracle\product\10.2.0\oradata\dgoracle
    win2003server
    Standby
    192.168.48.102
    D:\oracle\product\10.2.0\oradata\dgoracle
    注:PrimaryStandby的数据文件路径可以不一样。
     
    硬件及操作系统要求:
    1.       运行于相同的硬件平台,比如都是intelx86架构的32linux平台
    2.       服务器的配置可以不一样,只要有足够的存储数据文件的空间就行
    3.       primarystandby服务器的操作系统必须一致,当然版本可以略有差异,比如一个是AS4,另一个是AS5
     
    Oracle数据库名称规划:
    db_name
    dgoracle
    db_uniqe_name
    dgoracle
    instance_name
    txgj
    service_name
    dgoracle
    oracle_sid
    txgj
    Primarystandby服务器上分别安装好Oracle数据库,也可以先安装软件,然后在Primary上建库,然后再将数据文件copystandby上。
     
    DG配置之路
     
    1. Primary上查看归档
    SQL>archive log list
    如果未归档,则开启归档
    SQL>shutdown immediate;
    SQL>startup mount;
    SQL>alter database archivelog;
    SQL>alter database open;
    SQL>archive log list;
     
    2.Primary上指定归档日志路径与格式
    SQL>alter system set log_archive_dest_1=’D:\oracle\archlog VALID_FOR=(ALL_LOGFILES,ALL_ROLES)’scope=spfile;
    SQL>alter system set log_archive_format=’arch_%t_%s_%r_arc’ scope=spfile;
     
    3.Primary上修改数据库为强制归档模式
    SQL>alter database force logging;
    SQL>shutdowm immediate;
     
    4.Primary上创建参数文件及standby控制文件
    SQL>startup mount
    SQL>create pfile=’D:\oracle\init.ora’ from spfile;
    SQL>alter database create standby controlfile as ‘D:\oracle\01.ctl’;
    SQL>shutdown immediate;
     
    5.关闭Standby库,并将Primary的数据文件复制并覆盖同名文件,复制刚创建的参数文件与控制文件,将01.ctl再复制2份并命名为同名控制文件,然后覆盖安装目录下同名文件。复制Primary密码文件覆盖standby安装目录下同名文件。
     
    6.修改Primary刚创建的pfile参数,添加如下内容:
    *.LOG_ARCHIVE_DEST_STATE_1=ENABLE
    *.LOG_ARCHIVE_DEST_STATE_2=ENABLE
    *.FAL_SERVER='standby'
    *.FAL_CLIENT='primary'
    *.STANDBY_FILE_MANAGEMENT='AUTO'
    *.STANDBY_ARCHIVE_DEST='D:\oracle\archstandby'
    *.LOG_FILE_NAME_CONVERT=('D:\oracle\product\10.2.0\oradata\dgoracle','D:\oracle\product\10.2.0\oradata\dgoracle')
    *.DB_FILE_NAME_CONVERT=('D:\oracle\product\10.2.0\oradata\dgoracle','D:\oracle\product\10.2.0\oradata\dgoracle')
     
    每个参数具体什么意思去Baidu一下。
     
    7.修改Standby参数文件,添加以下内容:
    *.log_archive_dest_2='SERVICE=primary LGWR ASYNC'
    *.LOG_ARCHIVE_DEST_STATE_1=ENABLE
    *.LOG_ARCHIVE_DEST_STATE_2=ENABLE
    *.FAL_SERVER=primary
    *.FAL_CLIENT=standby
    *.STANDBY_ARCHIVE_DEST='D:\oracle\archstandby'
    *.STANDBY_FILE_MANAGEMENT=AUTO
    *.LOG_FILE_NAME_CONVERT=('D:\oracle\product\10.2.0\oradata\dgoracle','D:\oracle\product\10.2.0\oradata\dgoracle')
    *.DB_FILE_NAME_CONVERT=('D:\oracle\product\10.2.0\oradata\dgoracle','D:\oracle\product\10.2.0\oradata\dgoracle')
     
    8.配置主备库的监听文件
    SID_LIST_LISTENER =
        (SID_LIST =
           (SID_DESC =
             (SID_NAME = PLSExtProc)
             (ORACLE_HOME = f:\oracle\product\10.2.0\db_1)
             (PROGRAM = extproc)
          )
           (SID_DESC =
             (GLOBAL_DBNAME= dgoracle)
             (ORACLE_HOME = D:\oracle\product\10.2.0\db_1)
             (SID_NAME = txgj)
          )
        )
     
    LISTENER =
        (DESCRIPTION_LIST =
           (DESCRIPTION =
             (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.48.101)(PORT = 1521))
             (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
         )
       )
    注:蓝色字体为主备库都要添加内容,红色字体则是修改成本机的IP
     
    9.配置主备库tnsnames.ora文件,添加内容:
    PRIMARY =
        (DESCRIPTION =
           (ADDRESS_LIST =
             (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.48.101)(PORT = 1521))
           )
           (CONNECT_DATA =
             (SERVICE_NAME = dgoracle)
          )
        )
     
    STANDBY =
        (DESCRIPTION =
           (ADDRESS_LIST =
             (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.48.102)(PORT = 1521))
           )
           (CONNECT_DATA =
             (SERVICE_NAME = dgoracle)
           )
         )
     
    配置完后,启动监听测试下tnsping primarytnsping standby,看能否ping通。
     
    10.先启standby库,然后启动primary库,日志切换测试
    启动standby
    SQL>create spfile from pfile=’D:\oracle\init.ora’;
    SQL>startup nomount;
    SQL>alter database mount standby database;
    SQL>alter database recover managed standby database disconnect from session;
    启动primary
    SQL>create spfile from pfile=’D:\oracle\init.ora’;
    SQL>startup
    Primary上做几次日志切换测试
    SQL>alter system switch logfile;
    SQL>archive log list;
    此时在standby查到的日志情况应该是中间一项为0,其它2项目与primary一致。
    SQL> select sequence#,applied from v$archived_log order by sequence#;
    standby执行上面查询语句,若日志应用情况都为YES,且比primay当前日志序号小1则为正常。
    SQL> select database_role,switchover_status from v$database;
    primarystandby上执行上条语句,查询角色及切换状态。
     
    11.容灾测试
    Primary上创建:
    SQL>create user newyl identified by newyl;
    SQL>grant connect,resource to newyl;
    SQL>conn test/test@primary
    SQL>create table test(name varchar2(20));
    SQL>insert into test values(‘my name is tianwf’);
    SQL>commit;
    SQL>conn /as sysdba;
    SQL>alter system switch logfile;
    Standby切到只读模式,查询是数据是否同步过来
    SQL>conn /as sysdba
    SQL>alter database recover managed standby database cancel;
    SQL>alter database open read only;
    SQL>conn newyl/newyl
    SQL>select * from test;
    结果为:
    NAME:
    My name is tianwf
    说明同步正常。
    再次将standby切换至恢复状态:
    SQL>conn /as sysdba
    SQL>alter database recover managed standby database disconnect from session;
    12.主备机角色转换
    Primary切换standby角色
    SQL>alter system switch logfile;
    SQL>alter database commit to switchover to standby with session shutdown;
    SQL>shutdown immediate;
    SQL>startup nomount;
    SQL>alter database mount standby database;
    SQL>alter database recover managed standby database disconnect from session;
    Standby切换到primary角色
    SQL> alter database commit to switchover to primary with session shutdown;
    SQL>shutdown immediate;
    SQL>startup;
    查看主备角色及切换状态:
    SQL> select database_role,switchover_status from v$database;
    魔兽就是毒瘤,大家千万不要玩。
  • 相关阅读:
    linux安装lamp/lamp/lanmp
    git命令
    redis常问面试题
    liunx 项目发布(django + uwsgi + nginx+supervisor发布web服务器)
    安装nginx
    liunx安装mysql(mariadb)
    linux安装python3
    scrapy框架day01
    网络编程, socket用法
    面向对象进阶
  • 原文地址:https://www.cnblogs.com/tracy/p/2303438.html
Copyright © 2011-2022 走看看