一、安装前的准备:
1、有一套或者一台主库ORACLE,我这里是有一套RAC,版本11GR2
2、操作系统REDHAT6.5
二、使用duplicate进行DG搭建
1、安装单实例数据库
2、从主库拷贝init.ora文件到备库,修改相关路径,创建相关文件夹
主要有:
orcldg3.__db_cache_size=1073741824
orcldg3.__java_pool_size=201326592
orcldg3.__large_pool_size=167772160
orcldg3.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
orcldg3.__pga_aggregate_target=1073741824
orcldg3.__sga_target=3221225472
orcldg3.__shared_io_pool_size=0
orcldg3.__shared_pool_size=1073741824
orcldg3.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/diag/rdbms/orcl/orcl/adump'
*.audit_trail='NONE'
*.compatible='11.2.0.4.0'
*.control_files='/oradata/orcl/control01.ctl','/oradata/orcl/control02.ctl'
*.db_block_size=8192
*.db_create_file_dest='/oradata/orcl'
*.db_domain=''
*.db_file_name_convert='+ORCL_DATA/orcldg/datafile','/oradata/orcl','+ORCL_DATA/orcldg/tempfile','/oradata/orcl'
*.db_name='orcl'
*.db_unique_name='orcldg3'
*.diagnostic_dest='/u01/app/oracle'
*.fal_client='orcldg3'
*.fal_server='orcl'
*.log_archive_config='DG_CONFIG=(orcldg,orcldg3)'
*.log_archive_dest_1='location=/oradata/archivelog/orcl VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcldg3'
*.log_archive_dest_2='SERVICE=orcl lgwr ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl OPTIONAL REOPEN=15 MAX_FAILURE=10 NET_TIMEOUT=30'
*.log_archive_format='%t_%s_%r.arc'
*.log_file_name_convert='+ORCL_DATA/orcldg/onlinelog','/oradata/orcl'
*.nls_length_semantics='CHAR'
*.open_cursors=2000
*.optimizer_dynamic_sampling=1
*.optimizer_index_cost_adj=1
*.pga_aggregate_target=1073741824
*.processes=1500
*.query_rewrite_enabled='FALSE'
*.remote_login_passwordfile='exclusive'
*.service_names='orcl,orcldg3'
*.session_cached_cursors=40
*.sessions=1655
*.sga_target=3221225472
*.standby_file_management='auto'
*.undo_retention=1800
*.undo_tablespace='UNDOTBS1'
三、配置监听
listener.ora添加
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER=ON
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME =orcl)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
(GLOBAL_DBNAME=orcl)
)
)
tnsnames.ora添加
ORCLDG3 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.101)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
四、从主库拷贝密码文件到备库
启动备库数据库到nomount状态
startup nomount pfile='/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initorcl.ora';
然后create spfile from pfile='/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initorcl.ora';
shut immediate
startup nomount
五、在主库使用网络连接测试是否连接备库
su - oracle
sqlplu sys/passwd@orcldg3
六、在主库其中一个节点执行duplicate脚本
#!/bin/bash
LOG=duplicate_`date +%Y%m%d`.log
export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_BASE=/oracle/app
export ORACLE_HOME=/oracle/app/product/11.2.0/dbhome_1
export ORACLE_TERM=xterm
export PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/usr/x11R6/lib64
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
export ORACLE_SID=orcl2
/oracle/app/product/11.2.0/dbhome_1/bin/rman target sys/passwd@orcl2 auxiliary sys/passwd@orcldg3 log=/home/oracle/orcldg3.log append <
duplicate target database for standby from active database dorecover;
}
exit;
EOF
七、完成duplicate后,进行数据实时同步配置
这里注意,主库和备库配置保持一致
主库:
SQL> show parameter log_archive_config
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_config string DG_CONFIG=(orcldg,orcl)
SQL> alter system set log_archive_config='DG_CONFIG=(orcldg,orcldg3)';
alter system set log_archive_dest_state_3=enable;
alter system set LOG_ARCHIVE_DEST_3='service=orcldg3 LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcldg3';
select inst_id,dest_name,status,error from gv$archive_dest_status where dest_name='LOG_ARCHIVE_DEST_3';
alter system set log_archive_dest_state_3=enable;
这里注意主库RAC的两个节点都要配置TNSNAMES.ORA
ORCLDG3 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.101)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
备库:(实际一般在参数文件里设置好和主库一样这里就不用改了)
SQL> show parameter log_archive_config
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_config string DG_CONFIG=(orcldg,orcl)
SQL> alter system set log_archive_config='DG_CONFIG=(orcldg,orcldg3)';
八、备库开启同步
在备库上操作,开启DG同步
alter database recover managed standby database using current logfile disconnect from session;
查看是否同步
select thread#,process,client_process,sequence#,status from v$managed_standby;
九、相关报错的一些应对方式
1、
[oracle@erpdb2 ~]$ sqlplus sys/@tcbjeasdg4 as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Thu Oct 25 15:23:54 2018
Copyright (c) 1982, 2013, Oracle. All rights reserved.
ERROR:
ORA-12528: TNS:listener: all appropriate instances are blocking new connections
SQL> show parameter log_archive_config
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_config string DG_CONFIG=(orcldg,orcl)
SQL> alter system set log_archive_config='DG_CONFIG=(orcldg,orcldg3)';
出现这个报错,要注意修改这个参数log_archive_config
主库和备库都要修改
2、
SQL> select inst_id,dest_name,status,error from gv$archive_dest_status where dest_name='LOG_ARCHIVE_DEST_3';
INST_ID
----------
DEST_NAME
--------------------------------------------------------------------------------
STATUS ERROR
--------- -----------------------------------------------------------------
1
LOG_ARCHIVE_DEST_3
ERROR ORA-12154: TNS:could not resolve the connect identifier specified
2
LOG_ARCHIVE_DEST_3
VALID
INST_ID
----------
DEST_NAME
--------------------------------------------------------------------------------
STATUS ERROR
--------- -----------------------------------------------------------------
alter system set log_archive_dest_state_3=enable;
出现这个报错,要注意配置tnsnames.ora,与DG相连
3、
[oracle@erpdb2 admin]$ tnsping tcbjeasdg3
TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 25-OCT-2018 16:29:19
Copyright (c) 1997, 2013, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.101)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = tcbjeas))
TNS-12533: TNS:illegal ADDRESS parameters
遇到这个报错,一定要注意tnsnames.ora文件里面的配置,一定是多了空行,空格,或者少了括号之类的。
4、
[oracle@erpdb2 opt]$ sqlplus sys/@tcbjeasdg3 as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Thu Oct 25 16:40:01 2018
Copyright (c) 1982, 2013, Oracle. All rights reserved.
ERROR:
ORA-12528: TNS:listener: all appropriate instances are blocking new connections
遇到这个报错,要在备库配置好listener.ora和tnsnames.ora,如下:
listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.101)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER=ON
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME =orcl)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
(GLOBAL_DBNAME=orcldg3)
)
(SID_DESC =
(SID_NAME =tcbjeas)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
(GLOBAL_DBNAME=tcbjeas)
)
)
tnsnames.ora
tcbjeasdg3 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = erpdg)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = tcbjeas)
)
)
5、[oracle@erpdb2 opt]$ sqlplus sys/@tcbjeasdg3 as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Thu Oct 25 16:50:47 2018
Copyright (c) 1982, 2013, Oracle. All rights reserved.
ERROR:
ORA-01017: invalid username/password; logon denied
Enter user-name:
遇到这个报错,从主库复制密码文件到备库,并且这个密码文件要改名和备库ORACL_SID一样的名字
startup nomount pfile='/u01/app/oracle/product/11.2.0/dbhome_1/dbs/inittcbjeasdg3.ora';
startup nomount pfile='/u01/app/oracle/product/11.2.0/dbhome_1/dbs/inittcbjeas.ora';
6、
contents of Memory Script:
{
sql clone 'alter database mount standby database';
}
executing Memory Script
sql statement: alter database mount standby database
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 10/30/2018 14:15:43
RMAN-05501: aborting duplication of target database
RMAN-05001: auxiliary file name +CRM_DATA/crmproddg/datafile/siebeldata07.dbf conflicts with a file used by the target database
RMAN-05001: auxiliary file name +CRM_DATA/crmproddg/datafile/siebeldata06.dbf conflicts with a file used by the target database
RMAN-05001: auxiliary file name +CRM_DATA/crmproddg/datafile/siebelindex04.dbf conflicts with a file used by the target database
RMAN-05001: auxiliary file name +CRM_DATA/crmproddg/datafile/siebelindex03.dbf conflicts with a file used by the target database
RMAN-05001: auxiliary file name +CRM_DATA/crmproddg/datafile/siebelindex02.dbf conflicts with a file used by the target database
RMAN-05001: auxiliary file name +CRM_DATA/crmproddg/datafile/siebelindex01.dbf conflicts with a file used by the target database
RMAN-05001: auxiliary file name +CRM_DATA/crmproddg/datafile/siebeldata05.dbf conflicts with a file used by the target database
RMAN-05001: auxiliary file name +CRM_DATA/crmproddg/datafile/siebeldata04.dbf conflicts with a file used by the target database
RMAN-05001: auxiliary file name +CRM_DATA/crmproddg/datafile/siebeldata03.dbf conflicts with a file used by the target database
RMAN-05001: auxiliary file name +CRM_DATA/crmproddg/datafile/siebeldata02.dbf conflicts with a file used by the target database
RMAN-05001: auxiliary file name +CRM_DATA/crmproddg/datafile/siebeldata01.dbf conflicts with a file used by the target database
RMAN-05001: auxiliary file name +CRM_DATA/crmproddg/datafile/undotbs2.263.989833943 conflicts with a file used by the target database
RMAN-05001: auxiliary file name +CRM_DATA/crmproddg/datafile/users.264.989833943 conflicts with a file used by the target database
RMAN-05001: auxiliary file name +CRM_DATA/crmproddg/datafile/undotbs1.262.989833943 conflicts with a file used by the target database
RMAN-05001: auxiliary file name +CRM_DATA/crmproddg/datafile/sysaux.274.989835355 conflicts with a file used by the target database
RMAN-05001: auxiliary file name +CRM_DATA/crmproddg/datafile/system.269.989834569 conflicts with a file used by the target database
RMAN>
Recovery Manager complete.
检查备库的init.ora参数文件
crmproddg3.__db_cache_size=2147483648
crmproddg3.__java_pool_size=201326592
crmproddg3.__large_pool_size=167772160
crmproddg3.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
crmproddg3.__pga_aggregate_target=2147483648
crmproddg3.__sga_target=5368709120
crmproddg3.__shared_io_pool_size=0
crmproddg3.__shared_pool_size=1073741824
crmproddg3.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/diag/rdbms/crmprod/crmprod/adump'
*.audit_trail='NONE'
*.compatible='11.2.0.4.0'
*.control_files='/oradata/crmprod/control01.ctl','/oradata/crmprod/control02.ctl'
*.db_block_size=8192
*.db_create_file_dest='/oradata/crmprod'
*.db_domain=''
*.db_file_name_convert='+CRM_DATA/crmproddg/datafile','/oradata/crmprod','+CRM_DATA/crmproddg/tempfile','/oradata/crmprod'
*.db_name='crmprod'
*.db_unique_name='crmproddg3'
*.diagnostic_dest='/u01/app/oracle'
*.fal_client='crmproddg3'
*.fal_server='crmprod'
*.log_archive_config='DG_CONFIG=(crmproddg,crmproddg3)'
*.log_archive_dest_1='location=/oradata/archivelog/crmprod VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=crmproddg3'
*.log_archive_dest_2='SERVICE=crmprod lgwr ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=crmprod OPTIONAL REOPEN=15 MAX_FAILURE=10 NET_TIMEOUT=30'
*.log_archive_format='%t_%s_%r.arc'
*.log_file_name_convert='+CRM_DATA/crmproddg/onlinelog','/oradata/crmprod'
*.nls_length_semantics='CHAR'
*.open_cursors=2000
*.optimizer_dynamic_sampling=1
*.optimizer_index_cost_adj=1
*.pga_aggregate_target=2147483648
*.processes=1500
*.query_rewrite_enabled='FALSE'
*.remote_login_passwordfile='exclusive'
*.service_names='crmproddg,crmproddg3'
*.session_cached_cursors=40
*.sessions=1655
*.sga_target=5368709120
*.standby_file_management='auto'
*.undo_retention=1800
*.undo_tablespace='UNDOTBS1'
7、
SQL> select inst_id,dest_name,status,error from gv$archive_dest_status where dest_name='LOG_ARCHIVE_DEST_3';
INST_ID
----------
DEST_NAME
--------------------------------------------------------------------------------
STATUS ERROR
--------- -----------------------------------------------------------------
1
LOG_ARCHIVE_DEST_3
ERROR ORA-03135: connection lost contact
2
LOG_ARCHIVE_DEST_3
ERROR ORA-03135: connection lost contact
INST_ID
----------
DEST_NAME
--------------------------------------------------------------------------------
STATUS ERROR
--------- -----------------------------------------------------------------
这种报错,就好看主备库的配置是否一致,配置成一致的就可以了
show parameter log_archive_config
8、DG备库因为重启单个2节点,导致无法同步(这是一个BUG)
SQL> select inst_id,dest_name,status,error from gv$archive_dest_status where dest_name='LOG_ARCHIVE_DEST_3';
INST_ID
----------
DEST_NAME
--------------------------------------------------------------------------------
STATUS ERROR
--------- -----------------------------------------------------------------
1
LOG_ARCHIVE_DEST_3
VALID
2
LOG_ARCHIVE_DEST_3
ERROR ORA-01033: ORACLE initialization or shutdown in progress
这个时候,1节点是正常的,将1节点的密码文件复制到2节点并覆盖,然后再执行以下下面语句恢复正常
alter system set log_archive_dest_state_3=enable;