当前环境配置:
主库:rac 备库:racdg
1.Data Guard 主库配置
1)检查修改主库的force logging 模式
sqlplus / as sysdba
SQL>select FORCE_LOGGING from v$database;
alter database force logging;
--主库remote_login_passwordfile 为EXCLUSIVE
show parameter remote_login_passwordfile
2)在主库当前tnsnames.ora文件基础上添加以下连接串(两节点)
RACDG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.xxx.xxx)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.xxx.xxx)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = racdg)
)
)
3)配置主库初始化参数文件
create pfile='/tmp/oracle/initrac.ora' from spfile;
alter system set log_archive_config='dg_config=(rac,racdg)' scope=both sid='*';
---等备库实例启动再enable
alter system set log_archive_dest_state_2='defer' scope=both sid='*';
alter system set log_archive_dest_2=
'service=racdg LGWR ASYNC NOAFFIRM delay=0 optional
compression=disable max_failure=0 max_connections=1 reopen=300
net_timeout=30 valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE)
db_unique_name=racdg' scope=both sid='*';
alter system set fal_client='rac' scope=both sid='*';
alter system set fal_server='racdg' scope=both sid='*';
alter system set standby_file_management=AUTO scope=both sid='*';
4)备份主库
backup as compressed backupset database format '/tmp/bak/racdb%U';
5)生成standby controlfile 文件并拷贝至容灾环境中的+DATA中
alter database create standby controlfile as '/tmp/oracle/controlstd.ctl';
scp /tmp/oracle/controlstd.ctl racdg:/tmp/
$ asmcmd
创建目录 +DATA/RACDG/CONTROLFILE、+ARCH/RACDG/CONTROLFILE
ASMCMD> cp /tmp/controlstd.ctl +DATA/RACDG/CONTROLFILE/control01.ctl
ASMCMD> cp /tmp/controlstd.ctl +ARCH/RACDG/CONTROLFILE/control02.ctl
2. Data Guard 备库配置
1)准备参数文件
----在主库创建备库的pfile
create pfile='/tmp/oracle/initrac01.ora' from spfile;
scp /tmp/oracle/initrac01.ora 192.168.232.136:/tmp/
---修改节点pfile:注意修改以下项:
[oracle@racdg1 tmp]$ cat initrac01.ora
racdg1.__db_cache_size=201326592
racdg2.__db_cache_size=239075328
racdg1.__java_pool_size=4194304
racdg2.__java_pool_size=4194304
racdg2.__large_pool_size=8388608
racdg1.__large_pool_size=8388608
racdg1.__pga_aggregate_target=356515840
racdg2.__pga_aggregate_target=322961408
racdg1.__sga_target=423624704
racdg2.__sga_target=457179136
racdg1.__shared_io_pool_size=0
racdg2.__shared_io_pool_size=0
racdg1.__shared_pool_size=201326592
racdg2.__shared_pool_size=197132288
racdg1.__streams_pool_size=0
racdg2.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/racdg/adump'
*.audit_trail='db'
*.cluster_database=true
*.compatible='11.2.0.4.0'
*.control_files='+DATA/RACDG/CONTROLFILE/control01.ctl','+ARCH/RACDG/CONTROLFILE/control02.ctl'
*.db_block_size=8192
*.db_create_file_dest='+ARCH'
*.db_domain=''
*.db_name='rac'
*. db_unique_name='racdg'
*.db_recovery_file_dest='+ARCH'
*.db_recovery_file_dest_size=4621074432
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=racdgXDB)'
*.fal_client='racdg'
*.fal_server='rac'
racdg1.instance_number=1
racdg2.instance_number=2
*.log_archive_config='dg_config=(racdg,rac)'
*.log_archive_dest_2='service=racdg LGWR ASYNC NOAFFIRM delay=0 optional
compression=disable max_failure=0 max_connections=1 reopen=300
net_timeout=30 valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE)
db_unique_name=rac'
*.log_archive_dest_state_2='defer'
*.log_archive_format='%t_%s_%r.dbf'
*.memory_target=780140544
*.open_cursors=300
*.processes=300
*.remote_listener='racdg-scan:1521'
*.remote_login_passwordfile='exclusive'
*.standby_file_management='AUTO'
racdg2.thread=2
racdg1.thread=1
racdg1.undo_tablespace='UNDOTBS1'
racdg2.undo_tablespace='UNDOTBS2'
创建审计目录(两个节点):
mkdir -p /u01/app/oracle/admin/racdg/adump
正常启动之后,创建spfile:
create spfile='+DATA' from pfile='/tmp/initrac01.ora';
在两节点的$ORACLE_HOME/dbs上创建initracdgn.ora
cat initracdg2.ora
spfile='+data/rac/parameterfile/spfile.256.978738877'
关闭实例
shutdown immediate
使用spfile启动到 ADG模式
startup mount
2)准备密码文件
scp orapwrac1 192.168.232.135:/u01/app/oracle/product/11.2.0.4/dbs/orapwracdg1
scp orapwrac1 192.168.232.136:/u01/app/oracle/product/11.2.0.4/dbs/orapwracdg2
3)部署tnsname.ora(两节点)
RAC =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.xxx.xxx)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.xxx.xxx)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = rac)
)
)
RACDG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.232.145)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.232.146)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = racdg)
)
)
4)容灾数据库恢复
export ORACLE_SID=racdg
rman target / << EOF
run{
allocate channel ch01 type disk;
set newname for datafile 1 to '+DATA/RACDG/DATAFILE/system.256.978389699' ;
set newname for datafile 2 to '+DATA/RACDG/DATAFILE/sysaux.257.978389701' ;
set newname for datafile 3 to '+DATA/RACDG/DATAFILE/undotbs1.258.978389703';
set newname for datafile 4 to '+DATA/RACDG/DATAFILE/users.259.978389703' ;
set newname for datafile 5 to '+DATA/RACDG/DATAFILE/undotbs2.264.978389835';
set newname for datafile 1 to '+DATA/RACDG/TEMPFILE/temp.263.978389793';
restore database;
switch datafile all;
switch tempfile all;
release channel ch01;
}
5)恢复完成后,在备库先添加standby redo,然后再在主库添加
alter database ADD standby logfile thread 1 group 11 ('+DATA',‘+ARCH') size 50M ;
alter database ADD standby logfile thread 1 group 12 ('+DATA',‘+ARCH') size 50M ;
alter database ADD standby logfile thread 1 group 13 ('+DATA',‘+ARCH') size 50M ;
alter database ADD standby logfile thread 2 group 14 ('+DATA',‘+ARCH') size 50M ;
alter database ADD standby logfile thread 2 group 15 ('+DATA',‘+ARCH') size 50M ;
alter database ADD standby logfile thread 2 group 16 ('+DATA',‘+ARCH') size 50M ;
6)启动数据同步
alter database recover managed standby database using current logfile disconnect from session nodelay;
7)启动11G Data Guard 新特性Active Data Guard
alter database recover managed standby database cancel;
alter database open read only;
alter database recover managed standby database using current logfile disconnect from session nolay;
3、查看同步情况
--备库
col scn for 9999999999999999999
select current_scn from v$database;
--主库
select current_scn as scn from dual;
select group#,thread#, SEQUENCE#,ARCHIVED from v$log;
select PROCESS,THREAD#,SEQUENCE# from v$managed_standby;
4、注册数据库到CRS
srvctl add database -d racdg -n rac -o $ORACLE_HOME -p +DATA/rac/parameterfile/spfile.256.978738877
srvctl add instance -d racdg -i racdg1 -n racdg1
srvctl add instance -d racdg -i racdg2 -n racdg2
srvctl start instance -d racdg -i racdg1
srvctl start instance -d racdg -i racdg2