Oracle Dataguard的原理與基本配置,oracledataguard
最近集團在做災備方案,用於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
創建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狀態
使用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,做報表查詢分擔主庫壓力和實現讀寫分離做准備。