• Linux Oracle 11g dataguard物理standby的配置


    这两天研究了下oracle 11g dataguard 物理standby 功能,总体来说这个功能满足公司需求,好了,不多说了,以下是详细的配置过程。

    主库:

    IP:192.168.77.5
    主机名:nod1
    ORACLE_SID=test
    ORACLE_BASE=/oracle/app/oracle
    ORACLE_HOME=/oracle/app/oracle/product/11.2.0/dbhome_1

    备库:

    IP:192.168.77.10
    主机名:nod2
    ORACLE_SID=test
    ORACLE_BASE=/oracle/app/oracle
    ORACLE_HOME=/oracle/app/oracle/product/11.2.0/dbhome_1

    准备工作:分别在主库和备库都安装上oracle软件,不装数据库。

    安装配置步骤:

    1、主库运行dbca创建数据库(安装过程中需要注意:先关掉flash recovery),数据库名为test

    2、登陆到数据库上

    	
    [oracle@nod1 ~]$ sqlplus /nolog
    SQL*Plus: Release 10.2.0.1.0 - Production on 星期四 3月 11 20:31:09 2010
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    SQL> conn / as sysdba;
    Connected.
    SQL>
    

    3、将主库设置为 FORCE LOGGING 模式

    	
    SQL> ALTER DATABASE FORCE LOGGING;
    Database altered.
    

    4、创建一个密码文件,如果数据库是用dbca创建的则会在$ORACLE_HOME/dbs/下自动创建一个叫orapwdSID的一个密码文件。(否则可以用orapwd命令创建一个)。

    5、配置Standby Redo Log。创建组数至少要比主库的online redo log组数多一个。

    	
    SQL> select group#,bytes from v$log;
    GROUP#      BYTES
    ---------- ----------
    1   52428800
    2   52428800
    3   52428800
    

    这里创建4组

    	
    SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 4 ('/oracle/app/oracle/oradata/test/stdbyredo01.log') SIZE 52428800;
    Database altered.
    SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 5 ('/oracle/app/oracle/oradata/test/stdbyredo02.log') SIZE 52428800;
    Database altered.
    SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 6 ('/oracle/app/oracle/oradata/test/stdbyredo03.log') SIZE 52428800;
    Database altered.
    SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 7 ('/oracle/app/oracle/oradata/test/stdbyredo04.log') SIZE 52428800;
    

    验证一下创建是否成功

    	
    SQL> SELECT GROUP#,THREAD#,SEQUENCE#,ARCHIVED,STATUS FROM V$STANDBY_LOG;
    GROUP#    THREAD#  SEQUENCE# ARC STATUS
    ---------- ---------- ---------- --- ----------
    4          0          0 YES UNASSIGNED
    5          0          0 YES UNASSIGNED
    6          0          0 YES UNASSIGNED
    7          0          0 YES UNASSIGNED
    Database altered.
    

    如果想删除某个组可以用下面的命令:

    	
    SQL> alter database drop standby logfile group 4;
    

    如果给某个组添加成员可以用下面命令:

    	
    SQL> ALTER DATABASE ADD STANDBY LOGFILE MEMBER '/oracle/app/oracle/oradata/test/stdbyredo04_1.log' TO GROUP 7;
    

    删除组中的成员用以下命令:

    	
    SQL> ALTER DATABASE DROP STANDBY LOGFILE MEMBER '/oracle/app/oracle/oradata/test/stdbyredo04_1.log';
    Database altered.
    SQL> host rm -f /oracle/app/oracle/oradata/test/stdbyredo04_1.log
    

    6、检查数据库是否处于归档状态

    	
    SQL> archive log list;
    Database log mode              Archive Mode
    Automatic archival             Enabled
    Archive destination            /oracle/app/oraclearch_log
    Oldest online log sequence     1
    Next log sequence to archive   2
    Current log sequence           2
    

    如果不是处于归档状态则运行下面命令:

    	
    SQL> SHUTDOWN IMMEDIATE;
    SQL> STARTUP MOUNT;
    SQL> ALTER DATABASE ARCHIVELOG;
    SQL> ALTER DATABASE OPEN;
    

    7、创建备库的控制文件(创建后数据库不能做结构性的改变)

    	
    SQL> ALTER DATABASE CREATE STANDBY CONTROLFILE AS '/oracle/app/oracle/oradata/test/stdby.ctl';
    

    8、创建pfile以便于修改配置参数

    	
    SQL> CREATE PFILE='/oracle/app/oracle/oradata/test/pfile' FROM SPFILE;
    

    9、关掉数据库开始编辑参数

    	
    SQL> shutdown immediate;
    

    10、$ vi /oracle/app/oracle/oradata/test/pfile

    添加下面内容

    	
    DB_UNIQUE_NAME=nod1
    LOG_ARCHIVE_CONFIG='DG_CONFIG=(nod1,nod2)'
    LOG_ARCHIVE_DEST_2=
    'SERVICE=nod2 LGWR ASYNC
     VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) 
     DB_UNIQUE_NAME=nod2'
    LOG_ARCHIVE_DEST_STATE_1=ENABLE
    LOG_ARCHIVE_DEST_STATE_2=ENABLE
    LOG_ARCHIVE_MAX_PROCESSES=30
    FAL_SERVER=nod2
    FAL_CLIENT=nod1
    DB_FILE_NAME_CONVERT='nod2','nod1'
    STANDBY_FILE_MANAGEMENT=AUTO
    

    11、进入sqlplus创建pfile(NOMOUNT状态)

    	
    SQL> CREATE SPFILE from PFILE='/oracle/app/oracle/oradata/test/pfile';
    

    12、创建tnsnames.ora和listener.ora,可以手动创建也可以用netca创建,无论哪种方法都必须保证能互相畅通。

    	
    $ cd /oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/
    $ vi tnsnames.ora
    

    输入下面内容:

    	
    nod2 =
     (DESCRIPTION =
    (ADDRESS_LIST =
     (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.77.10)(PORT = 1521))
    )
    (CONNECT_DATA =
     (SERVICE_NAME = test)
    )
     )
    nod1 =
     (DESCRIPTION =
     (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.77.5)(PORT = 1521))
    (CONNECT _DATA =
     (SERVER = DEDICATED)
     (SERVICE_NAME = test)
    )
     )
    $ vi listener.ora
    SID_LIST_LISTENER =
     (SID_LIST =
    (SID_DESC =
     (SID_NAME = test)
     (ORACLE_HOME = /oracle/app/oracle/product/11.2.0/dbhome_1)
     (PROGRAM = extproc)
    )
    (SID_DESC =
                               (GLOBAL_DBNAME = test)
     (SID_NAME = test)
     (ORACLE_HOME = /oracle/app/oracle/product/11.2.0/dbhome_1)
    )
     )
    LISTENER =
     (DESCRIPTION_LIST =
    (DESCRIPTION =
     (ADDRESS = (PROTOCOL = TCP)(HOST = nod2)(PORT = 1521))
     (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
    )
     )
    

    13、复制备份文件到备库

    	
    $ cd /oracle/app/oracle
    $ scp -r arch_log/ admin/ oradata/ 192.168.77.10:/oracle/app/oracle
    $ cd /oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/
    $ scp listener.ora  tnsnames.ora 192.168.77.10:/oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/
    $ cd /oracle/app/oracle/product/11.2.0/dbhome_1/dbs/
    $ scp orapwtest 192.168.77.10:/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/
    

    14、打开备库做以下操作

    	
    $ cd /oracle/app/oracle/oradata/test/
    $ rm -rf control0*
    $ cp stdby.ctl control01.ctl
    $ cp stdby.ctl control02.ctl
    $ cp stdby.ctl control03.ctl
    
    $ vi pfile 对相应文件做修改
    
    DB_UNIQUE_NAME=nod2
    LOG_ARCHIVE_CONFIG='DG_CONFIG=(nod1,nod2)'
    LOG_ARCHIVE_DEST_2=
    'SERVICE=nod1 LGWR ASYNC
     VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
     DB_UNIQUE_NAME=nod1'
    LOG_ARCHIVE_DEST_STATE_1=ENABLE
    LOG_ARCHIVE_DEST_STATE_2=ENABLE
    LOG_ARCHIVE_MAX_PROCESSES=30
    FAL_SERVER=nod1
    FAL_CLIENT=nod2
    DB_FILE_NAME_CONVERT='nod2','nod1'
    STANDBY_FILE_MANAGEMENT=AUTO
    
    $ cd /oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/
    $ vi listener.ora
    

    将nod1修改为nod2

    15、在备库中进入sqlplus

    	
    $ sqlplus /nolog
    SQL> conn / as sysdba;
    SQL> CREATE SPFILE from PFILE='/oracle/app/oracle/oradata/test/pfile';
    shutdown immediate; 
    

    16、测试oracle net是否畅通

    首先启动监听服务(分别在主机和备机上进行)

    	
    $ lsnrctl stop
    $ lsnrctl start
    

    分别在主机和备机上运行下面命令来测试

    	
    $ tnsping nod1
    $ tnsping nod2
    

    17、启动主库(正常启动)

    	
    $ sqlplus /nolog
    SQL> conn / as sysdba;
    SQL> startup
    

    18、启动备库到mount状态,并打开redo Apply

    	
    $ sqlplus /nolog
    SQL> conn / as sysdba;
    SQL> startup mount
    SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
    

    19、在主库上做一次日志切换

    	
    SQL> ALTER SYSTEM SWITCH LOGFILE;
    

    20、分别在主库和备库上做下列查询,检查归档日志是否由主库传送到备库,以下语句可以查看日志应用情况。

    	
    SQL> SELECT SEQUENCE#,APPLIED FROM V$ARCHIVED_LOG  ORDER BY SEQUENCE#;
    
    
    SEQUENCE# APP
    ---------- ---
    2 YES
    3 YES
    

    如果出现上面情况则说明配置成功。

    21、在主 库建表然后在备库查询进行验证

    	
    SQL> create table nod2(id integer,name char(10))
    SQL> insert into nod2 values(1,'nod1');
    SQL> commit;
    SQL> select * from nod2;
    ID NAME
    ---------- ----------
    1 nod1
    

    22、在主库上做个日志归档

    	
    SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;
    

    23、在备库上取消掉redo apply

    	
    SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
    SQL> ALTER DATABASE OPEN;
    SQL> select * from nod2;
    
    ID NAME
    ---------- ----------
    1 nod1
    

    测试成功

    24、再次切换为备库的redo apply状态

    	
    SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
    
    主库备库互相切换
    --------------------------
    

    此步骤在切换成功后,要进行主机HOST的相应配置,要不然在日志切换时会报错。

    25、在主库上做如下sql语句

    	
    SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY WITH SESSION SHUTDOWN;
    SQL> shutdown immediate;
    SQL> startup nomount;
    SQL> ALTER DATABASE MOUNT STANDBY DATABASE;
    SQL> RECOVER MANAGED STANDBY DATABASE DISCONNECT;
    

    26、在备库上做switchover

    	
    SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
    SQL> shutdown immediate;
    SQL> startup
    

    27、分别在新的主库和备库上查看状态,验证主库备库是否切换正常。

    	
    SQL> select name,database_role from v$database;
    

    再次创建表在切换后的主库备库上验证。

    28、在新的主库上创建表

    	
    SQL> create table nod1(id integer,name char(10));
    SQL> insert into nod1 values(111,'haha');
    SQL> commit;
    SQL> select * from nod1;
    SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;
    

    29、在新的备库上做下面操作以取消redo apply

    	
    SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
    SQL> ALTER DATABASE OPEN;
    SQL> select * from nod1;
    

    30、恢复新备库为redo apply状态

    维护:

    1、开机顺序,先备库的listener再启动备库。再启动主库的listener,再启动主库;

    2、关机顺序,先关闭主库,再关闭备库。

    附上实时查看日志同步日志,可以查看问题所在:

    	
     tail -f /oracle/app/oracle/diag/rdbms/nod1/test/trace/alert_test.log 
    

    stanby上检查应用率和活动率:

    	
    SQL>select to_char(start_time,'dd-mon-rr hh24:mi:ss') start_time,item,sofar from V$recovery_progress where item in ('Active Apply Rate', 'Average Apply Rate','Redo Applied');
    

    Redo Applied值以MB衡量,而Active Apply Rate和Average Apply Rate以KB/s计算。

    以上就是整个Oracle 11g dataguard物理standby 数据实时同步配置过程。

    文章装在自: http://express.ruanko.com/ruanko-express_52/studentexchange4.html  作者:张佳雄

  • 相关阅读:
    cocos2dx3.1从零学习(二)菜单、场景切换、场景传值
    XCode5添加新建类模板(Cocos2dx Template Class for Scene or Layer)
    根据Uri获取图片绝对路径,解决Android4.4以上版本Uri转换
    如何学习 cocos2d-x ?
    Java数据类型中String、Integer、int相互间的转换
    Android各种效果集合
    重新生成IE02
    nvl与 is not null的区别等
    自定义view
    select into from 和 insert into select 的用法和区别(转)
  • 原文地址:https://www.cnblogs.com/StruggleBird/p/2837503.html
Copyright © 2020-2023  润新知