《Oracle 11g DataGuard配置详细说明.doc》由会员分享,可在线阅读,更多相关《Oracle 11g DataGuard配置详细说明.doc(17页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、如有侵权,请联系网站删除,仅供学习与交流Oracle 11g DataGuard 配置详细说明【精品文档】第 17 页Oracle 11g DataGuard 配置详细说明1判断DataGuard是否安装 select * from v$option where parameter = Oracle Data Guard; 2. 数据库环境说明主库配置:IP:192.168.228.133(Oracle11g1),数据库名:db1,监听服务名:db1pri,网络服务名:pri从库配置:IP:192.168.229.134(Oracle11g2),数据库名:db1,监听服务名:db1dg ,网络
2、服务名:dg数据库程序安装路径:/oracleapp/oinstall/oracle/product/11.2.0/dbhome_1/dbs数据库存放路径:/oracledata/db13.监听配置 在做oracle dataguard主从库配置时候,一定要配置静态监听,否则可能出现监听服务解析错误,不能连接的问题,监听配置如下:主库 配置如下:oracleOracle11g1 admin$ pwd/oracleapp/oinstall/oracle/product/11.2.0/dbhome_1/network/admin oracleOracle11g1 admin$ cat listen
3、er.ora # listener.ora Network Configuration File: /oracleapp/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_DE
4、SC = (GLOBAL_DBNAME =db1pri) (ORACLE_HOME = /oracleapp/oinstall/oracle/product/11.2.0/dbhome_1) (SID_NAME = db1)ADR_BASE_WU = /oracleapp/oinstall/oracle #注意这里的global_dbname=db1pri,SID_NAME=db1,这个SID_NAME 应与你对外提供服务的 $ORACLE_SID 一致,即数据库:db1oracleOracle11g1 admin$ cat tnsnames.ora# tnsnames.ora Network
5、 Configuration File: /oracleapp/oinstall/oracle/product/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 = db1pri)dg = (DESCRIPTION =
6、 (ADDRESS = (PROTOCOL = TCP)(HOST = Oracle11g2)(PORT = 1521) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = db1dg)#tnsname pri 中的 SERVICE_NAME=db1pri ,这里的服务名为 db1pri而不是通常的 db1,因为在 listener.ora 中已经注册了 db1pri,lsnrctl 启动时会监听 db1pri ,并对应到 SID_NAME=db1 上。此处的pri,dg为数据库参数文件中(initdb1.ora)的DB_UNIQUE_NA
7、ME的名字,即对外提供的服务名。从库配置如下:oracleOracle11g2 admin$ cat listener.ora# listener.ora Network Configuration File: /oracleapp/oinstall/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora# Generated by Oracle configuration tools.WU = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST =
8、Oracle11g2)(PORT = 1521)SID_LIST_WU = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = db1dg) (ORACLE_HOME = /oracleapp/oinstall/oracle/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: /oracle
9、app/oinstall/oracle/product/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 = db1pri)dg = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)
10、(HOST = Oracle11g2)(PORT = 1521) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = db1dg)分别用tnsping命令测试监听服务是否可用,正常显示信息如下:(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:34Copy
11、right (c) 1997, 2009, Oracle. All rights reserved.Used parameter files:Used TNSNAMES adapter to resolve the aliasAttempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = Oracle11g2)(PORT = 1521) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = db1dg)OK (10 msec)oracleOracle11g2 db
12、s$ tnsping priTNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 27-MAY-2014 15:40:16Copyright (c) 1997, 2009, Oracle. All rights reserved.Used parameter files:Used TNSNAMES adapter to resolve the aliasAttempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = Oracle11g1)(PO
13、RT = 1521) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME =db1 pri)OK (10 msec)oracleOracle11g2 dbs$ 4.主库前期准备 设置强制写日志 oracleOracle11g2 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. 创建口令文件 通
14、过dbca命令创建的数据库会自动在/oracleapp/oinstall/oracle/product/11.2.0/dbhome_1/dbs目录下创建orapwdb1密码文件,也可以通过如下命令创建oracleOracle11g1 admin$orapwd file=/oracleapp/oinstall/oracle/product/11.2.0/dbhome_1/dbs/orapwdb1 password=oracle entries=5 密码文件为orapw(数据库ID),这里为orapwdb1.6.修改主库初始化参数 在initdb1.ora文件下增加如下参数: oracleOrac
15、le11g2 dbs$ vim initdb1.ora*.db_name=db1 #注意保持同一个DataGuard中所有数据库DB_NAME相同(物理standby dataguard)。*.DB_UNIQUE_NAME=pri #为每一个数据库指定一个唯一的名称,该参数一经指定不会再发生变化,除非你主动修改它。*.LOG_ARCHIVE_CONFIG=DG_CONFIG=(pri,dg) #(启动db接受或发送redo data,包括所有库的db_unique_name)*.LOG_ARCHIVE_DEST_1= LOCATION=/oracleapp/oinstall/oracle/ar
16、chive 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的传输目的地,两种归档方式LGWR ARCn,ARCn只支持最高性能的保护模式;ASYNC异步传输,SYNC同步传输)#*.LOG_ARCHIVE_MAX_PROCESSES=5 (指定归档进程的数
17、量(1-30),默认值通常是4。使用ARCn归档redo时配置参数)*.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_CON
18、VERT=/路径,路径 (前为切换后的主库路径,后为切换后的备库路径,这里主备库目录结构完全一样,则无需设定)#*.LOG_FILE_NAME_CONVERT=/路径,/路径 (同上,这两个名字转换参数是主备库的路径映射关系,可能会是路径全名,看情况而定)*.STANDBY_FILE_MANAGEMENT=AUTO (auto后当主库的datafiles增删时备库也同样自动操作,且会把日志传送到备库standby_archive_dest参数指定的目录下,确保该目录存在,如果你的存储采用文件系统没有问题,但是如果采用了裸设备,你就必须将该参数设置为manual)*.remote_login_p
19、asswordfile=EXCLUSIVE #(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
20、 DATABASE ARCHIVELOG; 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 注意哟,控制文件通常需要有多份,你要么手工将上述文件复制几份,要么用命令多创建几个出来。另外,创建完控制文件之后到standby数据
21、库创建完成这段时间内,要保证primary数据库不再有结构性的变化(比如增加表空间等等),不然primary和standby同步时会有问题。9. 备份生产数据库 这里以复制数据库文件的方式将主库数据库文件拷贝到备份机器上Oracle11g2,先将数据库关闭。oracleOracle11g1 dbs scp -rp /oracledata/db1 Oracle11g2:/oracledata/ oracleOracle11g1 dbsscp rp /oracleapp/oinstall/oracle/admin/db1 Oracle11g2: /oracleapp/oinstall/oracle
22、/admin (记得在备库创建admin) 在Oracle11g2上删掉数据库的控制文件control01.ctloracleOracle11g2 rm -rf /oracledata/db1/control01.ctl将备份的控制文件拷贝到备份机器上,并复制两个备份control02.ctl,control03.ctloracleOracle11g1 dbs scp -rp /tmp/standby.ctl Oracle11g2:/oracledata/ db1/control01.ctl在Oracle11g2上操作oracleOracle11g2 db1$ cd /oracledata/d
23、b1/oracleOracle11g2 db1 cp control01.ctl control02.ctloracleOracle11g2 db1cp control01.ctl control03.ctl将control02.ctl复制到/oracleapp/oinstall/oracle/flash_recovery_area/db1 下先建立db1文件夹 oracleOracle11g2 db1mkdir /oracleapp/oinstall/oracle/flash_recovery_area/db1oracleOracle11g2 dbscp control02.ctl /ora
24、cleapp/oinstall/oracle/flash_recovery_area/db1/control02.ctl10.修改备库pfile 将主库的orapwdb1,initdb1.ora文件拷贝到从库/oracleapp/oinstall/oracle/product/11.2.0/dbhome_1/dbs下面oracleOracle11g1 dbs scp -rp orapwdb1 Oracle11g2: /oracleapp/oinstall/oracle/product/11.2.0/dbhome_1/dbs/orapwdb1oracleOracle11g1 dbs scp -r
25、p initdb1.ora Oracle11g2: /oracleapp/oinstall/oracle/product/11.2.0/dbhome_1/dbs/initdb1.ora在从库机器上修改initdb1.ora文件参数oracleOracle11g2 dbsvim initdb1.ora*.db_name=db1 #注意保持同一个DataGuard中所有数据库DB_NAME相同。*.DB_UNIQUE_NAME=dg #为每一个数据库指定一个唯一的名称,该参数一经指定不会再发生变化,除非你主动修改它。*.LOG_ARCHIVE_CONFIG=DG_CONFIG=(pri,dg) #
26、(启动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_NAME=pri #(当该库充当主库角色时,设置物理备库redo d
27、ata的传输目的地,两种归档方式LGWR ARCn,ARCn只支持最高性能的保护模式;ASYNC异步传输,SYNC同步传输)#*.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 #(配置网络服务名,假如转换为备库角色时,从这里获取丢失的归档文
28、件)*.FAL_CLIENT=dg #(配置网络服务名,fal_server拷贝丢失的归档文件到这里)#*.DB_FILE_NAME_CONVERT=/路径,路径 (前为切换后的主库路径,后为切换后的备库路径,这里主备库目录结构完全一样,则无需设定)#*.LOG_FILE_NAME_CONVERT=/路径,/路径 (同上,这两个名字转换参数是主备库的路径映射关系,可能会是路径全名,看情况而定)*.STANDBY_FILE_MANAGEMENT=AUTO (auto后当主库的datafiles增删时备库也同样自动操作,且会把日志传送到备库standby_archive_dest参数指定的目录下,
29、确保该目录存在,如果你的存储采用文件系统没有问题,但是如果采用了裸设备,你就必须将该参数设置为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/
30、initdb1.ora; sql create 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在主
31、库、从库上都配置standby redo 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
32、 group 5 (/oracledata/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) * 数据库线程数;单机线
33、程数为1,RAC一般为2。 standby redolog的组成员数和大小也尽量和online redolog一样。删除命令:SQLalter database drop standby logfile group4验证是否创建成功:sqlSELECT GROUP#,THREAD#,SEQUENCE#,ARCHIVED,STATUS FROM V$STANDBY_LOG;14. Start Redo Apply 启动redo应用SQLALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;启动实时应用SQL
34、 alter database recover managed standby database disconnect from session;提示:disconnect from session子句并非必须,该子句用于指定启动完应用后自动退出到命令操作符前,如果不指定的话,当前session就会一直停留处理redo应用,如果想做其它操作,就只能新建一个连接。停止standby正常情况下,我们停止也应该是先停止redo应用,可以通过下列语句:SQLALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;然后再停止standby数据库SQL
35、SHUTDOWNIMMEDIATE;查看哪些归档日志被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, NEXT_TIME FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#; 在备库查看接收到的被应用的redo
36、SQL SELECT SEQUENCE#,APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#; 查看数据库的角色 主库上:SQL select database_role,protection_mode,protection_level from v$database;DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVELPRIMARY MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE备库上SQL select database_role,protection_mode,protect
37、ion_level from v$database;DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVELPHYSICAL STANDBY MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE15、DataGuard关启状态 启用备用数据库 SQL STARTUP NOMOUNMT; SQL alter database mount standby database; SQL alter database recover managed standby database disconnect from session; (注: a
38、lter database recover managed standby database using current logfile disconnect from session #切换到实时恢复管理模式)关闭备用数据库 SQL alter database recover managed standby database cancel; SQL shutdown immediate; 从关闭状态打开 SQL startup nomount; SQL alter database mount standby database; SQL alter database open read o
39、nly; 从正在恢复状态只读打开 SQL alter database recover managed standby database cancel; SQL alter database open read only; 切换回到恢复状态 SQL alter database recover managed standby database disconnect from session;16、主备数据库切换 16.、正常切换: 主服务器 SQL alter database commit to switchover to physical standby;SQL shutdown imme
40、diate SQL startup nomount; SQL alter database mount standby database; SQL alter database recover managed standby database disconnect from session 备用服务器 SQL alter database commit to switchover to primary SQL shutdown immediate; SQL startup 16.、非正常切换:(即主服务器当机的情况)启动failover 备服务器 SQL alter database reco
41、ver managed standby database finish;SQL alter database commit to switchover to primary; SQL shutdown immediate; SQL startup;主备库切换 1)查看主库的状态 SQL SELECT SWITCHOVER_STATUS FROM V$DATABASE; 2)将主库切换至备用模式 SQL ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY WITH - SESSION SHUTDOWN; 3)关闭、装载主数据库 SQL
42、SHUTDOWN ABORT; SQL STARTUP MOUNT; 4)查看备库准备向主库模式切换 SQL SELECT SWITCHOVER_STATUS FROM V$DATABASE; SWITCHOVER_STATUS TO_PRIMARY 5)切换备库至主库模式 SQL ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN; 6)打开新的主数据库 SQL ALTER DATABASE OPEN; 7)在新的备库服务器上启动 REDO apply。 SQL ALTER DATABASE RECOVER
43、 MANAGED STANDBY DATABASE USING CURRENT LOGFILE - DISCONNECT FROM SESSION; 常用维护SQL 添加几个常用命令 备库启动归档日志应用 alter database recover managed standby database disconnect from session; 备库启动实时归档应用alter database recover managed standby database using current logfile disconnect from session备库停止归档日志应用 alter data
44、base recover managed standby database cancel; 查询归档日志是否被应用,查询V$archived_log视图的applied列 select sequence#,dest_id,first_time,next_time, applied from v$archived_log; 查看备库是否和主库同步,查询V$archive_dest_status视图 select archived_thread#,archived_seq#,applied_thread#,applied_seq# from v$archive_dest_status; 监控日志传
45、送状态,V$archive_gap记录当前备库mrp进程恢复需要的但是还没有传到备库的日志更简单的是查看主备库的归档日志的序列号相差多少 select * from v$archive_gap; 查看当前主机的运行状态 select switchover_status,database_role,protection_mode from v$database; 查看备库接收、应用redo数据的过程 select message from v$dataguard_status; 备库端查看RFS(Remote File Service)接收日志情况和MRP应用日志同步主数据库的情况(Physical Standby Database Only) 记录当前备库的一些进程情况和进程ID select process,status,thread#,sequence#,block#,blocks from v$managed_standby; V$STANDBY_LOG备用数据库的备用日志的数量与当前状态等信息 SELECT * FROM V$STANDBY_LOG; 启动Data Guard 后, 查看同步情况: SQL select error from v$archive_dest; 用SQL 查看了一下同步正常: SQL select sequence#,applied fro
限制150内