这篇文章主要介绍“Oracle Data Guard部署方法是什么”,在日常操作中,相信很多人在Oracle Data Guard部署方法是什么问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Oracle Data Guard部署方法是什么”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
本实施方案主要对Oracle DataGuard实施部署作相应的说明。以便能根据当前业务特点,规划、建设符合高可用、高可靠的数据库集群系统。
数据库服务器采用Data Guard灾备模式,可以满足对可用性有特殊需求的应用,具备以下特点:
1. 需要冗余的服务器设备,该模式需要有冗余的服务器硬件,硬件成本较高。
2. 需要冗余的存储设备,主机和备机都需要同样的存储空间,成本较高。
3. 安装配置比较复杂,该模式比单节点、单实例的模式配置复杂一些,需要更多的配置步骤。
4. 管理维护成本高,该模式对维护人员的要求较高,维护成本高。
5. 具备一定的容灾特性。当主机整个数据库系统不可用并短期内无法恢复时,可以把数据库系统切换到备机上,具备容灾的功能。
6. 备机可以用作只读查询,备机可以切换到只读状态供报表之类的查询操作,减轻主机的压力。
主机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 sysdba SQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 3 08:07:15 2019 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to an idle instance. SQL> startup mount; ORACLE instance started. Total System Global Area 1219260416 bytes Fixed Size 2252744 bytes Variable Size 788529208 bytes Database Buffers 419430400 bytes Redo Buffers 9048064 bytes Database 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 open Database dismounted. ORACLE instance shut down. SQL> startup mount; ORACLE instance started. Total System Global Area 1219260416 bytes Fixed Size 2252744 bytes Variable Size 788529208 bytes Database Buffers 419430400 bytes Redo Buffers 9048064 bytes Database 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_ ------ NO SQL> 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> exit Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options [oracle@test1 dbs]$ ls hc_PROD1.dat init.ora initPROD1.ora lkPROD1 orapwPROD1 spfilePROD1.ora [oracle@test1 dbs]$ cat initPROD1.ora PROD1.__db_cache_size=419430400 PROD1.__java_pool_size=16777216 PROD1.__large_pool_size=83886080 PROD1.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment PROD1.__pga_aggregate_target=503316480 PROD1.__sga_target=721420288 PROD1.__shared_io_pool_size=0 PROD1.__shared_pool_size=184549376 PROD1.__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=419430400 PROD2.__java_pool_size=16777216 PROD2.__large_pool_size=83886080 PROD2.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment PROD2.__pga_aggregate_target=503316480 PROD2.__sga_target=721420288 PROD2.__shared_io_pool_size=0 PROD2.__shared_pool_size=184549376 PROD2.__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=469762048 PROD5.__java_pool_size=16777216 PROD5.__large_pool_size=33554432 PROD5.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment PROD5.__pga_aggregate_target=503316480 PROD5.__sga_target=721420288 PROD5.__shared_io_pool_size=0 PROD5.__shared_pool_size=184549376 PROD5.__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=PROD5 LOG_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=ENABLE LOG_ARCHIVE_DEST_STATE_2=ENABLE LOG_ARCHIVE_DEST_STATE_3=ENABLE REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE LOG_ARCHIVE_FORMAT=%t_%s_%r.arc LOG_ARCHIVE_MAX_PROCESSES=30 FAL_SERVER=PROD1 FAL_CLIENT=PROD2,PROD5 STANDBY_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 sysdba SQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 3 08:04:27 2019 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to an idle instance. SQL> startup nomount; ORACLE instance started. Total System Global Area 1219260416 bytes Fixed Size 2252744 bytes Variable Size 788529208 bytes Database Buffers 419430400 bytes Redo Buffers 9048064 bytes
[oracle@test5 dbs]$ export ORACLE_SID=PROD5 [oracle@test5 dbs]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 3 08:04:47 2019 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to an idle instance. SQL> startup nomount; ORACLE instance started. Total System Global Area 1219260416 bytes Fixed Size 2252744 bytes Variable Size 788529208 bytes Database Buffers 419430400 bytes Redo Buffers 9048064 bytes
7. 验证监听和TNS配置
主备库上都需要验证
[oracle@test1 dbs]$ sqlplus sys/oracle@PROD1_1 as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 3 05:35:15 2019 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, OLAP, Data Mining and Real Application Testing options SQL> quit Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options [oracle@test1 dbs]$ sqlplus sys/oracle@PROD1_2 as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 3 05:35:54 2019 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, OLAP, Data Mining and Real Application Testing options SQL> quit Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options [oracle@test1 dbs]$ sqlplus sys/oracle@PROD1_5 as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Sun Mar 3 05:36:02 2019 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, OLAP, Data Mining and Real Application Testing options SQL> quit Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options
注意:该步骤一定要在主备库上都能通过才能执行下面步骤
[oracle@test1 ~]$ rman target sys/oracle@prod1_1 auxiliary sys/oracle@prod1_2 Recovery Manager: Release 11.2.0.4.0 - Production on Sat Mar 2 16:03:55 2019 Copyright (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:03 using target database control file instead of recovery catalog allocated channel: ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: SID=10 device type=DISK contents 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 Script Starting backup at 2019-03-02 16:04:03 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=144 device type=DISK Finished backup at 2019-03-02 16:04:04 contents 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 Script Starting backup at 2019-03-02 16:04:04 using channel ORA_DISK_1 channel ORA_DISK_1: starting datafile copy copying standby control file output file name=/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_PROD1.f tag=TAG20190302T160404 RECID=6 STAMP=1001865845 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03 Finished backup at 2019-03-02 16:04:08 Starting restore at 2019-03-02 16:04:08 using channel ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: copied control file copy Finished restore at 2019-03-02 16:04:09 contents of Memory Script: { sql clone 'alter database mount standby database'; } executing Memory Script sql statement: alter database mount standby database contents 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 Script executing command: SET NEWNAME renamed tempfile 1 to /u01/app/oracle/oradata/PROD1/temp01.dbf in control file executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME Starting backup at 2019-03-02 16:04:14 using channel ORA_DISK_1 channel ORA_DISK_1: starting datafile copy input datafile file number=00001 name=/u01/app/oracle/oradata/PROD1/system01.dbf output file name=/u01/app/oracle/oradata/PROD1/system01.dbf tag=TAG20190302T160414 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25 channel ORA_DISK_1: starting datafile copy input datafile file number=00002 name=/u01/app/oracle/oradata/PROD1/sysaux01.dbf output file name=/u01/app/oracle/oradata/PROD1/sysaux01.dbf tag=TAG20190302T160414 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15 channel ORA_DISK_1: starting datafile copy input datafile file number=00005 name=/u01/app/oracle/oradata/PROD1/example01.dbf output file name=/u01/app/oracle/oradata/PROD1/example01.dbf tag=TAG20190302T160414 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15 channel ORA_DISK_1: starting datafile copy input datafile file number=00003 name=/u01/app/oracle/oradata/PROD1/undotbs01.dbf output file name=/u01/app/oracle/oradata/PROD1/undotbs01.dbf tag=TAG20190302T160414 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03 channel ORA_DISK_1: starting datafile copy input datafile file number=00004 name=/u01/app/oracle/oradata/PROD1/users01.dbf output file name=/u01/app/oracle/oradata/PROD1/users01.dbf tag=TAG20190302T160414 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01 Finished backup at 2019-03-02 16:05:14 sql statement: alter system archive log current contents of Memory Script: { switch clone datafile all; } executing Memory Script datafile 1 switched to datafile copy input datafile copy RECID=6 STAMP=1001878035 file name=/u01/app/oracle/oradata/PROD1/system01.dbf datafile 2 switched to datafile copy input datafile copy RECID=7 STAMP=1001878035 file name=/u01/app/oracle/oradata/PROD1/sysaux01.dbf datafile 3 switched to datafile copy input datafile copy RECID=8 STAMP=1001878035 file name=/u01/app/oracle/oradata/PROD1/undotbs01.dbf datafile 4 switched to datafile copy input datafile copy RECID=9 STAMP=1001878035 file name=/u01/app/oracle/oradata/PROD1/users01.dbf datafile 5 switched to datafile copy input datafile copy RECID=10 STAMP=1001878035 file name=/u01/app/oracle/oradata/PROD1/example01.dbf Finished Duplicate Db at 2019-03-02 16:05:21
[oracle@test1 ~]$ rman target sys/oracle@prod1_1 auxiliary sys/oracle@prod1_5 Recovery Manager: Release 11.2.0.4.0 - Production on Sat Mar 2 16:05:39 2019 Copyright (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:42 using target database control file instead of recovery catalog allocated channel: ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: SID=10 device type=DISK contents 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 Script Starting backup at 2019-03-02 16:05:42 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=125 device type=DISK Finished backup at 2019-03-02 16:05:43 contents 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 Script Starting backup at 2019-03-02 16:05:43 using channel ORA_DISK_1 channel ORA_DISK_1: starting datafile copy copying standby control file output file name=/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_PROD1.f tag=TAG20190302T160543 RECID=7 STAMP=1001865944 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01 Finished backup at 2019-03-02 16:05:44 Starting restore at 2019-03-02 16:05:44 using channel ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: copied control file copy Finished restore at 2019-03-02 16:05:46 contents of Memory Script: { sql clone 'alter database mount standby database'; } executing Memory Script sql statement: alter database mount standby database contents 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 Script executing command: SET NEWNAME renamed tempfile 1 to /u01/app/oracle/oradata/PROD1/temp01.dbf in control file executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME Starting backup at 2019-03-02 16:05:51 using channel ORA_DISK_1 channel ORA_DISK_1: starting datafile copy input datafile file number=00001 name=/u01/app/oracle/oradata/PROD1/system01.dbf output file name=/u01/app/oracle/oradata/PROD1/system01.dbf tag=TAG20190302T160551 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25 channel ORA_DISK_1: starting datafile copy input datafile file number=00002 name=/u01/app/oracle/oradata/PROD1/sysaux01.dbf output file name=/u01/app/oracle/oradata/PROD1/sysaux01.dbf tag=TAG20190302T160551 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15 channel ORA_DISK_1: starting datafile copy input datafile file number=00005 name=/u01/app/oracle/oradata/PROD1/example01.dbf output file name=/u01/app/oracle/oradata/PROD1/example01.dbf tag=TAG20190302T160551 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15 channel ORA_DISK_1: starting datafile copy input datafile file number=00003 name=/u01/app/oracle/oradata/PROD1/undotbs01.dbf output file name=/u01/app/oracle/oradata/PROD1/undotbs01.dbf tag=TAG20190302T160551 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03 channel ORA_DISK_1: starting datafile copy input datafile file number=00004 name=/u01/app/oracle/oradata/PROD1/users01.dbf output file name=/u01/app/oracle/oradata/PROD1/users01.dbf tag=TAG20190302T160551 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01 Finished backup at 2019-03-02 16:06:50 sql statement: alter system archive log current contents of Memory Script: { switch clone datafile all; } executing Memory Script datafile 1 switched to datafile copy input datafile copy RECID=7 STAMP=1001878132 file name=/u01/app/oracle/oradata/PROD1/system01.dbf datafile 2 switched to datafile copy input datafile copy RECID=8 STAMP=1001878132 file name=/u01/app/oracle/oradata/PROD1/sysaux01.dbf datafile 3 switched to datafile copy input datafile copy RECID=9 STAMP=1001878132 file name=/u01/app/oracle/oradata/PROD1/undotbs01.dbf datafile 4 switched to datafile copy input datafile copy RECID=10 STAMP=1001878132 file name=/u01/app/oracle/oradata/PROD1/users01.dbf datafile 5 switched to datafile copy input datafile copy RECID=11 STAMP=1001878132 file name=/u01/app/oracle/oradata/PROD1/example01.dbf Finished 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.
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 bytes Fixed Size 2252744 bytes Variable Size 788529208 bytes Database Buffers 419430400 bytes Redo Buffers 9048064 bytes Database 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.
上面已经把Data Gurad搭建完,下面介绍如何验证Data Guard是否能实时同步:
1. 通过查看archive_log_dest_2、archive_log_dest_3列是否有error报错,如果有报错,则需要先根据报错内容解决问题:
test1: SQL> set linesize 150 SQL> col dest_name format a30 SQL> col error format a20 SQL> select dest_name,error from v$archive_dest; DEST_NAME ERROR ------------------------------ -------------------- LOG_ARCHIVE_DEST_1 LOG_ARCHIVE_DEST_2 LOG_ARCHIVE_DEST_3 LOG_ARCHIVE_DEST_4 LOG_ARCHIVE_DEST_5 LOG_ARCHIVE_DEST_6 LOG_ARCHIVE_DEST_7 LOG_ARCHIVE_DEST_8 LOG_ARCHIVE_DEST_9 LOG_ARCHIVE_DEST_10 LOG_ARCHIVE_DEST_11 DEST_NAME ERROR ------------------------------ -------------------- LOG_ARCHIVE_DEST_12 LOG_ARCHIVE_DEST_13 LOG_ARCHIVE_DEST_14 LOG_ARCHIVE_DEST_15 LOG_ARCHIVE_DEST_16 LOG_ARCHIVE_DEST_17 LOG_ARCHIVE_DEST_18 LOG_ARCHIVE_DEST_19 LOG_ARCHIVE_DEST_20 LOG_ARCHIVE_DEST_21 LOG_ARCHIVE_DEST_22 DEST_NAME ERROR ------------------------------ -------------------- LOG_ARCHIVE_DEST_23 LOG_ARCHIVE_DEST_24 LOG_ARCHIVE_DEST_25 LOG_ARCHIVE_DEST_26 LOG_ARCHIVE_DEST_27 LOG_ARCHIVE_DEST_28 LOG_ARCHIVE_DEST_29 LOG_ARCHIVE_DEST_30 LOG_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的故障切换分为switchover和failover两种:
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 bytes Fixed Size 2252744 bytes Variable Size 939524152 bytes Database Buffers 268435456 bytes Redo Buffers 9048064 bytes Database mounted. Database opened. SQL> set linesize 150 SQL> 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. switchover1 test5: 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 bytes Fixed Size 2252744 bytes Variable Size 788529208 bytes Database Buffers 419430400 bytes Redo Buffers 9048064 bytes Database 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后能够恢复DG,需要在主库上开启flashback,如果不开启flashback的话,DG就可能需要重新搭建。
由于主库已经不可访问,下面所有的操作都在备库完成:
上面提到了failover,这种情形是当主库真正出现异常之后,才会执行的操作,那么我们执行过failover 之后,如何再重新构建DG,这里我们利用flashback database来重构,具体方法如下:
到此,关于“Oracle Data Guard部署方法是什么”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。