Oracle数据库灾难恢复教程构建强大的DG双活防护体系(oracle dg教程)
Oracle数据库灾难恢复教程:构建强大的DG双活防护体系
在企业的生产环境中,一旦遭遇数据丢失或系统崩溃等灾难,就可能影响到企业的正常运营。为了解决这个问题,Oracle提供了一个双活(DG)方案,能够实现数据库的热备份和灾难恢复。本文将详细介绍如何构建一个高可靠的双活防护体系。
实验环境说明
本实验环境基于Oracle 12c数据库和Linux系统进行搭建。主服务器为主节点,副服务器为备节点,两台服务器间通过公共网段进行通信。
配置主节点
1. 创建数据文件和日志文件
在主节点上,创建数据文件和日志文件,并设置文件大小和块数,具体操作如下:
SQL> create tablespace dg_data datafile '/u01/app/oracle/oradata/orcl/dg_data.dbf' size 100M blocksize 8K;
SQL> create tablespace dg_indx datafile '/u01/app/oracle/oradata/orcl/dg_indx.dbf' size 50M blocksize 8K;SQL> alter database add logfile group 1 ('/u01/app/oracle/oradata/orcl/redo01.log') size 50M;
SQL> alter database add logfile group 2 ('/u01/app/oracle/oradata/orcl/redo02.log') size 50M;SQL> alter database add logfile group 3 ('/u01/app/oracle/oradata/orcl/redo03.log') size 50M;
2. 开启归档模式
在主节点上开启归档模式,并设置归档目录,具体操作如下:
SQL> shutdown immediate;
SQL> startup mount;SQL> alter database archivelog;
SQL> alter database open;SQL> archive log list;
SQL> alter system set log_archive_dest_1='location=/u01/app/oracle/archivelog' scope=both;
3. 创建同步复制组
在主节点上创建一个同步复制组,具体操作如下:
SQL> alter system set dg_broker_start=true;
SQL> alter system set dg_broker_config_file1='/u01/app/oracle/product/12.1.0/dbhome_1/dbs/dr1_orcl.dat' scope=both;SQL> alter system set dg_broker_config_file2='/u01/app/oracle/product/12.1.0/dbhome_1/dbs/dr2_orcl.dat' scope=both;
SQL> alter system set log_archive_dest_2='service=dr1' scope=both;SQL> alter system set log_archive_dest_3='service=dr2' scope=both;
SQL> alter system set dg_broker_config_file1='/u01/app/oracle/product/12.1.0/dbhome_1/dbs/dr1_orcl.dat' scope=both;SQL> alter system set dg_broker_config_file2='/u01/app/oracle/product/12.1.0/dbhome_1/dbs/dr2_orcl.dat' scope=both;
SQL> alter system set service_names='orcl,dr1,dr2' scope=spfile;SQL> create database link dr1 connect to system identified by Password using 'dr1';
SQL> create database link dr2 connect to system identified by Password using 'dr2';SQL> alter system switch logfile;
如上所示,创建了两个同步复制组,分别为dr1和dr2。并且配置了归档目录,以及创建了dr1和dr2的数据库链接。
配置备节点
1. 在备节点上创建数据文件和日志文件
在备节点上创建数据文件和日志文件,并设置文件大小和块数,具体操作如下:
SQL> create tablespace dg_data datafile '/u01/app/oracle/oradata/orcl/dg_data.dbf' size 100M blocksize 8K;
SQL> create tablespace dg_indx datafile '/u01/app/oracle/oradata/orcl/dg_indx.dbf' size 50M blocksize 8K;SQL> alter database add logfile group 1 ('/u01/app/oracle/oradata/orcl/redo01.log') size 50M;
SQL> alter database add logfile group 2 ('/u01/app/oracle/oradata/orcl/redo02.log') size 50M;SQL> alter database add logfile group 3 ('/u01/app/oracle/oradata/orcl/redo03.log') size 50M;
2. 还原主节点备份到备节点
在备节点上还原主节点的备份,并创建数据字典。这里假设主节点的备份已经存储在了/u01/app/oracle/backup目录下。
$ cp /u01/app/oracle/backup/backup. /tmp
$ cd /tmp$ tar -xf backup.
$ su - oracle$ export ORACLE_SID=orcl
$ rman target sys/Password@orcl auxiliary sys/Password@orclRMAN> run {
allocate channel ch1 type disk;restore controlfile from '/tmp/controlfile.';
alter database mount standby database;recover standby database;
}
3. 开启归档模式
在备节点上开启归档模式,并设置归档目录,具体操作如下:
SQL> shutdown immediate;
SQL> startup mount;SQL> alter database archivelog;
SQL> alter database open;SQL> archive log list;
SQL> alter system set log_archive_dest_1='location=/u01/app/oracle/archivelog' scope=both;
配置主备节点
1. 在主备节点上创建tnsnames.ora文件
在主备节点上创建tnsnames.ora文件,配置主备节点之间的监听,具体操作如下:
$ cd $ORACLE_HOME/network/admin
$ vi tnsnames.ora
ORCL = (DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 主服务器IP)(PORT = 1521)) (CONNECT_DATA =
(SERVER = DEDICATED) (SERVICE_NAME = orcl)
) )
DR1 = (DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 备服务器IP)(PORT = 1521)) (CONNECT_DATA =
(SERVER = DEDICATED) (SERVICE_NAME = dr1)
) )
DR2 = (DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 备服务器IP)(PORT = 1521)) (CONNECT_DATA =
(SERVER = DEDICATED) (SERVICE_NAME = dr2)
) )
2. 在主备节点的listener.ora文件中配置监听服务
在主服务器和备服务器上的listener.ora文件中分别添加以下内容:
主服务器listener.ora文件配置
SID_LIST_LISTENER =
(SID_LIST = (SID_DESC =
(GLOBAL_DBNAME = orcl) (SID_NAME = orcl)
(ORACLE_HOME = /u01/app/oracle/product/12.1.0/dbhome_1) )
(SID_DESC = (GLOBAL_DBNAME = dr1_dgmgrl)
(SID_NAME = dr1) (ORACLE_HOME = /u01/app/oracle/product/12.1.0/dbhome_1)
) (SID_DESC =
(GLOBAL_DBNAME = dr2_dgmgrl) (SID_NAME = dr2)
(ORACLE_HOME = /u01/app/oracle/product/12.1.0/dbhome_1) )
)
ADR_BASE_LISTENER = /u01/app/oracle
备服务器listener.ora文件配置
SID_LIST_LISTENER =
(SID_LIST = (SID_DESC =
(GLOBAL_DBNAME = orcl) (SID_NAME = orcl)
(ORACLE_HOME = /u01/app/oracle/product/12.1.0/dbhome_1) )
(SID_DESC = (GLOBAL_DBNAME = dr1_dgmgrl)
(SID_NAME = dr1) (ORACLE_HOME = /u01/app/oracle/product/12.1.0/dbhome_1)
) (SID_DESC =
(GLOBAL_DBNAME = dr2_dgmgrl) (SID_NAME = dr2)
(ORACLE_HOME = /u01/app/oracle/product/12.1.0/dbhome_1) )
)
ADR_BASE_LISTENER = /u01/app/oracle
3. 配置DG Broker
在主节点上配置DG Broker:
[oracle@localhost ~]$ dgmgrl /
DGMGRL> connect sys/Password@orclDGMGRL> create configuration 'orcl_dgmgrl' as primary database is 'orcl' connect identifier is 'orcl';
DGMGRL>