五一假期期间,闲来无事,测试了下oracle 11g异构下的dataguard,主库采用rhel5.4 64位系统,备库采用winxp sp1 32位系统,数据库软件采用当前最新的11.2.0.3版本!事先声明,本文只用于测试环境,各位看官若用在生产环境,请三思,且慎重!
环境介绍:
主库
IP地址:192.168.1.63/24
操作系统版本:rhel5.4 64bit
数据库版本:11.2.0.3 64bit
数据库sid名:dg
数据库名:dg
数据库db_unique_name:dg3
备库1 物理备库
IP地址:192.168.1.103/24
操作系统版本:winxp sp1 32位(有条件的话应该用win2003 server版)
数据库版本:11.2.0.3 32bit
数据库sid名:dg
数据库名:dg
数据库db_unique_name:dg4
在开始之前,还是先上MOS上找找相关的资料,看看能不能做!
主库id为13的情况下,备库id可以选择为7,但是必须要11g以后,且要搞定bug13104881
貌似这个bug在11.2.0.3中没有被修复,但是认真看下,这个bug只影响主库为windows,备库为linux的情况,也就是说,本例是个灰色地带了,那就用实践证明下吧!
一:配置主,备库的listener.ora和tnsnames.ora文件如下
- [oracle@dg3 ~]$ cat $TNS_ADMIN/listener.ora
- SID_LIST_LISTENER =
- (SID_LIST =
- (SID_DESC =
- (GLOBAL_DBNAME = dg.yang.com)
- (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db1)
- (SID_NAME = dg)
- )
- )
- LISTENER =
- (DESCRIPTION_LIST =
- (DESCRIPTION =
- (ADDRESS_LIST =
- (ADDRESS = (PROTOCOL = TCP)(HOST = dg3.yang.com)(PORT = 1521))
- )
- )
- )
- [oracle@dg3 ~]$ cat $TNS_ADMIN/tnsnames.ora
- DG3 =
- (DESCRIPTION =
- (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.63)(PORT = 1521))
- (CONNECT_DATA =
- (SERVER = DEDICATED)
- (SERVICE_NAME = dg2.yang.com)
- )
- )
- DG4 =
- (DESCRIPTION =
- (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.103)(PORT = 1521))
- (CONNECT_DATA =
- (SERVER = DEDICATED)
- (SERVICE_NAME = dg4.yang.com)
- )
- )
- C:\app\oracle\product\11.2.0\dbhome_1\NETWORK\ADMIN\listener.ora
- SID_LIST_LISTENER =
- (SID_LIST =
- (SID_DESC =
- (SID_NAME = dg)
- (ORACLE_HOME = C:\app\oracle\product\11.2.0\dbhome_1)
- (GLOBAL_DBNAME=dg.yang.com)
- )
- )
- LISTENER =
- (DESCRIPTION_LIST =
- (DESCRIPTION =
- (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.1.103)(PORT = 1521))
- )
- )
- ADR_BASE_LISTENER = C:\app\oracle
- C:\app\oracle\product\11.2.0\dbhome_1\NETWORK\ADMIN\tnsnames.ora
- DG3 =
- (DESCRIPTION =
- (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.63)(PORT = 1521))
- (CONNECT_DATA =
- (SERVER = DEDICATED)
- (SERVICE_NAME = dg.yang.com)
- )
- )
- DG4 =
- (DESCRIPTION =
- (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.103)(PORT = 1521))
- (CONNECT_DATA =
- (SERVER = DEDICATED)
- (SERVICE_NAME = dg.yang.com)
- )
- )
- C:\>lsnrctl services
- LSNRCTL for 32-bit Windows: Version 11.2.0.3.0 - Production on 30-4月 -2012 16:0
- 5:13
- Copyright (c) 1991, 2011, Oracle. All rights reserved.
- 正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.103)(PORT=1521)))
- 服务摘要..
- 服务 "dg.yang.com" 包含 1 个实例。
- 实例 "dg", 状态 UNKNOWN, 包含此服务的 1 个处理程序...
- 处理程序:
- "DEDICATED" 已建立:0 已被拒绝:0
- LOCAL SERVER
- 命令执行成功
二:在主库上修改dg相关的参数,异构DG下,文件系统的路径一定不一致,所以需要注意db_file_name_convert和log_file_name_convert两个初始化参数的设置
- [oracle@dg3 ~]$ sqlplus /nolog
- SQL*Plus: Release 11.2.0.3.0 Production on Mon Apr 30 16:09:15 2012
- Copyright (c) 1982, 2011, Oracle. All rights reserved.
- SQL> conn /as sysdba
- Connected.
- SQL> alter database force logging;
- Database altered.
- SQL> alter system set db_unique_name='dg3' scope=spfile;
- System altered.
- SQL> alter system set log_archive_config='DG_CONFIG=(dg3,dg4)';
- System altered.
- SQL> alter system set log_archive_dest_1='LOCATION=/u01/app/oracle/archivelog valid_for=(all_logfiles,primary_role) db_unique_name=dg3' scope=spfile;
- System altered.
- SQL> alter system set log_archive_dest_2='SERVICE=dg4 lgwr sync valid_for=(online_logfile,primary_role)
- db_unique_name=dg4';
- System altered.
- SQL> alter system set log_archive_dest_3='LOCATION=/u01/app/oracle/standbylog valid_for=(standby_logfile,standby_role) db_unique_name=dg3' scope=spfile;
- System altered.
- SQL> alter system set fal_server='dg4';
- System altered.
- SQL> alter system set fal_client='dg3';
- System altered.
- SQL> alter system set standby_file_management='auto';
- System altered.
- SQL> alter system set db_file_name_convert='/u01/app/oracle/oradata/dg','c:\app\oracle\oradata\dg' scope=spfile;
- System altered.
- SQL> alter system set log_file_name_convert=''/u01/app/oracle/oradata/dg','c:\app\oracle\oradata\dg' scope=spfile;
- System altered.
- SQL> alter system set log_archive_dest_state_3='defer';
- System altered.
三:重启主库后,添加standby日志组,并根据spfile文件生成pfile文件
- 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 327159088 bytes
- Database Buffers 79691776 bytes
- Redo Buffers 8466432 bytes
- Database mounted.
- Database opened.
- SQL> alter database add standby logfile group 4 '/u01/app/oracle/oradata/dg/standby04.dbf' size 50M;
- Database altered.
- SQL> alter database add standby logfile group 5 '/u01/app/oracle/oradata/dg/standby05.dbf' size 50M;
- Database altered.
- SQL> alter database add standby logfile group 6 '/u01/app/oracle/oradata/dg/standby06.dbf' size 50M;
- Database altered.
- SQL> alter database add standby logfile group 7 '/u01/app/oracle/oradata/dg/standby07.dbf' size 50M;
- Database altered.
- SQL> create pfile='/home/oracle/initdg.ora' from spfile;
- File created.
四:修改pfile文件如下,注意红色字体部分,修改完成后将文件传输到备库,winscp,samba,ftp啦,这里大家就各显神通吧!
[oracle@dg3 ~]$ cat initdg.ora |
五:配置备库,windows平台的oracle和linux很不一样,linux平台下备库只需要安装数据库软件即可,而在windows平台下,需要先建库,否则使用conn /as sysdba方式登录数据库会提示下图中的错误,主要是因为相关的windows服务不存在!不知道这里是不是可以采取其他的方法解决,在本例中,先使用dbca创建一个数据库,实例名和数据库均为dg,然后关闭数据库实例后,删除对应的数据文件!
六:启动备库到nomount状态,在主库端检测数据库的是否可以正常连接
- C:\>sqlplus /nolog
- SQL*Plus: Release 11.2.0.3.0 Production on 星期一 4月 30 16:37:06
- Copyright (c) 1982, 2011, Oracle. All rights reserved.
- SQL> conn /as sysdba
- 已连接到空闲例程。
- SQL> create spfile from pfile='c:\initdg.ora';
- 文件已创建。
- SQL> startup nomount
- ORACLE 例程已经启动。
- Total System Global Area 418484224 bytes
- Fixed Size 1385052 bytes
- Variable Size 327159204 bytes
- Database Buffers 83886080 bytes
- Redo Buffers 6053888 bytes
- [oracle@dg3 admin]$ sqlplus sys/123456@dg3 as sysdba
- SQL*Plus: Release 11.2.0.3.0 Production on Mon Apr 30 16:47:26 2012
- Copyright (c) 1982, 2011, Oracle. All rights reserved.
- Connected to:
- Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
- With the Partitioning, OLAP, Data Mining and Real Application Testing options
- SQL> select * from v$version;
- BANNER
- --------------------------------------------------------------------------------
- Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
- PL/SQL Release 11.2.0.3.0 - Production
- CORE 11.2.0.3.0 Production
- TNS for Linux: Version 11.2.0.3.0 - Production
- NLSRTL Version 11.2.0.3.0 - Production
- SQL> exit
- Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
- With the Partitioning, OLAP, Data Mining and Real Application Testing options
- [oracle@dg3 admin]$ sqlplus sys/123456@dg4 as sysdba
- SQL*Plus: Release 11.2.0.3.0 Production on Mon Apr 30 16:47:32 2012
- Copyright (c) 1982, 2011, Oracle. All rights reserved.
- Connected to:
- Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
- With the Partitioning, OLAP, Data Mining and Real Application Testing options
- SQL> select * from v$version;
- BANNER
- --------------------------------------------------------------------------------
- Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
- PL/SQL Release 11.2.0.3.0 - Production
- CORE 11.2.0.3.0 Production
- TNS for 32-bit Windows: Version 11.2.0.3.0 - Production
- NLSRTL Version 11.2.0.3.0 - Production
- SQL> exit
- Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
- With the Partitioning, OLAP, Data Mining and Real Application Testing options
七:在主库上使用rman进行duplicate操作
[oracle@dg3 ~]$ rman target sys/123456@dg3 auxiliary sys/123456@dg4 connected to target database: DG (DBID=1695308537) RMAN> duplicate target database for standby from active database; Starting Duplicate Db at 2012-04-30-17:16:48 contents of Memory Script: Starting backup at 2012-04-30-17:16:49 contents of Memory Script: Starting backup at 2012-04-30-17:16:51 STAMP=781982213 Starting restore at 2012-04-30-17:16:58 channel ORA_AUX_DISK_1: copied control file copy contents of Memory Script: sql statement: alter database mount standby database contents of Memory Script: executing command: SET NEWNAME renamed tempfile 1 to C:\APP\ORACLE\ORADATA\DG\TEMP01.DBF in control file executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME Starting backup at 2012-04-30-17:17:12 sql statement: alter system archive log current contents of Memory Script: datafile 1 switched to datafile copy |
八:检查主库的数据文件和日志文件,将备库置于ADG模式下
- [oracle@dg3 ~]$ sqlplus sys/123456@dg4 as sysdba
- SQL*Plus: Release 11.2.0.3.0 Production on Mon Apr 30 17:24:59 2012
- Copyright (c) 1982, 2011, Oracle. All rights reserved.
- Connected to:
- Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
- With the Partitioning, OLAP, Data Mining and Real Application Testing options
- SQL> select member from v$logfile;
- MEMBER
- --------------------------------------------------------------------------------
- C:\APP\ORACLE\ORADATA\DG\REDO03.LOG
- C:\APP\ORACLE\ORADATA\DG\REDO02.LOG
- C:\APP\ORACLE\ORADATA\DG\REDO01.LOG
- C:\APP\ORACLE\ORADATA\DG\STANDBY04.DBF
- C:\APP\ORACLE\ORADATA\DG\STANDBY05.DBF
- C:\APP\ORACLE\ORADATA\DG\STANDBY06.DBF
- C:\APP\ORACLE\ORADATA\DG\STANDBY07.DBF
- 7 rows selected.
- SQL> select name from v$datafile;
- NAME
- --------------------------------------------------------------------------------
- C:\APP\ORACLE\ORADATA\DG\SYSTEM01.DBF
- C:\APP\ORACLE\ORADATA\DG\SYSAUX01.DBF
- C:\APP\ORACLE\ORADATA\DG\UNDOTBS01.DBF
- C:\APP\ORACLE\ORADATA\DG\USERS01.DBF
- SQL> select open_mode,database_role,db_unique_name from v$database;
- OPEN_MODE DATABASE_ROLE DB_UNIQUE_NAME
- -------------------- ---------------- ------------------------------
- MOUNTED PHYSICAL STANDBY dg4
- SQL> alter database open;
- Database altered.
- SQL> select open_mode,database_role,db_unique_name from v$database;
- OPEN_MODE DATABASE_ROLE DB_UNIQUE_NAME
- -------------------- ---------------- ------------------------------
- READ ONLY PHYSICAL STANDBY dg4
- SQL> alter database recover managed standby database using current logfile disconnect from session;
- Database altered.
- SQL> select open_mode,database_role,db_unique_name from v$database;
- OPEN_MODE DATABASE_ROLE DB_UNIQUE_NAME
- -------------------- ---------------- ------------------------------
- READ ONLY WITH APPLY PHYSICAL STANDBY dg4
- SQL> archive log list;
- Database log mode Archive Mode
- Automatic archival Enabled
- Archive destination c:\app\oracle\standbylog
- Oldest online log sequence 14
- Next log sequence to archive 0
- Current log sequence 14
- SQL> select applied,sequence# from v$archived_log where sequence# >10;
- APPLIED SEQUENCE#
- --------- ----------
- YES 12
- YES 11
- IN-MEMORY 13
九:测试数据是否实时同步
- SQL> archive log list;
- Database log mode Archive Mode
- Automatic archival Enabled
- Archive destination /u01/app/oracle/standbylog
- Oldest online log sequence 12
- Next log sequence to archive 14
- Current log sequence 14
- SQL> create table t as select * from v$database;
- Table created.
- SQL> conn sys/123456@dg4 as sysdba
- Connected.
- SQL> desc t;
- Name Null? Type
- ----------------------------------------- -------- ----------------------------
- DBID NUMBER
- NAME VARCHAR2(9)
- CREATED DATE
- RESETLOGS_CHANGE# NUMBER
- RESETLOGS_TIME DATE
- PRIOR_RESETLOGS_CHANGE# NUMBER
- PRIOR_RESETLOGS_TIME DATE
- LOG_MODE VARCHAR2(12)
- CHECKPOINT_CHANGE# NUMBER
- ARCHIVE_CHANGE# NUMBER
- CONTROLFILE_TYPE VARCHAR2(7)
- CONTROLFILE_CREATED DATE
- CONTROLFILE_SEQUENCE# NUMBER
- CONTROLFILE_CHANGE# NUMBER
- CONTROLFILE_TIME DATE
- OPEN_RESETLOGS VARCHAR2(11)
- VERSION_TIME DATE
- OPEN_MODE VARCHAR2(20)
- PROTECTION_MODE VARCHAR2(20)
- PROTECTION_LEVEL VARCHAR2(20)
- REMOTE_ARCHIVE VARCHAR2(8)
- ACTIVATION# NUMBER
- SWITCHOVER# NUMBER
- DATABASE_ROLE VARCHAR2(16)
- ARCHIVELOG_CHANGE# NUMBER
- ARCHIVELOG_COMPRESSION VARCHAR2(8)
- SWITCHOVER_STATUS VARCHAR2(20)
- DATAGUARD_BROKER VARCHAR2(8)
- GUARD_STATUS VARCHAR2(7)
- SUPPLEMENTAL_LOG_DATA_MIN VARCHAR2(8)
- SUPPLEMENTAL_LOG_DATA_PK VARCHAR2(3)
- SUPPLEMENTAL_LOG_DATA_UI VARCHAR2(3)
- FORCE_LOGGING VARCHAR2(3)
- PLATFORM_ID NUMBER
- PLATFORM_NAME VARCHAR2(101)
- RECOVERY_TARGET_INCARNATION# NUMBER
- LAST_OPEN_INCARNATION# NUMBER
- CURRENT_SCN NUMBER
- FLASHBACK_ON VARCHAR2(18)
- SUPPLEMENTAL_LOG_DATA_FK VARCHAR2(3)
- SUPPLEMENTAL_LOG_DATA_ALL VARCHAR2(3)
- DB_UNIQUE_NAME VARCHAR2(30)
- STANDBY_BECAME_PRIMARY_SCN NUMBER
- FS_FAILOVER_STATUS VARCHAR2(22)
- FS_FAILOVER_CURRENT_TARGET VARCHAR2(30)
- FS_FAILOVER_THRESHOLD NUMBER
- FS_FAILOVER_OBSERVER_PRESENT VARCHAR2(7)
- FS_FAILOVER_OBSERVER_HOST VARCHAR2(512)
- CONTROLFILE_CONVERTED VARCHAR2(3)
- PRIMARY_DB_UNIQUE_NAME VARCHAR2(30)
- SUPPLEMENTAL_LOG_DATA_PL VARCHAR2(3)
- MIN_REQUIRED_CAPTURE_CHANGE# NUMBER