1、Oracle 11g DataGuard 配置详细说明Oracle 11g DataGuard 配置详细说明1判断DataGuard是否安装 select * from v$option where parameter = Oracle Data Guard; 2. 数据库环境说明主库配置:IP:192.168.228.133(Oracle11g1),数据库名:db1,监听服务名:pri从库配置:IP:192.168.229.134(Oracle11g2),数据库名:db1,监听服务名:dg 数据库程序安装路径:/oracleapp/oinstall/oracle/product/11.2.0
2、/dbhome_1/dbs数据库存放路径:/oracledata/db13.监听配置 在做oracle dataguard主从库配置时候,一定要配置静态监听,否则可能出现监听服务解析错误,不能连接的问题,监听配置如下:主库 配置如下:oracleOracle11g1 admin$ pwd/oracleapp/oinstall/oracle/product/11.2.0/dbhome_1/network/admin oracleOracle11g1 admin$ cat listener.ora # listener.ora Network Configuration File: /oracle
3、app/oinstall/oracle/product/1.2.0/dbhome_1/network/admin/listener.ora# Generated by Oracle configuration tools.WU = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = Oracle11g2)(PORT = 1521) ) )SID_LIST_WU = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = pri) (ORACLE_HOME = /oracleapp/
4、oinstall/oracle/product/11.2.0/dbhome_1) (SID_NAME = db1) ) )ADR_BASE_WU = /oracleapp/oinstall/oracle #注意这里的global_dbname=pri,SID_NAME=db1,这个SID_NAME 应与你对外提供服务的 $ORACLE_SID 一致,即数据库:db1oracleOracle11g1 admin$ cat tnsnames.ora# tnsnames.ora Network Configuration File: /oracleapp/oinstall/oracle/produc
5、t/11.2.0/dbhome_1/network/admin/tnsnames.ora# Generated by Oracle configuration tools.pri = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = Oracle11g1)(PORT = 1521) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = pri) ) )dg = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = Oracle11g2)(PORT
6、= 1521) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = dg) ) )#tnsname pri 中的 SERVICE_NAME=pri ,这里的服务名为 pri而不是通常的 db1,因为在 listener.ora 中已经注册了 pri,lsnrctl 启动时会监听 pri ,并对应到 SID_NAME=db1 上。从库配置如下:oracleOracle11g2 admin$ cat listener.ora# listener.ora Network Configuration File: /oracleapp/oinstal
7、l/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora# Generated by Oracle configuration tools.WU = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = Oracle11g2)(PORT = 1521) ) )SID_LIST_WU = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = dg) (ORACLE_HOME = /oracleapp/oinstall/or
8、acle/product/11.2.0/dbhome_1) (SID_NAME = db1) ) )ADR_BASE_WU = /oracleapp/oinstall/oracle oracleOracle11g2 admin$ cat tnsnames.ora# tnsnames.ora Network Configuration File: /oracleapp/oinstall/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora# Generated by Oracle configuration tools.pri = (
9、DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = Oracle11g1)(PORT = 1521) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = pri) ) )dg = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = Oracle11g2)(PORT = 1521) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = dg) ) )分别用tnsping命令测试监听服务是否可用,正常
10、显示信息如下:(tnsping对方的时候,有可能linux防火墙限制了,会提示TNS-12560: TNS: 协议适配器错误) oracleOracle11g2 dbs$ tnsping dgTNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 27-MAY-2014 15:39:34Copyright (c) 1997, 2009, Oracle. All rights reserved.Used parameter files:Used TNSNAMES adapter to resolve the aliasAtte
11、mpting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = Oracle11g2)(PORT = 1521) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = dg)OK (10 msec)oracleOracle11g2 dbs$ tnsping priTNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 27-MAY-2014 15:40:16Copyright (c) 1997, 200
12、9, Oracle. All rights reserved.Used parameter files:Used TNSNAMES adapter to resolve the aliasAttempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = Oracle11g1)(PORT = 1521) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = pri)OK (10 msec)oracleOracle11g2 dbs$ 4.主库前期准备 设置强制写日志 o
13、racleOracle11g2 admin$ sqlplus / as sysdbaSQL select FORCE_LOGGING from v$database; NO SQL alter database force logging; SQL select FORCE_LOGGING from v$database;YES 5. 创建口令文件 通过dbca命令创建的数据库会自动在/oracleapp/oinstall/oracle/product/11.2.0/dbhome_1/dbs目录下创建orapwdb1密码文件,也可以通过如下命令创建oracleOracle11g1 admin$
14、orapwd file=/oracleapp/oinstall/oracle/product/11.2.0/dbhome_1/dbs/orapwdb1 password=oracle entries=5 密码文件为orapw(数据库ID),这里为orapwdb1.6.修改主库初始化参数 在initdb1.ora文件下增加如下参数: oracleOracle11g2 dbs$ vim initdb1.ora*.DB_UNIQUE_NAME=pri*.LOG_ARCHIVE_CONFIG=DG_CONFIG=(pri,dg) #(启动db接受或发送redo data,包括所有库的db_unique
15、_name)*.LOG_ARCHIVE_DEST_1= LOCATION=/oracleapp/oinstall/oracle/archive VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=pri #(主库归档目的地)*.LOG_ARCHIVE_DEST_2= SERVICE=dg LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=dg #(当该库充当主库角色时,设置物理备库redo data的传输目的地)*.LOG_ARCHIVE_MAX_PROCESSE
16、S=5 (最大ARCn进程数)*.LOG_ARCHIVE_DEST_STATE_1=ENABLE #允许redo传输服务传输数据到目的地*.LOG_ARCHIVE_DEST_STATE_2=ENABLE #允许redo传输服务传输数据到目的地*.LOG_ARCHIVE_FORMAT=%t_%s_%r.arc #配置日志格式*.FAL_SERVER=dg #(配置网络服务名,假如转换为备库角色时,从这里获取丢失的归档文件)*.FAL_CLIENT=pri #(配置网络服务名,fal_server拷贝丢失的归档文件到这里)#*.DB_FILE_NAME_CONVERT=/路径,路径 (前为切换后的
17、主库路径,后为切换后的备库路径,这里主备库目录结构完全一样,则无需设定)#*.LOG_FILE_NAME_CONVERT=/路径,/路径 (同上,这两个名字转换参数是主备库的路径映射关系,可能会是路径全名,看情况而定)*.STANDBY_FILE_MANAGEMENT=AUTO (auto后当主库的datafiles增删时备库也同样自动操作,且会把日志传送到备库standby_archive_dest参数指定的目录下,确保该目录存在,如果你的存储采用文件系统没有问题,但是如果采用了裸设备,你就必须将该参数设置为manual)*.remote_login_passwordfile=EXCLUSI
18、VE #(exclusive or shared,所有库sys密码要一致,默认是exclusive)oracleOracle11g1 dbs$sqlplus / as sysdba创建主库spfile sqlstartup pfile=/oracleapp/oinstall/oracle/product/11.2.0/dbhome_1/dbs/initdb1.ora; sql create spfile from pfile; 7.修改数据库运行在归档模式下 sqlSHUTDOWN IMMEDIATE; sqlSTARTUP MOUNT; sqlALTER DATABASE ARCHIVELO
19、G; sql ALTER DATABASE OPEN; 8. 创建备份库需要的控制文件 创建控制文件 sqlShutdown immediate sqlSTARTUP MOUNT; sqlALTER DATABASE CREATE STANDBY CONTROLFILE AS /tmp/standby.ctl; sqlALTER DATABASE OPEN; sqlshutdown immediate;sql startup 9. 备份生产数据库 将主库数据库文件拷贝到备份机器上Oracle11g2oracleOracle11g1 dbs scp -rp /oracledata/db1 Ora
20、cle11g2:/oracledata/ oracleOracle11g1 dbsscp rp /oracleapp/oinstall/oracle/admin/db1 Oracle11g2: /oracleapp/oinstall/oracle/admin (记得在备库创建admin) 在Oracle11g2上删掉数据库的控制文件control01.ctloracleOracle11g2 rm -rf /oracledata/db1/control01.ctl将备份的控制文件拷贝到备份机器上,并复制两个备份control02.ctl,control03.ctloracleOracle11g1
21、 dbs scp -rp /tmp/standby.ctl Oracle11g2:/oracledata/ db1/control01.ctl在Oracle11g2上操作oracleOracle11g2 db1$ cd /oracledata/db1/oracleOracle11g2 db1 cp control01.ctl control02.ctloracleOracle11g2 db1cp control01.ctl control03.ctl将control02.ctl复制到/oracleapp/oinstall/oracle/flash_recovery_area/db1 下先建立d
22、b1文件夹 oracleOracle11g2 db1mkdir /oracleapp/oinstall/oracle/flash_recovery_area/db1oracleOracle11g2 dbscp control02.ctl /oracleapp/oinstall/oracle/flash_recovery_area/db1/control02.ctl10.修改备库pfile 将主库的orapwdb1,initdb1.ora文件拷贝到从库/oracleapp/oinstall/oracle/product/11.2.0/dbhome_1/dbs下面oracleOracle11g1
23、dbs scp -rp orapwdb1 Oracle11g2: /oracleapp/oinstall/oracle/product/11.2.0/dbhome_1/dbs/orapwdb1oracleOracle11g1 dbs scp -rp initdb1.ora Oracle11g2: /oracleapp/oinstall/oracle/product/11.2.0/dbhome_1/dbs/initdb1.ora在从库机器上修改initdb1.ora文件参数oracleOracle11g2 dbsvim initdb1.ora*.DB_UNIQUE_NAME=dg*.LOG_AR
24、CHIVE_CONFIG=DG_CONFIG=(pri,dg) #(启动db接受或发送redo data,包括所有库的db_unique_name)*.LOG_ARCHIVE_DEST_1= LOCATION=/oracleapp/oinstall/oracle/archive VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=dg #(主库归档目的地)*.LOG_ARCHIVE_DEST_2= SERVICE=pri LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_N
25、AME=pri #(当该库充当主库角色时,设置物理备库redo data的传输目的地)*.LOG_ARCHIVE_MAX_PROCESSES=5 (最大ARCn进程数)*.LOG_ARCHIVE_DEST_STATE_1=ENABLE #允许redo传输服务传输数据到目的地*.LOG_ARCHIVE_DEST_STATE_2=ENABLE #允许redo传输服务传输数据到目的地*.LOG_ARCHIVE_FORMAT=%t_%s_%r.arc #配置日志格式*.FAL_SERVER=pri #(配置网络服务名,假如转换为备库角色时,从这里获取丢失的归档文件)*.FAL_CLIENT=dg #(
26、配置网络服务名,fal_server拷贝丢失的归档文件到这里)#*.DB_FILE_NAME_CONVERT=/路径,路径 (前为切换后的主库路径,后为切换后的备库路径,这里主备库目录结构完全一样,则无需设定)#*.LOG_FILE_NAME_CONVERT=/路径,/路径 (同上,这两个名字转换参数是主备库的路径映射关系,可能会是路径全名,看情况而定)*.STANDBY_FILE_MANAGEMENT=AUTO (auto后当主库的datafiles增删时备库也同样自动操作,且会把日志传送到备库standby_archive_dest参数指定的目录下,确保该目录存在,如果你的存储采用文件系统
27、没有问题,但是如果采用了裸设备,你就必须将该参数设置为manual)*.remote_login_passwordfile=EXCLUSIVE #(exclusive or shared,所有库sys密码要一致,默认是exclusive)11.在备库上创建spfile oracleOracle11g2 dbs$sqlplus / as sysdba创建备库spfile sql Shutdown immediatesqlstartup pfile=/oracleapp/oinstall/oracle/product/11.2.0/dbhome_1/dbs/initdb1.ora; sql cre
28、ate spfile from pfile; 12.启动物理备用数据库 sql Shutdown immediatesqlSTARTUP MOUNT; 13.配置standby redolog(最佳性能模式可以忽略,如果要转为其它两种模式则要建立)分部在Oracle11g1和Oracle11g2上建立standby文件夹,用于standby Redo logoracleOracle11g2 dbsmkdir /oracledata/db1/standbyoracleOracle11g1 dbsmkdir /oracledata/db1/standby在主库、从库上都配置standby redo
29、 log 在主库查看日志组的数量和每个日志文件的大小 SQL SELECT GROUP#, BYTES FROM V$LOG; 在备库库查看日志组的数量和每个日志文件的大小 SQL SELECT GROUP#, BYTES FROM V$STANDBY_LOG; 创建日志组和redo log文件 SQL ALTER DATABASE ADD STANDBY LOGFILE group 4(/oracledata/db1/standby /slog1.rdo) SIZE 50M; SQL ALTER DATABASE ADD STANDBY LOGFILE group 5 (/oracledat
30、a/db1/standby /slog2.rdo) SIZE 50M; SQLALTER DATABASE ADD STANDBY LOGFILE group 6 (/oracledata/db1/standby /slog3.rdo) SIZE 50M; SQL ALTER DATABASE ADD STANDBY LOGFILE group 7(/oracledata/db1/standby /slog4.rdo) SIZE 50M; standby redolog的组数参考公式:(online redolog组数 + 1) * 数据库线程数;单机线程数为1,RAC一般为2。 standb
31、y redolog的组成员数和大小也尽量和online redolog一样。14. Start Redo Apply sqlALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION; 查看哪些归档日志被APPLY了 在备库 sqlSELECT SEQUENCE#,APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#; 在主库强制日志切换到当前的online redo log file.sql ALTER SYSTEM ARCHIVE LOG CURRENT; 在备库查看新的被归档的redo data sqlSELECT SEQUENCE#, FIRST_TIME,
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1