目标:实现dataguard redo传输cascade,即dg1的redo日志先传输到dg2,然后再从dg2传输到dg3,从而减少dg1主库的网络带宽压力!通常使用于dg1和dg2在同一局域网内,dg2和dg3通过广域网相连的场合!
一:环境介绍
主库
IP地址:192.168.1.61/24
操作系统版本:rhel5.4 64bit
数据库版本:11.2.0.3 64bit
数据库sid名:dg
数据库名:dg
数据库db_unique_name:dg1
备库1 物理备库
IP地址:192.168.1.62/24
操作系统版本:rhel5.4 64bit
数据库版本:11.2.0.3 64bit
数据库sid名:dg
数据库名:dg
数据库db_unique_name:dg2
备库2 物理备库
IP地址:192.168.1.62/24
操作系统版本:rhel5.4 64bit
数据库版本:11.2.0.3 64bit
数据库sid名:dg
数据库名:dg
数据库db_unique_name:dg3
二:统一修改三台数据库服务器的listener.ora和tnsnames.ora文件如下,listener.ora文件里面的GLOBAL_DBNAME和HOST参数做相应的修改
[oracle@dg1 ~]$ cat $TNS_ADMIN/listener.ora LISTENER =
dg2 = dg3 = |
三:dg1和dg2数据库服务器构建active dataguard
3.1修改主库初始化参数,添加standby日志组
- [oracle@dg1 ~]$ sqlplus /nolog
- SQL*Plus: Release 11.2.0.3.0 Production on Sat Apr 7 14:11:18 2012
- Copyright (c) 1982, 2011, Oracle. All rights reserved.
- SQL> conn /as sysdba
- Connected.
- SQL> !mkdir /u01/app/oracle/archivelog
- SQL> alter system set log_archive_dest_1='LOCATION=/u01/app/oracle/archivelog'
- valid_for=(all_logfiles,primary_role) db_unique_name=dg1;
- System altered.
- SQL> archive log list;
- Database log mode Archive Mode
- Automatic archival Enabled
- Archive destination /u01/app/oracle/archivelog
- Oldest online log sequence 3
- Next log sequence to archive 5
- Current log sequence 5
- SQL> select force_logging,db_unique_name from v$database;
- FOR DB_UNIQUE_NAME
- --- ------------------------------
- NO dg
- SQL> alter database force logging;
- Database altered.
- SQL> alter system set db_unique_name='dg1' scope=spfile;
- System altered.
- SQL> select force_logging,db_unique_name from v$database;
- FOR DB_UNIQUE_NAME
- --- ------------------------------
- YES dg
- SQL>alter system set log_archive_config='DG_CONFIG=(dg1,dg2,dg3)';
- System altered.
- SQL>alter system set log_archive_dest_2='SERVICE=dg2 valid_for=(online_logfile,primary_role) db_unique_name=dg2' scope=spfile;
- System altered.
- SQL>alter system set log_archive_dest_3='SERVICE=dg3 valid_for=(standby_logfiles,standby_role) db_unique_name=dg3' scope=spfile;
- System altered.
- SQL> show parameter remote_login;
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- remote_login_passwordfile string EXCLUSIVE
- SQL> show parameter log_archive_format;
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- log_archive_format string %t_%s_%r.dbf
- SQL> alter database add standby logfile group 4 '/u01/app/oracle/oradata/dg/standby01.log' size 50M;
- Database altered.
- SQL> alter database add standby logfile group 5 '/u01/app/oracle/oradata/dg/standby02.log' size 50M;
- Database altered.
- SQL> alter database add standby logfile group 6 '/u01/app/oracle/oradata/dg/standby03.log' size 50M;
- Database altered.
- SQL> alter database add standby logfile group 7 '/u01/app/oracle/oradata/dg/standby04.log' size 50M;
- Database altered.
- SQL> select member,group# from v$logfile order by 2;
- MEMBER GROUP#
- ---------------------------------------- ----------
- /u01/app/oracle/oradata/dg/redo01.log 1
- /u01/app/oracle/oradata/dg/redo02.log 2
- /u01/app/oracle/oradata/dg/redo03.log 3
- /u01/app/oracle/oradata/dg/standby01.log 4
- /u01/app/oracle/oradata/dg/standby02.log 5
- /u01/app/oracle/oradata/dg/standby03.log 6
- /u01/app/oracle/oradata/dg/standby04.log 7
- 7 rows selected.
一:环境介绍3. 3.2 由spfile生成pfile,重启主库,使先前修改的参数生效!修改参数文件,scp至dg2
- SQL> create pfile='/home/oracle/initdg.ora' from spfile;
- File created.
- SQL> shutdown immediate
- Database closed.
- Database dismounted.
- ORACLE instance shut down.
- SQL> startup
- ORACLE instance started.
- Total System Global Area 417546240 bytes
- Fixed Size 2228944 bytes
- Variable Size 281021744 bytes
- Database Buffers 125829120 bytes
- Redo Buffers 8466432 bytes
- Database mounted.
- Database opened.
- SQL> show parameter name;
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- db_file_name_convert string
- db_name string dg
- db_unique_name string dg1
- global_names boolean FALSE
- instance_name string dg
- lock_name_space string
- log_file_name_convert string
- processor_group_name string
- service_names string dg1.yang.com
- [oracle@dg1 ~]$ cat initdg.ora
- dg.__db_cache_size=125829120
- dg.__java_pool_size=4194304
- dg.__large_pool_size=4194304
- dg.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
- dg.__pga_aggregate_target=167772160
- dg.__sga_target=251658240
- dg.__shared_io_pool_size=0
- dg.__shared_pool_size=104857600
- dg.__streams_pool_size=0
- *.audit_file_dest='/u01/app/oracle/admin/dg/adump'
- *.audit_trail='db'
- *.compatible='11.2.0.0.0'
- *.control_files='/u01/app/oracle/oradata/dg/control01.ctl','/u01/app/oracle/fast_recovery_area/dg/control02.ctl'
- *.db_block_size=8192
- *.db_domain='yang.com'
- *.db_name='dg'
- *.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
- *.db_recovery_file_dest_size=4322230272
- *.db_unique_name='dg2'
- *.diagnostic_dest='/u01/app/oracle'
- *.dispatchers='(PROTOCOL=TCP) (SERVICE=dgXDB)'
- *.log_archive_config='DG_CONFIG=(dg1,dg2,dg3)'
- *.log_archive_dest_1='LOCATION=/u01/app/oracle/archivelog valid_for=(all_logfiles,primary_role) db_unique_name=dg2'
- *.log_archive_dest_2='SERVICE=dg1 valid_for=(online_logfiles,primary_role) db_unique_name=dg1'
- *.log_archive_dest_3='SERVICE=dg3 valid_for=(standby_logfiles,standby_role) db_unique_name=dg3'
- *.log_archive_format='%t_%s_%r.dbf'
- *.memory_target=419430400
- *.open_cursors=300
- *.processes=150
- *.remote_login_passwordfile='EXCLUSIVE'
- *.undo_tablespace='UNDOTBS1
- [oracle@dg1 ~]$ scp initdg.ora 192.168.1.62:/home/oracle/
3.3 在dg2上创建密码文件,由pfile生成spfile文件,启动数据库实例到nomount状态,通过rman进行duplicate操作,在11g中,duplicate数据库可以from active database,意味着不需要先在主库上进行rman备份,然后再将备份文件复制到备库上,在10g版本上需要这样操作,操作完成后将备库1置于active dataguard状态,即实时应用日志并只读的状态,adg也是11g dataguard非常大的一个飞跃(dg2只安装数据库软件,未建库)
- [oracle@dg2 ~]$ orapwd file=$ORACLE_HOME/dbs/orapwdg password=123456 entries=5
- [oracle@dg2 ~]$ sqlplus /nolog
- SQL*Plus: Release 11.2.0.3.0 Production on Sat Apr 7 15:40:33 2012
- Copyright (c) 1982, 2011, Oracle. All rights reserved.
- SQL> conn /as sysdba
- Connected to an idle instance.
- SQL> create spfile from pfile='/home/oracle/initdg.ora';
- File created.
- SQL> startup nomount
- ORACLE instance started.
- Total System Global Area 417546240 bytes
- Fixed Size 2228944 bytes
- Variable Size 281021744 bytes
- Database Buffers 125829120 bytes
- Redo Buffers 8466432 bytes
- [oracle@dg2 ~]$ rman target sys/123456@dg1 auxiliary sys/123456@dg2
- Recovery Manager: Release 11.2.0.3.0 - Production on Sat Apr 7 16:22:57 2012
- Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
- connected to target database: DG (DBID=1693312161)
- connected to auxiliary database: DG (not mounted)
- RMAN> list backup of database summary; //这个时候主库没有任何的物理备份
- using target database control file instead of recovery catalog
- specification does not match any backup in the repository
- RMAN> duplicate target database for standby nofilenamecheck from active database;
- ————————输出省略——————
- [oracle@dg2 ~]$ sqlplus /nolog
- SQL*Plus: Release 11.2.0.3.0 Production on Sat Apr 7 16:30:11 2012
- Copyright (c) 1982, 2011, Oracle. All rights reserved.
- SQL> conn /as sysdba
- Connected.
- SQL> select database_role,open_mode,name from v$database;
- DATABASE_ROLE OPEN_MODE NAME
- ---------------- -------------------- ---------
- PHYSICAL STANDBY MOUNTED DG
- SQL> archive log list;
- Database log mode Archive Mode
- Automatic archival Enabled
- Archive destination /u01/app/oracle/archivelog
- Oldest online log sequence 8
- Next log sequence to archive 0
- Current log sequence 10
- SQL> alter database open read only;
- Database altered.
- SQL> alter database recover managed standby database using current logfile disconnect from session;
- Database altered.
- SQL> select database_role,open_mode,name from v$database;
- DATABASE_ROLE OPEN_MODE NAME
- ---------------- -------------------- ---------
- PHYSICAL STANDBY READ ONLY WITH APPLY DG
3.4测试主库上切换日志
- SQL> alter system switch logfile;
- System altered.
- SQL> select message from v$dataguard_status;
- MESSAGE
- --------------------------------------------------------------------------------
- LNS: Completed archiving log 3 thread 1 sequence 9
- ARC0: Beginning to archive thread 1 sequence 9 (1049579-1050098)
- ARC0: Completed archiving thread 1 sequence 9 (1049579-1050098)
- LNS: Standby redo logfile selected for thread 1 sequence 10 for destination LOG_
- ARCHIVE_DEST_2
- LNS: Beginning to archive log 1 thread 1 sequence 10
- LNS: Completed archiving log 1 thread 1 sequence 10
- ARC2: Beginning to archive thread 1 sequence 10 (1050098-1050271)
- ARC2: Completed archiving thread 1 sequence 10 (1050098-1050271)
- LNS: Beginning to archive log 2 thread 1 sequence 11
- 备库上查看日志应用情况
- SQL> archive log list;
- Database log mode Archive Mode
- Automatic archival Enabled
- Archive destination /u01/app/oracle/archivelog
- Oldest online log sequence 9
- Next log sequence to archive 0
- Current log sequence 11
3.5 实际操作应用情况,发现需要主库上切换日志后,数据才会同步,也就是standby日志组未使用
- SQL> create table t1 as select * from dba_objects;
- Table created.
- SQL> alter system switch logfile;
- System altered.
- SQL> conn sys/123456@dg2 as sysdba
- Connected.
- SQL> select count(*) from t1;
- COUNT(*)
- ----------
- 74510
四:配置redo传输的cascade
4.1 将修改过的初始化文件传输到dg3上(dg3服务器上同样只安装数据库软件,不建库)
[oracle@dg2 ~]$ cat initdg.ora dg.__db_cache_size=125829120 dg.__java_pool_size=4194304 dg.__large_pool_size=4194304 dg.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment dg.__pga_aggregate_target=167772160 dg.__sga_target=251658240 dg.__shared_io_pool_size=0 dg.__shared_pool_size=104857600 dg.__streams_pool_size=0 *.audit_file_dest='/u01/app/oracle/admin/dg/adump' *.audit_trail='db' *.compatible='11.2.0.0.0' *.control_files='/u01/app/oracle/oradata/dg/control01.ctl','/u01/app/oracle/fast_recovery_area/dg/control02.ctl' *.db_block_size=8192 *.db_domain='yang.com' *.db_name='dg' *.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area' *.db_recovery_file_dest_size=4322230272 *.db_unique_name='dg3' *.diagnostic_dest='/u01/app/oracle' *.dispatchers='(PROTOCOL=TCP) (SERVICE=dgXDB)' *.log_archive_config='DG_CONFIG=(dg1,dg2,dg3)' *.log_archive_dest_1='LOCATION=/u01/app/oracle/archivelog valid_for=(all_logfiles,primary_role) db_unique_name=dg3' *.standby_archive_dest=/u01/app/oracle/standbylog *.log_archive_format='%t_%s_%r.dbf' *.memory_target=419430400 *.open_cursors=300 *.processes=150 *.remote_login_passwordfile='EXCLUSIVE' *.undo_tablespace='UNDOTBS1' |
4.2 通过pfile生成spfile,将数据库启动到nomount状态,然后进行duplicate
- [oracle@dg3 ~]$ sqlplus /nolog
- SQL*Plus: Release 11.2.0.3.0 Production on Sat Apr 14 18:01:59 2012
- Copyright (c) 1982, 2011, Oracle. All rights reserved.
- SQL> conn /as sysdba
- Connected to an idle instance.
- SQL> create spfile from pfile='/home/oracle/initdg.ora';
- File created.
- SQL> startup nomount
- ORACLE instance started.
- Total System Global Area 417546240 bytes
- Fixed Size 2228944 bytes
- Variable Size 281021744 bytes
- Database Buffers 125829120 bytes
- Redo Buffers 8466432 bytes
- [oracle@dg3 ~]$ rman target sys/123456@dg1 auxiliary sys/123456@dg3
- Recovery Manager: Release 11.2.0.3.0 - Production on Sat Apr 14 18:02:59 2012
- Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
- connected to target database: DG (DBID=1693928392)
- connected to auxiliary database: DG (not mounted)
- RMAN> duplicate target database for standby nofilenamecheck from active database;
- ————————输出省略——————
4.3 将备库dg3置于只读且应用日志模式下
- [oracle@dg3 ~]$ sqlplus /nolog
- SQL*Plus: Release 11.2.0.3.0 Production on Sat Apr 14 18:49:12 2012
- Copyright (c) 1982, 2011, Oracle. All rights reserved.
- SQL> conn /as sysdba
- Connected.
- SQL> alter database open read only;
- Database altered.
- SQL> alter database recover managed standby database using current logfile disconnect from session;
- Database altered.
- SQL> select open_mode,database_role,name from v$database;
- OPEN_MODE DATABASE_ROLE NAME
- -------------------- ---------------- ---------
- READ ONLY WITH APPLY PHYSICAL STANDBY DG
五:测试
- SQL> conn /as sysdba
- Connected.
- SQL> select open_mode,database_role,name from v$database;
- OPEN_MODE DATABASE_ROLE NAME
- -------------------- ---------------- ---------
- READ WRITE PRIMARY DG
- SQL> truncate table t1;
- Table truncated.
- SQL> conn sys/123456@dg2 as sysdba
- Connected.
- SQL> select count(*) from t1;
- COUNT(*)
- ----------
- 74510
- SQL> conn sys/123456@dg3 as sysdba
- Connected.
- SQL> select count(*) from t1;
- COUNT(*)
- ----------
- 74510
- SQL> conn /as sysdba
- Connected.
- SQL> alter system switch logfile; //主库上未切换日志前,数据不能同步
- System altered.
- SQL> conn sys/123456@dg2 as sysdba
- Connected.
- SQL> select count(*) from t1;
- COUNT(*)
- ----------
- 0
- SQL> conn sys/123456@dg3 as sysdba //在dg3上可以看到明显的延迟情况
- Connected.
- SQL> select count(*) from t1;
- COUNT(*)
- ----------
- 74510
- SQL> select count(*) from t1;
- COUNT(*)
- ----------
- 0
- SQL> select message from v$dataguard_status; //查看备库dg3的dataguard状态
- MESSAGE
- --------------------------------------------------------------------------------
- Media Recovery Log /u01/app/oracle/standbylog/1_13_780597393.dbf
- Media Recovery Waiting for thread 1 sequence 14
- FAL[client]: Error fetching gap sequence, no FAL server specified
- RFS[1]: Assigned to RFS process 2701
- Media Recovery Log /u01/app/oracle/archivelog/1_14_780597393.dbf
- Media Recovery Waiting for thread 1 sequence 15
- FAL[client]: Error fetching gap sequence, no FAL server specified
- 18 rows selected.
- SQL> alter system set fal_server='dg2';
- System altered.
- SQL> alter system set fal_client='dg3';
- System altered.
总结:
1:在测试上,可以将主库的log_archive_dest_state_3参数设置为defer,然后切换日志,观察dg2,dg3的日志传输情况
2:在本文档中没有设置standby_file_management参数,因为不涉及新建数据文件的操作
3:在dg1和dg2上均未设置fal_server和fal_client参数,因为此处不考虑dg的角色切换问题,纯粹测试redo日志的cascade传输
4:本文档未能成功实现adg,猜想和几个归档日志路径配置的参数相关,后续将继续测试!
本文出自 “斩月” 博客,谢绝转载!