Oracle Data Guard部署方法是什么
这篇文章主要介绍"Oracle Data Guard部署方法是什么",在日常操作中,相信很多人在Oracle Data Guard部署方法是什么问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"Oracle Data Guard部署方法是什么"的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
一、 文档介绍
本实施方案主要对Oracle DataGuard实施部署作相应的说明。以便能根据当前业务特点,规划、建设符合高可用、高可靠的数据库集群系统。
二、 Oracle Data Guard介绍
(一) Data Guard环境拓展
(二) Data Guard特点
数据库服务器采用Data Guard灾备模式,可以满足对可用性有特殊需求的应用,具备以下特点:
1. 需要冗余的服务器设备,该模式需要有冗余的服务器硬件,硬件成本较高。
2. 需要冗余的存储设备,主机和备机都需要同样的存储空间,成本较高。
3. 安装配置比较复杂,该模式比单节点、单实例的模式配置复杂一些,需要更多的配置步骤。
4. 管理维护成本高,该模式对维护人员的要求较高,维护成本高。
5. 具备一定的容灾特性。当主机整个数据库系统不可用并短期内无法恢复时,可以把数据库系统切换到备机上,具备容灾的功能。
6. 备机可以用作只读查询,备机可以切换到只读状态供报表之类的查询操作,减轻主机的压力。
三、 Oracle Data Guard单实例部署一主两备
(一) 安装环境
主机1 | 主机2 | 主机3 | |
操作系统 | Oracle Linux Server release 6.5 | Oracle Linux Server release 6.5 | Oracle Linux Server release 6.5 |
主机名 | test1.us.oracle.com | test2.us.oracle.com | test5.us.oracle.com |
IP | 192.168.1.2 | 192.168.1.3 | 192.168.1.6 |
数据库软件版本 | 11.2.0.4.0 | 11.2.0.4.0 | 11.2.0.4.0 |
ORACLE_BASE | /u01/app/oracle | /u01/app/oracle | /u01/app/oracle |
ORACLE_HOME | /u01/app/oracle/product/11.2.0/db_1 | /u01/app/oracle/product/11.2.0/db_1 | /u01/app/oracle/product/11.2.0/db_1 |
ORACLE_SID | PROD1 | PROD2 | PROD5 |
闪回区路径 | /home/oracle/flash | ||
闪回区大小 | 4G | ||
归档 | archovelog | ||
主从关系 | Primiry | Standby | Standby |
强制日志 | logging force | ||
闪回 | flashbackdatabase | ||
是否开启监听 | start | start | start |
是否建立实例 | setup | no setup | no setup |
(二) 主数据库配置
1. 设置数据库归档
[oracle@test1 dbs]$ export ORACLE_SID=PROD1[oracle@test1 dbs]$ sqlplus / as sysdbaSQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 3 08:07:15 2019Copyright (c) 1982, 2013, Oracle. All rights reserved.Connected to an idle instance.SQL> startup mount;ORACLE instance started.Total System Global Area 1219260416 bytesFixed Size 2252744 bytesVariable Size 788529208 bytesDatabase Buffers 419430400 bytesRedo Buffers 9048064 bytesDatabase mounted. SQL> alter system set db_recovery_file_dest='/home/oracle/flash';System altered. SQL> alter system set db_recovery_file_dest_size=4G;System altered. SQL> alter database archivelog;Database altered. SQL> alter database open;Database altered.
2. 设置数据库闪回
SQL> select flashback_on from v$database;FLASHBACK_ON------------------------------------NO SQL> alter system set db_recovery_file_dest='/home/oracle/flash';System altered. SQL> alter system set db_recovery_file_dest_size='5G';System altered.SQL> shutdown immediate;ORA-01109: database not openDatabase dismounted.ORACLE instance shut down.SQL> startup mount;ORACLE instance started.Total System Global Area 1219260416 bytesFixed Size 2252744 bytesVariable Size 788529208 bytesDatabase Buffers 419430400 bytesRedo Buffers 9048064 bytesDatabase mounted.SQL> alter database flashback on; Database altered.SQL> alter database open;Database altered.SQL> select flashback_on from v$database;FLASHBACK_ON------------------------------------YES
3. 设置数据库强制归档
SQL> select force_logging from v$database;FORCE_------NOSQL> alter database force logging;Database altered.SQL> select force_logging from v$database;FORCE_------YES
4. 添加Standby日志文件
在备库,当RFS进程接受到日志后,就将其写入Standby日志文件里,备库的Standby日志文件可以看做是主库在线日志文件的一个镜像,当主库做日志切换时,备库的Standby日志也做相应的切换,切换后的Standby日志由备库的ARCH进程归档。
Oracle规定备库的Standby日志文件大小不能小于主库在线日志文件最大的一个,一般情况下,为了管理方便,最好把所有的在线日志和Standby日志大小设为一样。
通过下面语句可以查询主库在线日志的大小和组数:
SQL> select group#,bytes/1024/1024 from v$log; GROUP# BYTES/1024/1024---------- --------------- 1 50 2 50 3 50 SQL> select group#,bytes/1024/1024 from v$standby_log;no rows selected SQL> alter database add standby logfile group 4 '/home/oracle/s1.log' size 50M;Database altered.SQL> alter database add standby logfile group 5 '/home/oracle/s2.log' size 50M;Database altered.SQL> alter database add standby logfile group 6 '/home/oracle/s3.log' size 50M;Database altered.SQL> alter database add standby logfile group 7 '/home/oracle/s4.log' size 50M;Database altered. SQL> select group#,bytes/1024/1024 from v$standby_log; GROUP# BYTES/1024/1024---------- --------------- 4 50 5 50 6 50 7 50
5. 修改参数文件
SQL> create pfile from spfile;File created.SQL> exitDisconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing options[oracle@test1 dbs]$ lshc_PROD1.dat init.ora initPROD1.ora lkPROD1 orapwPROD1 spfilePROD1.ora[oracle@test1 dbs]$ cat initPROD1.oraPROD1.__db_cache_size=419430400PROD1.__java_pool_size=16777216PROD1.__large_pool_size=83886080PROD1.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environmentPROD1.__pga_aggregate_target=503316480PROD1.__sga_target=721420288PROD1.__shared_io_pool_size=0PROD1.__shared_pool_size=184549376PROD1.__streams_pool_size=0*.audit_file_dest='/u01/app/oracle/admin/PROD1/adump'*.audit_trail='db'*.compatible='11.2.0.4.0'*.control_files='/u01/app/oracle/oradata/PROD1/control01.ctl','/u01/app/oracle/fast_recovery_area/PROD1/control02.ctl'*.db_block_size=8192*.db_domain=''*.db_name='PROD1'*.db_recovery_file_dest='/home/oracle/flash'*.db_recovery_file_dest_size=4294967296*.diagnostic_dest='/u01/app/oracle'*.dispatchers='(PROTOCOL=TCP) (SERVICE=PROD1XDB)'*.undo_tablespace='UNDOTBS1'*.processes=150*.open_cursors=300*.memory_target=1211105280 *.DB_UNIQUE_NAME='PROD1'*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(PROD1,PROD2,PROD5)'*.LOG_ARCHIVE_DEST_1='LOCATION=/home/oracle/flash VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=PROD1'*.LOG_ARCHIVE_DEST_2='SERVICE=PROD1_2 ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=PROD2'*.LOG_ARCHIVE_DEST_3='SERVICE=PROD1_5 ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=PROD5'*.LOG_ARCHIVE_DEST_STATE_1='ENABLE'*.LOG_ARCHIVE_DEST_STATE_2='ENABLE'*.LOG_ARCHIVE_DEST_STATE_3='ENABLE'*.LOG_ARCHIVE_FORMAT='%t_%s_%r.arc'*.LOG_ARCHIVE_MAX_PROCESSES=30*.REMOTE_LOGIN_PASSWORDFILE='EXCLUSIVE'*.FAL_CLIENT='PROD2,PROD5'*.FAL_SERVER='PROD1'
注意:上面修改的参数有的需要重启数据库才能生效
6. 修改监听配置文件
[oracle@test1 ~]$ cd /u01/app/oracle/product/11.2.0/db_1/network/admin/[oracle@test1 admin]$ cat listener.ora # listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora# Generated by Oracle configuration tools. LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = test1.us.oracle.com)(PORT = 1521)) (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) ) ) ADR_BASE_LISTENER = /u01/app/oracle SID_LIST_LISTENER= (SID_LIST= (SID_DESC= (GLOBAL_DBNAME=PROD1) (ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1) (SID_NAME=PROD1)))
7. 修改TNS配置文件
[oracle@test1 admin]$ cat tnsnames.ora # tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora# Generated by Oracle configuration tools. PROD1_5 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = test5.us.oracle.com)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = PROD5) ) ) PROD1_2 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = test2.us.oracle.com)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = PROD2) ) ) PROD1_1 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = test1.us.oracle.com)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = PROD1) ) )
8. 重启监听服务,测试服务名的连通情况
[oracle@test1 dbs]$ lsnrctl stop[oracle@test1 dbs]$ lsnrctl start
9. 拷贝参数文件
[oracle@test1 dbs]$ scp initPROD1.ora oracle@test2:/u01/app/oracle/product/11.2.0/db_1/dbs/oracle@test2's password: initPROD1.ora 100% 1519 1.5KB/s 00:00 [oracle@test1 dbs]$ scp initPROD1.ora oracle@test5:/u01/app/oracle/product/11.2.0/db_1/dbs/oracle@test5's password: initPROD1.ora 100% 1519 1.5KB/s 00:00
10. 拷贝密码文件
[oracle@test1 dbs]$ scp orapwPROD1 oracle@test2:/u01/app/oracle/product/11.2.0/db_1/dbs/oracle@test2's password: orapwPROD1 100% 1536 1.5KB/s 00:00 [oracle@test1 dbs]$ scp orapwPROD1 oracle@test5:/u01/app/oracle/product/11.2.0/db_1/dbs/oracle@test5's password: orapwPROD1 100% 1536 1.5KB/s 00:00
(三) 两备数据库配置
1. 修改参数文件
[oracle@test2 dbs]$ cat initPROD1.ora PROD2.__db_cache_size=419430400PROD2.__java_pool_size=16777216PROD2.__large_pool_size=83886080PROD2.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environmentPROD2.__pga_aggregate_target=503316480PROD2.__sga_target=721420288PROD2.__shared_io_pool_size=0PROD2.__shared_pool_size=184549376PROD2.__streams_pool_size=0*.audit_file_dest='/u01/app/oracle/admin/PROD1/adump'*.audit_trail='db'*.compatible='11.2.0.4.0'*.control_files='/u01/app/oracle/oradata/PROD1/control01.ctl','/u01/app/oracle/fast_recovery_area/PROD1/control02.ctl'*.db_block_size=8192*.db_domain=''*.db_name='PROD1'*.db_recovery_file_dest='/home/oracle/flash'*.db_recovery_file_dest_size=4294967296*.diagnostic_dest='/u01/app/oracle'*.dispatchers='(PROTOCOL=TCP) (SERVICE=PROD1XDB)'*.undo_tablespace='UNDOTBS1'*.processes=150*.open_cursors=300*.memory_target=1211105280*.DB_UNIQUE_NAME='PROD2'*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(PROD2,PROD1,PROD5)'*.LOG_ARCHIVE_DEST_1='LOCATION=/home/oracle/flash VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=PROD2'*.LOG_ARCHIVE_DEST_2='SERVICE=PROD1_1 ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=PROD1'*.LOG_ARCHIVE_DEST_3='SERVICE=PROD1_5 ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=PROD5'*.LOG_ARCHIVE_DEST_STATE_1='ENABLE'*.LOG_ARCHIVE_DEST_STATE_2='ENABLE'*.LOG_ARCHIVE_DEST_STATE_3='ENABLE'*.LOG_ARCHIVE_FORMAT='%t_%s_%r.arc'*.LOG_ARCHIVE_MAX_PROCESSES=30*.REMOTE_LOGIN_PASSWORDFILE='EXCLUSIVE'*.FAL_CLIENT='PROD2,PROD5'*.FAL_SERVER='PROD1'
[oracle@test5 dbs]$ cat initPROD1.ora PROD5.__db_cache_size=469762048PROD5.__java_pool_size=16777216PROD5.__large_pool_size=33554432PROD5.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environmentPROD5.__pga_aggregate_target=503316480PROD5.__sga_target=721420288PROD5.__shared_io_pool_size=0PROD5.__shared_pool_size=184549376PROD5.__streams_pool_size=0*.audit_file_dest='/u01/app/oracle/admin/PROD1/adump'*.audit_trail='db'*.compatible='11.2.0.4.0'*.control_files='/u01/app/oracle/oradata/PROD1/control01.ctl','/u01/app/oracle/fast_recovery_area/PROD1/control02.ctl'*.db_block_size=8192*.db_domain=''*.db_name='PROD1'*.db_recovery_file_dest='/home/oracle/flash'*.db_recovery_file_dest_size=4294967296*.diagnostic_dest='/u01/app/oracle'*.dispatchers='(PROTOCOL=TCP) (SERVICE=PROD1XDB)'*.memory_target=1211105280*.open_cursors=300*.processes=150*.remote_login_passwordfile='EXCLUSIVE'*.undo_tablespace='UNDOTBS1' DB_UNIQUE_NAME=PROD5LOG_ARCHIVE_CONFIG='DG_CONFIG=(PROD5,PROD1,PROD2)'LOG_ARCHIVE_DEST_1= 'LOCATION=/home/oracle/flash VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=PROD5'LOG_ARCHIVE_DEST_2= 'SERVICE=PROD1_2 ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=PROD2'LOG_ARCHIVE_DEST_3= 'SERVICE=PROD1_1 ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=PROD1'LOG_ARCHIVE_DEST_STATE_1=ENABLELOG_ARCHIVE_DEST_STATE_2=ENABLELOG_ARCHIVE_DEST_STATE_3=ENABLEREMOTE_LOGIN_PASSWORDFILE=EXCLUSIVELOG_ARCHIVE_FORMAT=%t_%s_%r.arcLOG_ARCHIVE_MAX_PROCESSES=30FAL_SERVER=PROD1FAL_CLIENT=PROD2,PROD5STANDBY_FILE_MANAGEMENT=AUTO
2. 修改密码文件创建相应的文件目录
根据上面修改的参数文件,为备库创建相应的文件目录
[oracle@test2 dbs]$ mv orapwPROD1 orapwPROD2[oracle@test2 dbs]$ mv initPROD1.ora initPROD2.ora[oracle@test2 dbs]$ mkdir -p /u01/app/oracle/admin/PROD1/adump[oracle@test2 dbs]$ mkdir -p /u01/app/oracle/oradata/PROD1[oracle@test2 dbs]$ mkdir -p /u01/app/oracle/fast_recovery_area/PROD1[oracle@test2 dbs]$ mkdir -p /home/oracle/flash [oracle@test5 dbs]$ mv orapwPROD1 orapwPROD5[oracle@test5 dbs]$ mv initPROD1.ora initPROD5.ora[oracle@test5 dbs]$ mkdir -p /u01/app/oracle/admin/PROD1/adump[oracle@test5 dbs]$ mkdir -p /u01/app/oracle/oradata/PROD1[oracle@test5 dbs]$ mkdir -p /u01/app/oracle/fast_recovery_area/PROD1[oracle@test5 dbs]$ mkdir -p /home/oracle/flash
3. 修改监听配置文件
[oracle@test2 admin]$ cat listener.ora # listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora# Generated by Oracle configuration tools. LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = test2.us.oracle.com)(PORT = 1521)) (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) ) ) ADR_BASE_LISTENER = /u01/app/oracle SID_LIST_LISTENER= (SID_LIST= (SID_DESC= (GLOBAL_DBNAME=PROD2) (ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1) (SID_NAME=PROD2)))
[oracle@test5 admin]$ cat listener.ora # listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora# Generated by Oracle configuration tools. LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = test5.us.oracle.com)(PORT = 1521)) (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) ) ) ADR_BASE_LISTENER = /u01/app/oracle SID_LIST_LISTENER= (SID_LIST= (SID_DESC= (GLOBAL_DBNAME=PROD5) (ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1) (SID_NAME=PROD5)))
4. 修改TNS配置文件
两备库的TNS配置文件与主库相同
[oracle@test2 admin]$ cat tnsnames.ora # tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora# Generated by Oracle configuration tools. PROD1_1 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.2)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = PROD1) ) ) PROD1_2 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = test2.us.oracle.com)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = PROD2) ) ) PROD1_5 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = test5.us.oracle.com)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = PROD5) ) )
5. 重启监听服务
[oracle@test2 dbs]$ lsnrctl stop[oracle@test2 dbs]$ lsnrctl start[oracle@test5 dbs]$ lsnrctl stop[oracle@test5 dbs]$ lsnrctl start
6. 启动数据库到nomonunt状态
[oracle@test2 dbs]$ export ORACLE_SID=PROD2 [oracle@test2 dbs]$ sqlplus / as sysdbaSQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 3 08:04:27 2019Copyright (c) 1982, 2013, Oracle. All rights reserved.Connected to an idle instance. SQL> startup nomount;ORACLE instance started.Total System Global Area 1219260416 bytesFixed Size 2252744 bytesVariable Size 788529208 bytesDatabase Buffers 419430400 bytesRedo Buffers 9048064 bytes
[oracle@test5 dbs]$ export ORACLE_SID=PROD5 [oracle@test5 dbs]$ sqlplus / as sysdbaSQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 3 08:04:47 2019Copyright (c) 1982, 2013, Oracle. All rights reserved.Connected to an idle instance. SQL> startup nomount;ORACLE instance started.Total System Global Area 1219260416 bytesFixed Size 2252744 bytesVariable Size 788529208 bytesDatabase Buffers 419430400 bytesRedo Buffers 9048064 bytes
7. 验证监听和TNS配置
主备库上都需要验证
[oracle@test1 dbs]$ sqlplus sys/oracle@PROD1_1 as sysdbaSQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 3 05:35:15 2019Copyright (c) 1982, 2013, Oracle. All rights reserved.Connected to:Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing optionsSQL> quitDisconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing options[oracle@test1 dbs]$ sqlplus sys/oracle@PROD1_2 as sysdbaSQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 3 05:35:54 2019Copyright (c) 1982, 2013, Oracle. All rights reserved.Connected to:Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing optionsSQL> quitDisconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing options[oracle@test1 dbs]$ sqlplus sys/oracle@PROD1_5 as sysdbaSQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 3 05:36:02 2019Copyright (c) 1982, 2013, Oracle. All rights reserved.Connected to:Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing optionsSQL> quitDisconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing options
注意:该步骤一定要在主备库上都能通过才能执行下面步骤
(四) 恢复数据库
[oracle@test1 ~]$ rman target sys/oracle@prod1_1 auxiliary sys/oracle@prod1_2Recovery Manager: Release 11.2.0.4.0 - Production on Sat Mar 2 16:03:55 2019Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.connected to target database: PROD1 (DBID=2223201576)connected to auxiliary database: PROD1 (not mounted) RMAN> duplicate target database for standby from active database nofilenamecheck;Starting Duplicate Db at 2019-03-02 16:04:03using target database control file instead of recovery catalogallocated channel: ORA_AUX_DISK_1channel ORA_AUX_DISK_1: SID=10 device type=DISKcontents of Memory Script:{ backup as copy reuse targetfile '/u01/app/oracle/product/11.2.0/db_1/dbs/orapwPROD1' auxiliary format '/u01/app/oracle/product/11.2.0/db_1/dbs/orapwPROD2' ;}executing Memory ScriptStarting backup at 2019-03-02 16:04:03allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=144 device type=DISKFinished backup at 2019-03-02 16:04:04contents of Memory Script:{ backup as copy current controlfile for standby auxiliary format '/u01/app/oracle/oradata/PROD1/control01.ctl'; restore clone controlfile to '/u01/app/oracle/fast_recovery_area/PROD1/control02.ctl' from '/u01/app/oracle/oradata/PROD1/control01.ctl';}executing Memory ScriptStarting backup at 2019-03-02 16:04:04using channel ORA_DISK_1channel ORA_DISK_1: starting datafile copycopying standby control fileoutput file name=/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_PROD1.f tag=TAG20190302T160404 RECID=6 STAMP=1001865845channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03Finished backup at 2019-03-02 16:04:08Starting restore at 2019-03-02 16:04:08using channel ORA_AUX_DISK_1channel ORA_AUX_DISK_1: copied control file copyFinished restore at 2019-03-02 16:04:09contents of Memory Script:{ sql clone 'alter database mount standby database';}executing Memory Scriptsql statement: alter database mount standby databasecontents of Memory Script:{ set newname for tempfile 1 to "/u01/app/oracle/oradata/PROD1/temp01.dbf"; switch clone tempfile all; set newname for datafile 1 to "/u01/app/oracle/oradata/PROD1/system01.dbf"; set newname for datafile 2 to "/u01/app/oracle/oradata/PROD1/sysaux01.dbf"; set newname for datafile 3 to "/u01/app/oracle/oradata/PROD1/undotbs01.dbf"; set newname for datafile 4 to "/u01/app/oracle/oradata/PROD1/users01.dbf"; set newname for datafile 5 to "/u01/app/oracle/oradata/PROD1/example01.dbf"; backup as copy reuse datafile 1 auxiliary format "/u01/app/oracle/oradata/PROD1/system01.dbf" datafile 2 auxiliary format "/u01/app/oracle/oradata/PROD1/sysaux01.dbf" datafile 3 auxiliary format "/u01/app/oracle/oradata/PROD1/undotbs01.dbf" datafile 4 auxiliary format "/u01/app/oracle/oradata/PROD1/users01.dbf" datafile 5 auxiliary format "/u01/app/oracle/oradata/PROD1/example01.dbf" ; sql 'alter system archive log current';}executing Memory Scriptexecuting command: SET NEWNAMErenamed tempfile 1 to /u01/app/oracle/oradata/PROD1/temp01.dbf in control fileexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEStarting backup at 2019-03-02 16:04:14using channel ORA_DISK_1channel ORA_DISK_1: starting datafile copyinput datafile file number=00001 name=/u01/app/oracle/oradata/PROD1/system01.dbfoutput file name=/u01/app/oracle/oradata/PROD1/system01.dbf tag=TAG20190302T160414channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25channel ORA_DISK_1: starting datafile copyinput datafile file number=00002 name=/u01/app/oracle/oradata/PROD1/sysaux01.dbfoutput file name=/u01/app/oracle/oradata/PROD1/sysaux01.dbf tag=TAG20190302T160414channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15channel ORA_DISK_1: starting datafile copyinput datafile file number=00005 name=/u01/app/oracle/oradata/PROD1/example01.dbfoutput file name=/u01/app/oracle/oradata/PROD1/example01.dbf tag=TAG20190302T160414channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15channel ORA_DISK_1: starting datafile copyinput datafile file number=00003 name=/u01/app/oracle/oradata/PROD1/undotbs01.dbfoutput file name=/u01/app/oracle/oradata/PROD1/undotbs01.dbf tag=TAG20190302T160414channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03channel ORA_DISK_1: starting datafile copyinput datafile file number=00004 name=/u01/app/oracle/oradata/PROD1/users01.dbfoutput file name=/u01/app/oracle/oradata/PROD1/users01.dbf tag=TAG20190302T160414channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01Finished backup at 2019-03-02 16:05:14sql statement: alter system archive log currentcontents of Memory Script:{ switch clone datafile all;}executing Memory Scriptdatafile 1 switched to datafile copyinput datafile copy RECID=6 STAMP=1001878035 file name=/u01/app/oracle/oradata/PROD1/system01.dbfdatafile 2 switched to datafile copyinput datafile copy RECID=7 STAMP=1001878035 file name=/u01/app/oracle/oradata/PROD1/sysaux01.dbfdatafile 3 switched to datafile copyinput datafile copy RECID=8 STAMP=1001878035 file name=/u01/app/oracle/oradata/PROD1/undotbs01.dbfdatafile 4 switched to datafile copyinput datafile copy RECID=9 STAMP=1001878035 file name=/u01/app/oracle/oradata/PROD1/users01.dbfdatafile 5 switched to datafile copyinput datafile copy RECID=10 STAMP=1001878035 file name=/u01/app/oracle/oradata/PROD1/example01.dbfFinished Duplicate Db at 2019-03-02 16:05:21
[oracle@test1 ~]$ rman target sys/oracle@prod1_1 auxiliary sys/oracle@prod1_5Recovery Manager: Release 11.2.0.4.0 - Production on Sat Mar 2 16:05:39 2019Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.connected to target database: PROD1 (DBID=2223201576)connected to auxiliary database: PROD1 (not mounted) RMAN> duplicate target database for standby from active database nofilenamecheck;Starting Duplicate Db at 2019-03-02 16:05:42using target database control file instead of recovery catalogallocated channel: ORA_AUX_DISK_1channel ORA_AUX_DISK_1: SID=10 device type=DISKcontents of Memory Script:{ backup as copy reuse targetfile '/u01/app/oracle/product/11.2.0/db_1/dbs/orapwPROD1' auxiliary format '/u01/app/oracle/product/11.2.0/db_1/dbs/orapwPROD5' ;}executing Memory ScriptStarting backup at 2019-03-02 16:05:42allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=125 device type=DISKFinished backup at 2019-03-02 16:05:43contents of Memory Script:{ backup as copy current controlfile for standby auxiliary format '/u01/app/oracle/oradata/PROD1/control01.ctl'; restore clone controlfile to '/u01/app/oracle/fast_recovery_area/PROD1/control02.ctl' from '/u01/app/oracle/oradata/PROD1/control01.ctl';}executing Memory ScriptStarting backup at 2019-03-02 16:05:43using channel ORA_DISK_1channel ORA_DISK_1: starting datafile copycopying standby control fileoutput file name=/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_PROD1.f tag=TAG20190302T160543 RECID=7 STAMP=1001865944channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01Finished backup at 2019-03-02 16:05:44Starting restore at 2019-03-02 16:05:44using channel ORA_AUX_DISK_1channel ORA_AUX_DISK_1: copied control file copyFinished restore at 2019-03-02 16:05:46contents of Memory Script:{ sql clone 'alter database mount standby database';}executing Memory Scriptsql statement: alter database mount standby databasecontents of Memory Script:{ set newname for tempfile 1 to "/u01/app/oracle/oradata/PROD1/temp01.dbf"; switch clone tempfile all; set newname for datafile 1 to "/u01/app/oracle/oradata/PROD1/system01.dbf"; set newname for datafile 2 to "/u01/app/oracle/oradata/PROD1/sysaux01.dbf"; set newname for datafile 3 to "/u01/app/oracle/oradata/PROD1/undotbs01.dbf"; set newname for datafile 4 to "/u01/app/oracle/oradata/PROD1/users01.dbf"; set newname for datafile 5 to "/u01/app/oracle/oradata/PROD1/example01.dbf"; backup as copy reuse datafile 1 auxiliary format "/u01/app/oracle/oradata/PROD1/system01.dbf" datafile 2 auxiliary format "/u01/app/oracle/oradata/PROD1/sysaux01.dbf" datafile 3 auxiliary format "/u01/app/oracle/oradata/PROD1/undotbs01.dbf" datafile 4 auxiliary format "/u01/app/oracle/oradata/PROD1/users01.dbf" datafile 5 auxiliary format "/u01/app/oracle/oradata/PROD1/example01.dbf" ; sql 'alter system archive log current';}executing Memory Scriptexecuting command: SET NEWNAMErenamed tempfile 1 to /u01/app/oracle/oradata/PROD1/temp01.dbf in control fileexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEStarting backup at 2019-03-02 16:05:51using channel ORA_DISK_1channel ORA_DISK_1: starting datafile copyinput datafile file number=00001 name=/u01/app/oracle/oradata/PROD1/system01.dbfoutput file name=/u01/app/oracle/oradata/PROD1/system01.dbf tag=TAG20190302T160551channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25channel ORA_DISK_1: starting datafile copyinput datafile file number=00002 name=/u01/app/oracle/oradata/PROD1/sysaux01.dbfoutput file name=/u01/app/oracle/oradata/PROD1/sysaux01.dbf tag=TAG20190302T160551channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15channel ORA_DISK_1: starting datafile copyinput datafile file number=00005 name=/u01/app/oracle/oradata/PROD1/example01.dbfoutput file name=/u01/app/oracle/oradata/PROD1/example01.dbf tag=TAG20190302T160551channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15channel ORA_DISK_1: starting datafile copyinput datafile file number=00003 name=/u01/app/oracle/oradata/PROD1/undotbs01.dbfoutput file name=/u01/app/oracle/oradata/PROD1/undotbs01.dbf tag=TAG20190302T160551channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03channel ORA_DISK_1: starting datafile copyinput datafile file number=00004 name=/u01/app/oracle/oradata/PROD1/users01.dbfoutput file name=/u01/app/oracle/oradata/PROD1/users01.dbf tag=TAG20190302T160551channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01Finished backup at 2019-03-02 16:06:50sql statement: alter system archive log currentcontents of Memory Script:{ switch clone datafile all;}executing Memory Scriptdatafile 1 switched to datafile copyinput datafile copy RECID=7 STAMP=1001878132 file name=/u01/app/oracle/oradata/PROD1/system01.dbfdatafile 2 switched to datafile copyinput datafile copy RECID=8 STAMP=1001878132 file name=/u01/app/oracle/oradata/PROD1/sysaux01.dbfdatafile 3 switched to datafile copyinput datafile copy RECID=9 STAMP=1001878132 file name=/u01/app/oracle/oradata/PROD1/undotbs01.dbfdatafile 4 switched to datafile copyinput datafile copy RECID=10 STAMP=1001878132 file name=/u01/app/oracle/oradata/PROD1/users01.dbfdatafile 5 switched to datafile copyinput datafile copy RECID=11 STAMP=1001878132 file name=/u01/app/oracle/oradata/PROD1/example01.dbfFinished Duplicate Db at 2019-03-02 16:06:58
(五) 开启实时同步
test2&test5:SQL> alter database open;Database altered. SQL> recover managed standby database using current logfile disconnect from session;Media recovery complete.
(六) 备库均开启flashback
test2&test5:SQL> alter database recover managed standby database cancel;Database altered.SQL> shutdown immediate ;Database closed.Database dismounted.ORACLE instance shut down.SQL> startup mount ;ORACLE instance started.Total System Global Area 1219260416 bytesFixed Size 2252744 bytesVariable Size 788529208 bytesDatabase Buffers 419430400 bytesRedo Buffers 9048064 bytesDatabase mounted.SQL> alter database flashback on;Database altered.SQL> alter database open;Database altered.SQL> alter database recover managed standby database using current logfile disconnect from session; Database altered.
(七) 验证DG同步
上面已经把Data Gurad搭建完,下面介绍如何验证Data Guard是否能实时同步:
1. 通过查看archive_log_dest_2、archive_log_dest_3列是否有error报错,如果有报错,则需要先根据报错内容解决问题:
test1:SQL> set linesize 150SQL> col dest_name format a30SQL> col error format a20SQL> select dest_name,error from v$archive_dest; DEST_NAME ERROR------------------------------ --------------------LOG_ARCHIVE_DEST_1LOG_ARCHIVE_DEST_2LOG_ARCHIVE_DEST_3LOG_ARCHIVE_DEST_4LOG_ARCHIVE_DEST_5LOG_ARCHIVE_DEST_6LOG_ARCHIVE_DEST_7LOG_ARCHIVE_DEST_8LOG_ARCHIVE_DEST_9LOG_ARCHIVE_DEST_10LOG_ARCHIVE_DEST_11 DEST_NAME ERROR------------------------------ --------------------LOG_ARCHIVE_DEST_12LOG_ARCHIVE_DEST_13LOG_ARCHIVE_DEST_14LOG_ARCHIVE_DEST_15LOG_ARCHIVE_DEST_16LOG_ARCHIVE_DEST_17LOG_ARCHIVE_DEST_18LOG_ARCHIVE_DEST_19LOG_ARCHIVE_DEST_20LOG_ARCHIVE_DEST_21LOG_ARCHIVE_DEST_22DEST_NAME ERROR------------------------------ --------------------LOG_ARCHIVE_DEST_23LOG_ARCHIVE_DEST_24LOG_ARCHIVE_DEST_25LOG_ARCHIVE_DEST_26LOG_ARCHIVE_DEST_27LOG_ARCHIVE_DEST_28LOG_ARCHIVE_DEST_29LOG_ARCHIVE_DEST_30LOG_ARCHIVE_DEST_31 31 rows selected.
注意:上面显示没有报错
2. 查询主库最大归档序号,一致即归档同步成功。
test1:SQL> select max(sequence#) from v$archived_log;MAX(SEQUENCE#)-------------- 26 test2&test5:SQL> select max(sequence#) from v$archived_log;MAX(SEQUENCE#)-------------- 26 test1:SQL> alter system archive log current;System altered. SQL> select max(sequence#) from v$archived_log;MAX(SEQUENCE#)-------------- 27 test2&test5:SQL> select max(sequence#) from v$archived_log;MAX(SEQUENCE#)-------------- 27
3. 查看主备库状态
test1:SQL> select open_mode,database_role,switchover_status from v$database; OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS---------------- ----------------- --------------------READ WRITE PRIMARY TO STANDBY test2&test5:SQL> select open_mode,database_role,switchover_status from v$database; OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS------------------------ -------------------- ---------------READ ONLY WITH APPLY PHYSICAL STANDBY NOT ALLOWED
4. 在test1上创建一个table测试
test1:SQL> create table dg(id number);Table created. SQL> insert into dg values(1);1 row created. SQL> commit;Commit complete. SQL> select * from dg; ID---------- 1 test2&test5:SQL> select * from dg; ID---------- 1
四、 DG切换与恢复
我们配置DG的目的就是为了在主库出现故障时,备库能够提供服务,保证业务的正常运行。DG的故障切换分为switchover和failover两种:
(一) switchover
switchover是用户有计划的进行停机切换,能够保证不丢失数据。以下是具体操作:
1. switchover1
SQL> select open_mode,database_role,switchover_status from v$database;OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS-------------------- --------------------- ---------------------READ WRITE PRIMARY SESSIONS ACTIVE
注意:上面查询结果为TO STANDBY 或 SESSIONS ACTIVE表明可以进行切换
SQL> alter database commit to switchover to physical standby;Database altered. SQL> conn / as sysdba;Connected to an idle instance. SQL> startup ORACLE instance started. Total System Global Area 1219260416 bytesFixed Size 2252744 bytesVariable Size 939524152 bytesDatabase Buffers 268435456 bytesRedo Buffers 9048064 bytesDatabase mounted.Database opened.SQL> set linesize 150SQL> select open_mode,database_role,switchover_status from v$database; OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS--------------------- ------------------------ --------------------READ ONLY PHYSICAL STANDBY TO PRIMARY test5:SQL> recover managed standby database cancel;Media recovery complete. SQL> select open_mode,database_role,switchover_status from v$database;OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS-------------------- ------------------------- --------------------READ ONLY PHYSICAL STANDBY TO PRIMARY SQL> alter database commit to switchover to primary;Database altered. SQL> select open_mode,database_role,switchover_status from v$database;OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS-------------------- --------------------- --------------------MOUNTED PRIMARY NOT ALLOWED SQL> alter database open;Database altered. SQL> insert into t1 values (1);1 row created. SQL> commit;Commit complete. SQL> select * from t1; ID---------- 1 test1:SQL> select * from t1;no rows selected SQL> recover managed standby database using current logfile disconnect from session;Media recovery complete. SQL> select * from t1; ID---------- 1 test2:SQL> recover managed standby database cancel;Media recovery complete. SQL> select open_mode,database_role,switchover_status from v$database;OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS-------------------- ------------------------- --------------------READ ONLY PHYSICAL STANDBY TO PRIMARY SQL> recover managed standby database using current logfile disconnect from session;Media recovery complete. SQL> select * from t1; ID---------- 1 1. switchover1test5:SQL> alter database commit to switchover to physical standby;Database altered. SQL> conn / as sysdba;Connected to an idle instance. SQL> startup ORACLE instance started.Total System Global Area 1219260416 bytesFixed Size 2252744 bytesVariable Size 788529208 bytesDatabase Buffers 419430400 bytesRedo Buffers 9048064 bytesDatabase mounted.Database opened. SQL> select open_mode,database_role,switchover_status from v$database; OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS-------------------- ------------------------- ------------------READ ONLY PHYSICAL STANDBY TO PRIMARY test2:SQL> recover managed standby database cancel;Media recovery complete. SQL> select open_mode,database_role,switchover_status from v$database;OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS-------------------- ------------------------- -------------------READ ONLY PHYSICAL STANDBY TO PRIMARY SQL> alter database commit to switchover to primary;Database altered. SQL> select open_mode,database_role,switchover_status from v$database;OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS--------------------- -------------------- -------------------MOUNTED PRIMARY NOT ALLOWED SQL> alter database open;Database altered. SQL> insert into t1 values (2);1 row created. SQL> commit;Commit complete. SQL> select * from t1; ID---------- 1 2 test5:SQL> select * from t1; ID---------- 1 SQL> recover managed standby database using current logfile disconnect from session;Media recovery complete. SQL> select * from t1; ID---------- 1 2 SQL> select open_mode,database_role,switchover_status from v$database;OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS------------------------ ------------------------- --------------------READ ONLY WITH APPLY PHYSICAL STANDBY NOT ALLOWED test1:SQL> recover managed standby database cancel;Media recovery complete. SQL> select open_mode,database_role,switchover_status from v$database;OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS-------------------- ------------------------- -------------------READ ONLY PHYSICAL STANDBY TO PRIMARY SQL> select * from t1; ID---------- 1 SQL> recover managed standby database using current logfile disconnect from session;Media recovery complete. SQL> select * from t1; ID---------- 1 2 SQL> select open_mode,database_role,switchover_status from v$database;OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS------------------------ ------------------------- -------------------READ ONLY WITH APPLY PHYSICAL STANDBY NOT ALLOWED
到此DG switover切换完成,验证方法同上。
到此DG switover切换完成,验证方法同上。
(二) failover
failover是当主库真正出现严重系统故障,如数据库宕机,软硬件故障导致主库不能支持服务,从而进行的切换动作。
注意:为了能够在failover后能够恢复DG,需要在主库上开启flashback,如果不开启flashback的话,DG就可能需要重新搭建。
由于主库已经不可访问,下面所有的操作都在备库完成:
(三) failover恢复
上面提到了failover,这种情形是当主库真正出现异常之后,才会执行的操作,那么我们执行过failover 之后,如何再重新构建DG,这里我们利用flashback database来重构,具体方法如下:
到此,关于"Oracle Data Guard部署方法是什么"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!