最近集团在做灾备方案,用于Oracle的高可用性,在不影响主库性能的前提下,我们选择使用DG的"最大性能"模式。
DG是Oracle数据库自带的数据同步功能,其基本原理是将日志文件从主库传输到备库,然后在备库上应用这些日志文件,从而使备库与主库保持同步。
DataGuard提供了三种日志传输(Redo Transport)方式,分别是ARCH传输、LGWR同步传输和LGWR异步传输。在上述三种日志传输方式的基础上,提供了三种数据保护模式,即最大性能(Maximum Performance Mode)、最大保护(Maximum Protection Mode)和最大可用(Maximum Availability Mode),其中最大保护模式和最大可用模式要求日志传输必须用LGWR同步传输方式,最大性能模式下可用任何一种日志传输方式。
现将Dataguard配置过程给大家做以分享
1.主库开启归档模式
2.alter database force logging;
3.添加standby logfile
alter database add standby logfile '/data/oracle/oradata/orcl/standby01.log' size 50M;
alter database add standby logfile '/data/oracle/oradata/orcl/standby02.log' size 50M;
alter database add standby logfile '/data/oracle/oradata/orcl/standby03.log' size 50M;
4.配置log_archive_config
alter system set log_archive_config='dg_config=(orcl,dgorcl)';
alter system set log_archive_dest_1='location=/data/arch valid_for=(all_logfiles,all_roles) db_unique_name=orcl';
alter system set log_archive_dest_2 ='service=dgorcl async valid_for=(online_logfile,primary_role) db_unique_name=dgorcl';
5.编辑主库tnsnames.ora文件,将standby实例加进去
DGORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dgorcl)
)
)
6.编辑主库listener.ora文件,将standby静态注册进去
# listener.ora Network Configuration File: /data/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /data/oracle
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = dgorcl)
(ORACLE_HOME = /data/oracle/product/11.2.0/db_1)
(SID_NAME = dgorcl)
)
)
7.重启监听
lsnrctl stop
lsnrctl start
8.创建standby库密码文件
cd $ORACLE_HOME/dbs
cp orapworcl orapwdgorcl
9.创建standby的初始化参数文件
cd $ORACLE_HOME/dbs
echo DB_NAME=dgorcl>initdgorcl.ora
10.创建standby库相应的目录
mkdir $ORACLE_BASE/admin/dgorcl
mkdir $ORACLE_BASE/admin/dgorcl/adump
mkdir $ORACLE_BASE/admin/dgorcl/dpdump
mkdir $ORACLE_BASE/admin/dgorcl/pfile
11.创建standby数据文件存放位置
mkdir $ORACLE_BASE/oradata/dgorcl
12.使用standby pfile启动至nomount状态
12.使用rman以auxiliary方式连接standby数据库
export ORACLE_SID=orcl
rman target / auxiliary sys@dgorcl
13.rman 创建standby数据库
run{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate auxiliary channel stby type disk;
duplicate target database for standby from active database
spfile
parameter_value_convert 'orcl','dgorcl'
set db_unique_name='dgorcl'
set db_file_name_convert='/orcl/','/dgorcl/'
set control_files='/data/oracle/oradata/dgorcl/dgorcl.ctl'
set log_archive_max_processes='5'
set fal_client='dgorcl'
set fal_server='orcl'
set standby_file_management='AUTO'
set log_archive_config='dg_config=(orcl,dgorcl)'
set log_archive_dest_2='service=orcl async valid_for=(online_logfile,primary_role) db_unique_name=orcl' ;
}
14.standby库日志恢复开启
alter database recover managed standby database disconnect from session;
到此已完成Phyical Dataguard的相关配置,并为之后调整DG到ADG,做logical dataguard,做报表查询分担主库压力和实现读写分离做准备。