合 Oracle 主库rac + 备库rac 11.2.0.4的DG环境部署
前言部分
导读和注意事项
各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学到一些其它你所不知道的知识,~O(∩_∩)O~:
① 主库为rac,备库为rac的物理dg的搭建(重点)
② dbca 静默方式创建rac数据库
③ 如何将数据库加入crsctl管理
④ rac库修改归档路径和归档模式
⑤ 如何添加standby日志
⑥ 简单物理dg的维护
本文简介
虽然之前已经多次安装过dg了,但都是基于单实例的,无论是物理还是逻辑的,感觉都非常轻松,没有碰到大的问题,但是最近同事安装dg老是碰到问题,尤其是在执行duplicate命令的时候报错,所以我想还是自己也搭建的试试吧,顺便也写写文档。
相关知识点扫盲
Physical Standby使用的是Media Recovery 技术,在数据块级别进行恢复,这种方式没有数据类型的限制,可以保证两个数据库完全一致。 Physical Standby数据库只能在Mount 状态下进行恢复,也可以是打开,但只能已只读方式打开,并且打开时不能执行恢复操作。Logical Standby使用的是Logminer 技术,通过把日志内容还原成SQL 语句,然后SQL引擎执行这些语句,Logminer Standby不支持所有数据类型,可以在视图DBA_LOGSTDBY_UNSUPPORTED 中查看不支持的数据类型,如果使用了这种数据类型,则不能保证数据库完全一致。LogicalStandby数据库可以在恢复的同时进行读写操作。
不少未实际接触过dg的初学者可能会下意识以为data guard是一个备份恢复的工具。我要说的是,这种形容不完全错,dg拥有备份的功能,某些情况下它甚至可以与primary数据库完全一模一样,但是它存在的目的并不仅仅是为了恢复数据,应该说它的存在是为了 确保企业数据的高可用性,数据保护以及灾难恢复 ( 注意这个字眼,灾难恢复) 。dg提供全面的服务包括:创建,维护,管理以及监控standby数据库,确保数据安全,管理员可以通过将一些操作转移到standby数据库执行的方式改善数据库性能 ,构建高可用的企业数据库应用环境。
在Data Gurad 环境中,至少有两个数据库,一个处于Open 状态对外提供服务,这个数据库叫作Primary Database。 第二个处于恢复状态,叫作Standby Database。 运行时primary Database 对外提供服务,用户在Primary Database 上进行操作,操作被记录在联机日志和归档日志中,这些日志通过网络传递给Standby Database。 这个日志会在Standby Database 上重演,从而实现Primary Database 和Standby Database 的数据同步。
Oracle Data Gurad 对这一过程进一步的优化设计,使得日志的传递,恢复工作更加自动化,智能化,并且提供一系列参数和命令简化了DBA工作。
如果是可预见因素需要关闭Primary Database,比如软硬件升级,可以把Standby Database 切换为Primary Database 继续对外服务,这样即减少了服务停止时间,并且数据不会丢失。如果异常原因导致Primary Database 不可用,也可以把Standby Database 强制切换为Primary Database继续对外服务,这时数据损失都和配置的数据保护级别有关系。因此Primary 和Standby 只是一个角色概念,并不固定在某个数据库中。
问题:RAC 和DG 有什么区别
RAC, Data Gurad, 高可用性体系中的二种工具,每个工具即可以独立应用,也可以相互配合。 他们各自的侧重点不同,适用场景也不同。
RAC 它的强项在于解决单点故障和负载均衡,因此RAC 方案常用于7*24 的核心系统,但RAC 方案中的数据只有一份,尽管可以通过RAID 等机制可以避免存储故障,但是数据本身是没有冗余的,容易形成单点故障。
Data Gurad 通过冗余数据来提供数据保护,Data Gurad 通过日志同步机制保证冗余数据和主数据之前的同步,这种同步可以是实时,延时,同步,异步多种形式。Data Gurad 常用于异地容灾和小企业的高可用性方案,虽然可以在Standby 机器上执行只读查询,从而分散Primary 数据库的性能压力,但是Data Gurad 决不是性能解决方案。
实验部分
创建物理备库的方法很多,对于Oracle 11g而言,可以直接从active database来创建,也可以基于10g 的RMAN备份方式来创建。
实验环境介绍
项目 | primary db | physical standby db |
---|---|---|
db 类型 | rac | rac |
db version | 11.2.0.4.0 | 11.2.0.4.0 |
db 存储 | ASM | ASM |
主机IP地址/hosts配置 | 22.188.194.31 LHRAXXTDB3 22.188.194.33 LHRAXXTDB3-vip 222.188.194.31 LHRAXXTDB3-priv 22.188.194.32 LHRAXXTDB4 22.188.194.34 LHRAXXTDB4-vip 222.188.194.32 LHRAXXTDB4-priv 22.188.194.35 LHRAXXTDB-scan | 22.188.194.64 LHRAXXTDB1 22.188.194.65 LHRAXXTDB1-vip 222.188.194.64 LHRAXXTDB1-priv 22.188.194.66 LHRAXXTDB2 22.188.194.67 LHRAXXTDB2-vip 222.188.194.66 LHRAXXTDB2-priv 22.188.194.68 LHRAXXTDB-scan |
OS版本及kernel版本 | AIX 64位 7.1.0.0 | AIX 64位 7.1.0.0 |
OS hostname | LHRAXXTDB3 LHRAXXTDB4 | LHRAXXTDB1 LHRAXXTDB2 |
platform_name | AIX-Based Systems (64-bit) | AIX-Based Systems (64-bit) |
db time zone | 14 | 14 |
字符集 | ZHS16GBK | ZHS16GBK |
compatible | 11.2.0.4.0 | 11.2.0.4.0 |
归档模式 | Archive Mode | Archive Mode |
ORACLE_SID | DGPRI | DGPHY |
db_name/GLOBAL_DBNAME | TESTDG | TESTDG |
db_unique_name | TESTDG | TESTDGPHY |
TNS_NAME | TNS_DGPRI | TNS_DGPHY |
磁盘组 | +DATA | +DATA |
归档路径 | GPFS方式共享路径: /arch | GPFS方式共享路径: /arch |
ORACLE_HOME | /oracle/app/oracle/product/11.2.0/db | /oracle/app/oracle/product/11.2.0/db |
dbid | 2836886746 | 2836886746 |
注:标红的选项是必填,且需要特别关注的项目 |
该环境中我主要是为了区分dg中各种参数配置的是tnsnames、oracle_sid、dbname还是db_unique_name,所以设置的值不同,一般情况这4者可以设置成一样的,dg中db_unique_name、oracle_sid和tns可以设置成一样的。
主库操作
先创建主库
1 2 | dbca -silent -createDatabase -templateName General_Purpose.dbc -gdbname TESTDG -sid DGPRI -sysPassword lhr -systemPassword lhr -datafileDestination 'DATA/' -redoLogFileSize 50 -recoveryAreaDestination '/arch' -storageType ASM -asmsnmpPassword lhr -diskGroupName 'DATA' -responseFile NO_VALUE -characterset ZHS16GBK -nationalCharacterSet AL16UTF16 -sampleSchema true -automaticMemoryManagement true -totalMemory 1024 -nodeinfo LHRAXXTDB3,LHRAXXTDB4 |
注意:sid不能含有下横线,如DG_PRI会报错:
The SID name can only contain alphanumeric characters.
静默方式创建一个rac主库:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | [LHRAXXTDB3:root]:/>crsctl stat res -t -------------------------------------------------------------------------------- NAME TARGET STATE SERVER STATE_DETAILS -------------------------------------------------------------------------------- Local Resources -------------------------------------------------------------------------------- ora.DATA.dg ONLINE ONLINE LHRAXXTDB3 ONLINE ONLINE LHRAXXTDB4 ora.LISTENER.lsnr ONLINE ONLINE LHRAXXTDB3 ONLINE ONLINE LHRAXXTDB4 ora.asm ONLINE ONLINE LHRAXXTDB3 Started ONLINE ONLINE LHRAXXTDB4 Started ora.gsd OFFLINE OFFLINE LHRAXXTDB3 OFFLINE OFFLINE LHRAXXTDB4 ora.net1.network ONLINE ONLINE LHRAXXTDB3 ONLINE ONLINE LHRAXXTDB4 ora.ons ONLINE ONLINE LHRAXXTDB3 ONLINE ONLINE LHRAXXTDB4 ora.registry.acfs ONLINE ONLINE LHRAXXTDB3 ONLINE ONLINE LHRAXXTDB4 -------------------------------------------------------------------------------- Cluster Resources -------------------------------------------------------------------------------- ora.LISTENER_SCAN1.lsnr 1 ONLINE ONLINE LHRAXXTDB4 ora.cvu 1 ONLINE ONLINE LHRAXXTDB4 ora.oc4j 1 ONLINE ONLINE LHRAXXTDB4 ora.oradesdb.db 1 ONLINE ONLINE LHRAXXTDB3 Open,Readonly 2 ONLINE ONLINE LHRAXXTDB4 Open,Readonly ora.scan1.vip 1 ONLINE ONLINE LHRAXXTDB4 ora.testdg.db 1 OFFLINE OFFLINE 2 OFFLINE OFFLINE ora.LHRAXXTDB3.vip 1 ONLINE ONLINE LHRAXXTDB3 ora.LHRAXXTDB4.vip 1 ONLINE ONLINE LHRAXXTDB4 [LHRAXXTDB3:root]:/>cat /etc/hosts # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # bos61D src/bos/usr/sbin/netstart/hosts 1.2 # # Licensed Materials - Property of IBM # # COPYRIGHT International Business Machines Corp. 1985,1989 # All Rights Reserved # # US Government Users Restricted Rights - Use, duplication or # disclosure restricted by GSA ADP Schedule Contract with IBM Corp. # # @(#)47 1.2 src/bos/usr/sbin/netstart/hosts, cmdnet, bos61D, d2007_49A2 10/1/07 13:57:52 # IBM_PROLOG_END_TAG # # COMPONENT_NAME: TCPIP hosts # # FUNCTIONS: loopback # # ORIGINS: 26 27 # # (C) COPYRIGHT International Business Machines Corp. 1985, 1989 # All Rights Reserved # Licensed Materials - Property of IBM # # US Government Users Restricted Rights - Use, duplication or # disclosure restricted by GSA ADP Schedule Contract with IBM Corp. # # /etc/hosts # # This file contains the hostnames and their address for hosts in the # network. This file is used to resolve a hostname into an Internet # address. # # At minimum, this file must contain the name and address for each # device defined for TCP in your /etc/net file. It may also contain # entries for well-known (reserved) names such as timeserver # and printserver as well as any other host name and address. # # The format of this file is: # Internet Address Hostname # Comments # Internet Address can be either IPv4 or IPv6 address. # Items are separated by any number of blanks and/or tabs. A '#' # indicates the beginning of a comment; characters up to the end of the # line are not interpreted by routines which search this file. Blank # lines are allowed. # Internet Address Hostname # Comments # 192.9.200.1 net0sample # ethernet name/address # 128.100.0.1 token0sample # token ring name/address # 10.2.0.2 x25sample # x.25 name/address # 2000:1:1:1:209:6bff:feee:2b7f ipv6sample # ipv6 name/address 127.0.0.1 loopback localhost # loopback (lo0) name/address ::1 loopback localhost # IPv6 loopback (lo0) name/address 172.16.5.242 ZBNIM 22.188.129.254 aix7nim 22.188.189.42 ZFBKUPSVR 22.188.129.240 ZTINIMSERVER ZTI17 22.188.129.202 ZTDNETAP3 count_dest 22.188.189.42 ZFBKUPSVR 22.188.194.31 LHRAXXTDB3 22.188.194.33 LHRAXXTDB3-vip 222.188.194.31 LHRAXXTDB3-priv 22.188.194.32 LHRAXXTDB4 22.188.194.34 LHRAXXTDB4-vip 222.188.194.32 LHRAXXTDB4-priv 22.188.194.35 LHRAXXTDB-scan [LHRAXXTDB3:root]:/> [LHRAXXTDB3:root]:/>oslevel 7.1.0.0 [LHRAXXTDB3:root]:/>su - oracle [LHRAXXTDB3:oracle]:/oracle>dbca -silent -createDatabase -templateName General_Purpose.dbc -gdbname TESTDG -sid DGPRI -sysPassword lhr -systemPassword lhr -datafileDestination 'DATA/' -redoLogFileSize 50 -recoveryAreaDestination '/arch' -storageType ASM -asmsnmpPassword lhr -diskGroupName 'DATA' -responseFile NO_VALUE -characterset ZHS16GBK -nationalCharacterSet AL16UTF16 -sampleSchema true -automaticMemoryManagement true -totalMemory 1024 -nodeinfo LHRAXXTDB3,LHRAXXTDB4 Copying database files 1% complete 3% complete 30% complete Creating and starting Oracle instance 32% complete 36% complete 40% complete 44% complete 45% complete 48% complete 50% complete Creating cluster database views 52% complete 70% complete Completing Database Creation 73% complete 76% complete 85% complete 94% complete 100% complete Look at the log file "/oracle/app/oracle/cfgtoollogs/dbca/TESTDG/TESTDG.log" for further details. [LHRAXXTDB3:oracle]:/oracle>more /oracle/app/oracle/cfgtoollogs/dbca/TESTDG/TESTDG.log Copying database files DBCA_PROGRESS : 1% DBCA_PROGRESS : 3% DBCA_PROGRESS : 30% Creating and starting Oracle instance DBCA_PROGRESS : 32% DBCA_PROGRESS : 36% DBCA_PROGRESS : 40% DBCA_PROGRESS : 44% DBCA_PROGRESS : 45% DBCA_PROGRESS : 48% DBCA_PROGRESS : 50% Creating cluster database views DBCA_PROGRESS : 52% DBCA_PROGRESS : 70% Completing Database Creation DBCA_PROGRESS : 73% DBCA_PROGRESS : 76% DBCA_PROGRESS : 85% DBCA_PROGRESS : 94% DBCA_PROGRESS : 100% Database creation complete. For details check the logfiles at: /oracle/app/oracle/cfgtoollogs/dbca/TESTDG. Database Information: Global Database Name:TESTDG System Identifier(SID) Prefix:DGPRI [LHRAXXTDB3:oracle]:/oracle> [LHRAXXTDB3:oracle]:/oracle>crsctl stat res -t -------------------------------------------------------------------------------- NAME TARGET STATE SERVER STATE_DETAILS -------------------------------------------------------------------------------- Local Resources -------------------------------------------------------------------------------- ora.DATA.dg ONLINE ONLINE LHRAXXTDB3 ONLINE ONLINE LHRAXXTDB4 ora.LISTENER.lsnr ONLINE ONLINE LHRAXXTDB3 ONLINE ONLINE LHRAXXTDB4 ora.asm ONLINE ONLINE LHRAXXTDB3 Started ONLINE ONLINE LHRAXXTDB4 Started ora.gsd OFFLINE OFFLINE LHRAXXTDB3 OFFLINE OFFLINE LHRAXXTDB4 ora.net1.network ONLINE ONLINE LHRAXXTDB3 ONLINE ONLINE LHRAXXTDB4 ora.ons ONLINE ONLINE LHRAXXTDB3 ONLINE ONLINE LHRAXXTDB4 ora.registry.acfs ONLINE ONLINE LHRAXXTDB3 ONLINE ONLINE LHRAXXTDB4 -------------------------------------------------------------------------------- Cluster Resources -------------------------------------------------------------------------------- ora.LISTENER_SCAN1.lsnr 1 ONLINE ONLINE LHRAXXTDB4 ora.cvu 1 ONLINE ONLINE LHRAXXTDB4 ora.oc4j 1 ONLINE ONLINE LHRAXXTDB4 ora.oradesdb.db 1 ONLINE ONLINE LHRAXXTDB3 Open,Readonly 2 ONLINE ONLINE LHRAXXTDB4 Open,Readonly ora.scan1.vip 1 ONLINE ONLINE LHRAXXTDB4 ora.testdg.db 1 ONLINE ONLINE LHRAXXTDB3 Open 2 ONLINE ONLINE LHRAXXTDB4 Open ora.LHRAXXTDB3.vip 1 ONLINE ONLINE LHRAXXTDB3 ora.LHRAXXTDB4.vip 1 ONLINE ONLINE LHRAXXTDB4 [LHRAXXTDB3:root]:/> |
主库前期准备
force logging + archivelog
- 创建一个用户lhr用于测试
- 修改主库为force logging模式
- 修改主库为归档模式
select INST_ID, dbid,name,DB_UNIQUE_NAME,current_scn,protection_mode,database_role,force_logging,open_mode,switchover_status from gv$database;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | [LHRAXXTDB3:oracle]:/oracle>export ORACLE_SID=DGPRI1 [LHRAXXTDB3:oracle]:/oracle>sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Wed Feb 17 11:19:24 2016 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options SYS@DGPRI1> create user lhr identified by lhr; User created. SYS@DGPRI1> grant dba to lhr; Grant succeeded. SYS@DGPRI1> set line 9999 SYS@DGPRI1> select name , open_mode, log_mode,force_logging,DATABASE_ROLE,switchover_status from gv$database; NAME OPEN_MODE LOG_MODE FOR DATABASE_ROLE SWITCHOVER_STATUS --------- -------------------- ------------ --- ---------------- -------------------- TESTDG READ WRITE NOARCHIVELOG NO PRIMARY NOT ALLOWED TESTDG READ WRITE NOARCHIVELOG NO PRIMARY NOT ALLOWED SYS@DGPRI1> alter database force logging; Database altered. SYS@DGPRI1> select name , open_mode, log_mode,force_logging,DATABASE_ROLE,switchover_status from gv$database; NAME OPEN_MODE LOG_MODE FOR DATABASE_ROLE SWITCHOVER_STATUS --------- -------------------- ------------ --- ---------------- -------------------- TESTDG READ WRITE NOARCHIVELOG YES PRIMARY NOT ALLOWED TESTDG READ WRITE NOARCHIVELOG YES PRIMARY NOT ALLOWED SYS@DGPRI1> alter system set log_archive_dest_1='LOCATION=/arch' scope=spfile sid='DGPRI1'; alter system set log_archive_dest_1='LOCATION=/arch' scope=spfile sid='DGPRI2'; alter system set log_archive_dest_1='LOCATION=/arch' scope=spfile sid='*'; host srvctl stop database -d TESTDG -o immediate host srvctl status database -d TESTDG host srvctl start database -d TESTDG -o mount alter database archivelog; 修改rac主库为归档模式: SYS@DGPRI1> alter system set log_archive_dest_1='LOCATION=/arch' scope=spfile sid='DGPRI1'; System altered. SYS@DGPRI1> alter system set log_archive_dest_1='LOCATION=/arch' scope=spfile sid='DGPRI2'; System altered. SYS@DGPRI1> host srvctl stop database -d TESTDG -o immediate SYS@DGPRI1> host srvctl status database -d TESTDG Instance DGPRI1 is not running on node LHRAXXTDB3 Instance DGPRI2 is not running on node LHRAXXTDB4 SYS@DGPRI1> host srvctl start database -d TESTDG -o mount SYS@DGPRI1> archive log list; ORA-03135: connection lost contact SYS@DGPRI1> conn / as sysdba Connected. SYS@DGPRI1> alter database archivelog; Database altered. SYS@DGPRI1> set line 9999 SYS@DGPRI1> select name , open_mode, log_mode,force_logging,DATABASE_ROLE,switchover_status from gv$database; NAME OPEN_MODE LOG_MODE FOR DATABASE_ROLE SWITCHOVER_STATUS --------- -------------------- ------------ --- ---------------- -------------------- TESTDG MOUNTED ARCHIVELOG YES PRIMARY NOT ALLOWED TESTDG MOUNTED ARCHIVELOG YES PRIMARY NOT ALLOWED SYS@DGPRI1> archive log list; Database log mode Archive Mode Automatic archival Enabled Archive destination /arch Oldest online log sequence 5 Next log sequence to archive 6 Current log sequence 6 SYS@DGPRI1> alter database open; Database altered. SYS@DGPRI1> select name , open_mode, log_mode,force_logging,DATABASE_ROLE,switchover_status from gv$database; NAME OPEN_MODE LOG_MODE FOR DATABASE_ROLE SWITCHOVER_STATUS --------- -------------------- ------------ --- ---------------- -------------------- TESTDG READ WRITE ARCHIVELOG YES PRIMARY NOT ALLOWED TESTDG MOUNTED ARCHIVELOG YES PRIMARY NOT ALLOWED SYS@DGPRI1> 启动第二个节点: [LHRAXXTDB4:root]:/>ORACLE_SID=DGPRI2 [LHRAXXTDB4:root]:/>su - oracle [LHRAXXTDB4:oracle]:/oracle>ORACLE_SID=DGPRI2 [LHRAXXTDB4:oracle]:/oracle>sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Wed Feb 17 12:26:42 2016 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options SYS@DGPRI2> alter database open; Database altered. SYS@DGPRI2> set line 9999 SYS@DGPRI2> select name , open_mode, log_mode,force_logging,DATABASE_ROLE,switchover_status from gv$database; NAME OPEN_MODE LOG_MODE FOR DATABASE_ROLE SWITCHOVER_STATUS --------- -------------------- ------------ --- ---------------- -------------------- TESTDG READ WRITE ARCHIVELOG YES PRIMARY NOT ALLOWED TESTDG READ WRITE ARCHIVELOG YES PRIMARY NOT ALLOWED SYS@DGPRI2> archive log list; Database log mode Archive Mode Automatic archival Enabled Archive destination /arch Oldest online log sequence 1 Next log sequence to archive 1 Current log sequence 1 SYS@DGPRI2> |
为主库添加standby redo log
为主库添加standby redo log,简要描述一下standby redo log的作用
实际上就是与主库接收到的重做日志相对应,也就是说备库调用RFS进程将从主库接收到的重做日志按顺序写入到standby logfile
在主库创建standby logfile是便于发生角色转换后备用
sandby redo log创建原则:
a)、确保standby redo log的大小与主库online redo log的大小一致
b)、如主库为单实例数据库:standby redo log组数=主库日志组总数+1
c)、如果主库是RAC数据库:standby redo log组数=(每线程的日志组数+1)*最大线程数
d)、不建议复用standby redo log,避免增加额外的I/O以及延缓重做传输
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | 单实例: alter database add standby logfile group 4 ('/u01/app/oracle/oradata/oralg/standby_redo04.log') size 50m; alter database add standby logfile group 5 ('/u01/app/oracle/oradata/oralg/standby_redo05.log') size 50m; alter database add standby logfile group 6 ('/u01/app/oracle/oradata/oralg/standby_redo06.log') size 50m; alter database add standby logfile group 7 ('/u01/app/oracle/oradata/oralg/standby_redo07.log') size 50m; rac下: alter database add standby logfile thread 1 group 5 size 50M ,group 6 size 50M ,group 7 size 50M ; alter database add standby logfile thread 2 group 8 size 50M ,group 9 size 50M ,group 10 size 50M ; SYS@DGPRI1> select * from v$standby_log; no rows selected SYS@DGPRI1> select group#,THREAD#,MEMBERS from v$log ; GROUP# THREAD# MEMBERS ---------- ---------- ---------- 1 1 2 2 1 2 3 2 2 4 2 2 SYS@DGPRI1> SYS@DGPRI1> col member format a100 SYS@DGPRI1> select GROUP# ,STATUS , TYPE , MEMBER from v$logfile; GROUP# STATUS TYPE MEMBER ---------- ------- ------- ---------------------------------------------------------------------------------------------------- 2 ONLINE +DATA/testdg/onlinelog/group_2.260.904043421 2 ONLINE +DATA/testdg/onlinelog/group_2.263.904043421 1 ONLINE +DATA/testdg/onlinelog/group_1.262.904043421 1 ONLINE +DATA/testdg/onlinelog/group_1.261.904043421 3 ONLINE +DATA/testdg/onlinelog/group_3.303.904043623 3 ONLINE +DATA/testdg/onlinelog/group_3.304.904043623 4 ONLINE +DATA/testdg/onlinelog/group_4.305.904043623 4 ONLINE +DATA/testdg/onlinelog/group_4.306.904043623 8 rows selected. SYS@DGPRI1> alter database add standby logfile thread 1 group 5 size 50M ,group 6 size 50M ,group 7 size 50M ; Database altered. SYS@DGPRI1> alter database add standby logfile thread 2 group 8 size 50M ,group 9 size 50M ,group 10 size 50M ; Database altered. SYS@DGPRI1> select GROUP#,DBID,THREAD#,SEQUENCE#,BYTES,BLOCKSIZE,USED,ARCHIVED,STATUS from v$standby_log; GROUP# DBID THREAD# SEQUENCE# BYTES BLOCKSIZE USED ARC STATUS ---------- ---------------------------------------- ---------- ---------- ---------- ---------- ---------- --- ---------- 5 UNASSIGNED 1 0 52428800 512 0 YES UNASSIGNED 6 UNASSIGNED 1 0 52428800 512 0 YES UNASSIGNED 7 UNASSIGNED 1 0 52428800 512 0 YES UNASSIGNED 8 UNASSIGNED 2 0 52428800 512 0 YES UNASSIGNED 9 UNASSIGNED 2 0 52428800 512 0 YES UNASSIGNED 10 UNASSIGNED 2 0 52428800 512 0 YES UNASSIGNED 6 rows selected. SYS@DGPRI1> SYS@DGPRI1> select GROUP# ,STATUS , TYPE , MEMBER from v$logfile; GROUP# STATUS TYPE MEMBER ---------- ------- ------- ---------------------------------------------------------------------------------------------------- 2 ONLINE +DATA/testdg/onlinelog/group_2.260.904043421 2 ONLINE +DATA/testdg/onlinelog/group_2.263.904043421 1 ONLINE +DATA/testdg/onlinelog/group_1.262.904043421 1 ONLINE +DATA/testdg/onlinelog/group_1.261.904043421 3 ONLINE +DATA/testdg/onlinelog/group_3.303.904043623 3 ONLINE +DATA/testdg/onlinelog/group_3.304.904043623 4 ONLINE +DATA/testdg/onlinelog/group_4.305.904043623 4 ONLINE +DATA/testdg/onlinelog/group_4.306.904043623 5 STANDBY +DATA/testdg/onlinelog/group_5.267.904048731 5 STANDBY +DATA/testdg/onlinelog/group_5.294.904048731 6 STANDBY +DATA/testdg/onlinelog/group_6.308.904048733 6 STANDBY +DATA/testdg/onlinelog/group_6.309.904048733 7 STANDBY +DATA/testdg/onlinelog/group_7.310.904048733 7 STANDBY +DATA/testdg/onlinelog/group_7.311.904048733 8 STANDBY +DATA/testdg/onlinelog/group_8.312.904048737 8 STANDBY +DATA/testdg/onlinelog/group_8.313.904048737 9 STANDBY +DATA/testdg/onlinelog/group_9.314.904048737 9 STANDBY +DATA/testdg/onlinelog/group_9.315.904048739 10 STANDBY +DATA/testdg/onlinelog/group_10.316.904048739 10 STANDBY +DATA/testdg/onlinelog/group_10.317.904048739 20 rows selected. SYS@DGPRI1> show parameter name NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ cell_offloadgroup_name string db_file_name_convert string db_name string TESTDG db_unique_name string TESTDG global_names boolean FALSE instance_name string DGPRI1 lock_name_space string log_file_name_convert string processor_group_name string service_names string TESTDG SYS@DGPRI1> |
修改主库参数文件
使用下面的命令修改主库参数(此时主库应当使用spfile启动参数)
LOG_ARCHIVE_CONFIG = 'DG_CONFIG ( db_unique_name, db_unique_name, ... )' 主库与备库端采用相同设置。
LOG_ARCHIVE_DEST_n ='SERVICE=。。。。。 SERIVCE: 用于指定备用数据库的TNSNAMES描述符
db_file_name_convert、 log_file_name_convert 参数值为路径,可以直接写db_unique_name, 如果使用ASM,可以设置为*.db_file_name_convert =('+DATA','+RECOVERY')
fal_server、 fal_client 参数值为TNSNAMES描述符
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | alter system set db_unique_name='TESTDG' scope=spfile; alter system set log_archive_config='DG_CONFIG=(TESTDG,TESTDGPHY)' sid='*'; alter system set log_archive_dest_1='LOCATION=/arch db_unique_name=TESTDG valid_for=(ALL_LOGFILES,ALL_ROLES)' sid='*'; alter system set log_archive_dest_2='SERVICE=TNS_DGPHY LGWR ASYNC db_unique_name=TESTDGPHY valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE)' sid='*'; alter system set log_archive_dest_state_1=enable sid='*'; alter system set log_archive_dest_state_2=enable sid='*'; alter system set log_archive_max_processes=4 sid='*'; alter system set remote_login_passwordfile='EXCLUSIVE' scope=spfile; --Add below item when DB turn to standby role alter system set db_file_name_convert='TESTDGPHY','TESTDG' scope=spfile; alter system set log_file_name_convert='TESTDGPHY','TESTDG' scope=spfile; alter system set standby_file_management='AUTO' sid='*'; alter system set fal_server='TNS_DGPHY' sid='*'; alter system set fal_client='TNS_DGPRI' sid='*'; SYS@DGPRI1> show parameter spfile NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ spfile string +DATA/testdg/spfiledgpri.ora SYS@DGPRI1> SYS@DGPRI1>alter system set db_unique_name='TESTDG' scope=spfile; alter system set log_archive_config='DG_CONFIG=(TESTDG,TESTDGPHY)' sid='*'; alter system set log_archive_dest_1='LOCATION=/arch db_unique_name=TESTDG valid_for=(ALL_LOGFILES,ALL_ROLES)' sid='*'; alter system set log_archive_dest_2='SERVICE=TNS_DGPHY LGWR ASYNC db_unique_name=TESTDGPHY valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE)' sid='*'; alter system set log_archive_dest_state_1=enable sid='*'; alter system set log_archive_dest_state_2=enable sid='*'; alter system set log_archive_max_processes=4 sid='*'; alter system set remote_login_passwordfile='EXCLUSIVE' scope=spfile; --Add below item when DB turn to standby role alter system set db_file_name_convert='TESTDGPHY','TESTDG' scope=spfile; alter system set log_file_name_convert='TESTDGPHY','TESTDG' scope=spfile; alter system set standby_file_management='AUTO' sid='*'; alter system set fal_server='TNS_DGPHY' sid='*'; alter system set fal_client='TNS_DGPRI' sid='*'; SYS@DGPRI1> System altered. SYS@DGPRI1> System altered. SYS@DGPRI1> System altered. SYS@DGPRI1> System altered. SYS@DGPRI1> System altered. SYS@DGPRI1> System altered. SYS@DGPRI1> System altered. SYS@DGPRI1> System altered. SYS@DGPRI1> System altered. SYS@DGPRI1> System altered. SYS@DGPRI1> System altered. SYS@DGPRI1> System altered. SYS@DGPRI1> System altered. SYS@DGPRI1> SYS@DGPRI1> SYS@DGPRI1> SYS@DGPRI1> SYS@DGPRI1> SYS@DGPRI1> SYS@DGPRI1> SYS@DGPRI1> SYS@DGPRI1> |
配置主库和备库的监听
为主库和备库配置监听,整个DG的redo传输服务,都依赖于Oracle Net,因此需要为主备库配置监听,且需要配置静态监听
配置方法多种多样,可用netmgr,netca,以及直接编辑listener.ora 与tnsnames.ora文件
下面是配置之后的listener.ora 与tnsnames.ora文件内容
more $ORACLE_HOME/network/admin/listener.ora
主库
在主库的第一个节点的监听文件中加入如下内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | 在主库的第一个节点的监听文件中加入如下内容: LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 22.188.194.31)(PORT = 1521)) ) ) SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = PLSExtProc) (ORACLE_HOME = /oracle/app/oracle/product/11.2.0/db) (PROGRAM = extproc) ) (SID_DESC = (GLOBAL_DBNAME = TESTDG) (ORACLE_HOME = /oracle/app/oracle/product/11.2.0/db) (SID_NAME= DGPRI1) ) ) 第二个节点加入: LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 22.188.194.32)(PORT = 1521)) ) ) SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = PLSExtProc) (ORACLE_HOME = /oracle/app/oracle/product/11.2.0/db) (PROGRAM = extproc) ) (SID_DESC = (GLOBAL_DBNAME = TESTDG) (ORACLE_HOME = /oracle/app/oracle/product/11.2.0/db) (SID_NAME= DGPRI2) ) ) 以第一个节点为例,其它类似: [LHRAXXTDB3:oracle]:/oracle>lsnrctl status LSNRCTL for IBM/AIX RISC System/6000: Version 11.2.0.4.0 - Production on 17-FEB-2016 16:50:02 Copyright (c) 1991, 2013, Oracle. All rights reserved. Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521)) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for IBM/AIX RISC System/6000: Version 11.2.0.4.0 - Production Start Date 31-DEC-2015 15:02:50 Uptime 48 days 1 hr. 47 min. 12 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /oracle/app/11.2.0/grid/network/admin/listener.ora Listener Log File /oracle/app/grid/diag/tnslsnr/LHRAXXTDB3/listener/alert/log.xml |
将上边所说的内容加入文件:/oracle/app/11.2.0/grid/network/admin/listener.ora ,然后重启监听器,lsnrctl stop , lsnrctl start,需要注意的是rac下是在grid用户下修改监听文件的。
备库
监听配置参考主库的操作: