环境:
主库A机:在线生产环境,RHEL 6.4 + Oracle 11.2.0.3
备库B机:新增备机,RHEL 6.4
需求:
对生产环境最小影响前提下配置DG备库。
目录:
一、B机安装相同版本Oracle软件
二、A机,B机配置网络连接
三、配置主库A机,需要重启A机数据库
四、duplicate主库到备机
五、日常运维
一、B机安装相同版本Oracle软件
只需要安装相同版本的Oracle软件,配置环境变量,不需要建库。
参考:《[Linux平台oracle 11g单实例 安装部署配置 快速参考](http://www.cnblogs.com/jyzhao/p/3891769.html)》 部分内容。
二、A机,B机配置网络连接
2.1 配置listener.ora
### 2.1.1 A机配置listener.ora ###
新增下面静态注册内容,然后`lsnrctl reload`重载监听,这样重载不会影响到现有业务:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = jingyu)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
(SID_NAME = jingyu)
)
(SID_DESC =
(GLOBAL_DBNAME = jingyu_dgmgrl)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
(SID_NAME = jingyu)
)
)
2.1.2 B机配置listener.ora
加入下面静态注册内容:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = jingyu_s)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
(SID_NAME = jingyu_s)
)
(SID_DESC =
(GLOBAL_DBNAME = jingyu_s_dgmgrl)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
(SID_NAME = jingyu_s)
)
)
2.2 配置tnsnames.ora
A机、B机都配置tnsnames.ora,添加以下内容:
jingyu =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.99.180)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = jingyu)
)
)
jingyu_s =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.99.183)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = jingyu_s)
)
)
2.3 生成密码文件
A机生成密码文件:
orapwd file=$ORACLE_HOME/dbs/orapwjingyu password=oracle entries=10 ignorecase=Y
B机生成密码文件:
orapwd file=$ORACLE_HOME/dbs/orapwjingyu_s password=oracle entries=10 ignorecase=Y
测试在A机连接到B机正常联通:
首先确定已经关闭防火墙和SELinux。
sqlplus sys/oracle@jingyu_s as sysdba
三、配置主库A机,需要重启A机数据库
添加standby logfile, 如果原来有三组联机日志,那么添加4组standby日志。
A机确定以下目录存在且赋予正确权限:
归档日志文件存放目录:/u01/app/oracle/arch
--设置数据库为force logging
alter database force logging;
--设置db_unique_name, log_archive_config(这里主库的db_unique_name,出于对现有的生产环境最小影响考虑没有改)
alter system set db_unique_name='jingyu' scope=spfile;
alter system set log_archive_config='DG_CONFIG=(jingyu,jingyu_s)';
--归档日志目录
alter system set log_archive_dest_1='LOCATION=/u01/app/oracle/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=jingyu';
alter system set log_archive_dest_2='SERVICE=jingyu_s ASYNC LGWR VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=jingyu_s';
--归档日志文件命名规则
alter system set log_archive_format='arch_%r_%t_%s.arc' scope=spfile;
--DG的fal_server和fal_client
alter system set fal_server=jingyu_s;
alter system set fal_client=jingyu;
--设置standby_file_management为自动
alter system set standby_file_management=AUTO;
--设置备库日志文件组,数量一般为目标库日志文件组+1
alter database add standby logfile group 11 size 52428800;
alter database add standby logfile group 12 size 52428800;
alter database add standby logfile group 13 size 52428800;
alter database add standby logfile group 14 size 52428800;
四、duplicate主库到备机
4.1 B机确定以下目录存在且赋予正确权限
归档日志文件存放目录:/u01/app/oracle/arch
审计文件目录:/u01/app/oracle/admin/jingyu_s/adump
数据文件目录:/usr2/oracle/oradata
4.2 B机数据库启动到nomount模式
参数文件initjingyu_s.ora
echo "db_name=jingyu_s" > /tmp/initjingyu_s.ora
启动到nomount状态
startup nomount pfile='/tmp/initjingyu_s.ora';
4.3 A机登录,复制数据库到B机
duplicate命令
rman target / auxiliary sys/oracle@jingyu_s cmdfile=duplicate_standby.sql
vi duplicate_standby.sql
duplicate target database
for standby
from active database
DORECOVER
spfile
set db_unique_name='jingyu_s'
set audit_file_dest='/u01/app/oracle/admin/jingyu_s/adump'
set db_create_file_dest='/usr2/oracle/oradata'
--set control_files='/usr2/oracle/oradata/jingyu_s/control01.ctl','/u01/app/oracle/fast_recovery_area/jingyu_s/control02.ctl'
set log_archive_dest_1='location=/u01/app/oracle/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=jingyu_s'
set log_archive_dest_2='SERVICE=jingyu ASYNC LGWR VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=jingyu'
set standby_file_management='AUTO'
set fal_server='jingyu'
set fal_client='jingyu_s'
set memory_target='0'
set sga_target='1024M';
五、日常运维
5.1 日常管理维护
参考:
5.2 备份策略
参考: