一、主库打开归档模式以及修改primary处于force logging模式
mount状态下
alter database force logging alter database archivelog;
二、主备监听配置如下:
主:listener.ora SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = primary) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1) (SID_NAME = primary) ) ) LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = primary)(PORT = 1521)) ) ) 备:listener.ora SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = standby) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1) (SID_NAME = standby) ) ) LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = standby)(PORT = 1521)) ) ) 主、备:tnsnames.ora PRIMARY = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = primary)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = primary) ) ) STANDBY = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = standby)(PORT = 1522)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = standby) ) ) ~
三、配置主库
alter system set db_name='primary' scope=spfile; -- 主备db_name必须一致 alter system set db_unique_name='primary' scope=spfile; alter system set log_archive_config='DG_CONFIG=(primary,standby)' scope=spfile; alter system set log_archive_dest_1='LOCATION=/u01/app/oracle/fast_recovery_area valid_for=(all_logfiles,all_roles) db_unique_name=primary' scope=spfile; alter system set log_archive_dest_2='SERVICE=standby lgwr sync valid_for=(online_logfiles,primary_role) db_unique_name=standby' scope=spfile; --注意每一个=前后均不能有空格,否则报错 alter system set LOG_ARCHIVE_DEST_STATE_1=ENABLE; alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE; alter system set standby_file_management=AUTO scope=spfile; alter system set log_archive_format='%t_%s_%r.arc' scope=spfile; alter system set fal_server=primary scope=spfile; --必须配置,否则导致日志应用不正常 alter system set fal_client=standby scope=spfile;
四、更新spfile信息,并创建pfile文件以及传输相关文件到备库
shutdown abort; startup; create pfile='/tmp/initstandby.ora' from spfile; alter database create standby controlfile as '/tmp/controlfile.ctl'; --不创建 scp -r $ORACLE_BASE/admin/ $ORACLE_BASE/diag/ $ORACLE_BASE/oradata/ $ORACLE_BASE/fast_recovery_area/ standby:/$ORACLE_BASE
五、备库配置
利用主库传过来的pfile启动到nomount状态,并配置如下:
create spfile from pfile='$ORACLE_HOME/dbs/initstandby.ora' startup nomount; alter system set db_name=primary scope=spfile; alter system set db_unique_name=standby scope=spfile; alter system set log_archive_config='DG_CONFIG=(primary,standby)' scope=spfile; alter system set log_archive_dest_1='LOCATION=/u01/app/oracle/fast_recovery_area valid_for=(all_logfiles,all_roles) db_unique_name=standby' scope=spfile; alter system set log_archive_dest_2='SERVICE=primary lgwr sync valid_for=(online_logfiles,primary_role) db_unique_name=primary' scope=spfile; alter system set standby_file_management=AUTO scope=spfile; alter system set log_archive_format='%t_%s_%r.arc' scope=spfile; alter system set fal_server=standby scope=spfile; alter system set fal_client=primary scope=spfile; shutdown abort; startup nomount; create pfile from spfile;
六、主库创建密码文件--$ORACLE_HOME/dbs
orapwd file=orapw$ORACLE_SID password=redhat entries=5 --主库 orapwd file=orapw$ORACLE_SID password=redhat entries=5 --备库
七、在primary端通过Rman Duplicate创建备库,同步信息
$rman target sys/redhat@primary auxiliary sys/redhat@standby nocatalog Recovery Manager: Release 11.2.0.3.0 - Production on Sun Feb 21 16:36:41 2016 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. connected to target database: PRIMARY (DBID=1741821069) using target database control file instead of recovery catalog connected to auxiliary database: PRIMARY (not mounted)
复制主库信息到备库:
RMAN>duplicate target database for standby from active database nofilenamecheck;
八、创建4组standby log(primary/standby都必须创建,否则导致日志传输不正常)
alter database add standby logfile group 4 '/u01/app/oracle/oradata/primary/redo04.log' size 50m ; alter database add standby logfile group 5 '/u01/app/oracle/oradata/primary/redo05.log' size 50m ; alter database add standby logfile group 6 '/u01/app/oracle/oradata/primary/redo06.log' size 50m; alter database add standby logfile group 7 '/u01/app/oracle/oradata/primary/redo07.log' size 50m;
九、查看standby log状态
select process,client_process,sequence#,status from v$managed_standby; select group#,thread#,sequence#,archived,status from v$standby_log;
十、打开standby实时应用日志
recover managed standby database using current logfile disconnect from session; 查看standby启动的DG进程 select process,client_process,sequence#,status from v$managed_standby; 查看主备中保护模式 select database_role,protection_mode,protection_level,open_mode from v$database; 主: SQL> select database_role,protection_mode,protection_level,open_mode from v$database; DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL OPEN_MODE ---------------- -------------------- -------------------- -------------------- PRIMARY MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE READ WRITE 备: SQL> select database_role,protection_mode,protection_level,open_mode from v$database; DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL OPEN_MODE ---------------- -------------------- -------------------- -------------------- PHYSICAL STANDBY MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE MOUNTED
至此,DG已经配置完毕,以上步骤同样适合于oracle 10g以下版本,以下步骤是11g以后才具备的
十一、Open Read Only standby数据库并且开启实时日志应用(注意细节)
备:
SQL> shutdown immediate ORA-01109: database not open Database dismounted. ORACLE instance shut down. SQL> startup ORACLE instance started. Total System Global Area 463478784 bytes Fixed Size 2229384 bytes Variable Size 146803576 bytes Database Buffers 310378496 bytes Redo Buffers 4067328 bytes Database mounted. Database opened. SQL> select * from v$dataguard_status; FACILITY SEVERITY DEST_ID MESSAGE_NUM ERROR_CODE CAL TIMESTAMP ------------------------ ------------- ---------- ----------- ---------- --- --------- MESSAGE -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Log Transport Services Informational0 1 0 NO 21-FEB-16 ARC0: Archival started Log Transport Services Informational0 2 0 NO 21-FEB-16 ARC1: Archival started 查看备节点此时状态: SQL> select database_role,protection_mode,protection_level,open_mode from v$database; DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL OPEN_MODE ---------------- -------------------- -------------------- -------------------- PHYSICAL STANDBY MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE READ ONLY SQL> select process,client_process,sequence#,status from v$managed_standby; PROCESS CLIENT_P SEQUENCE# STATUS --------- -------- ---------- ------------ ARCH ARCH 0 CONNECTED ARCH ARCH 0 CONNECTED ARCH ARCH 0 CONNECTED ARCH ARCH 0 CONNECTED
十二、应用日志:并查看进程
SQL> recover managed standby database using current logfile disconnect from session;--这步必须操作,才能发现数据是实时同步的,只有操作此步骤,备库才能看到APPLYING_LOG SQL> select process,client_process,sequence#,status from v$managed_standby; PROCESS CLIENT_P SEQUENCE# STATUS --------- -------- ---------- ------------ ARCH ARCH 0 CONNECTED ARCH ARCH 0 CONNECTED ARCH ARCH 0 CONNECTED ARCH ARCH 0 CONNECTED MRP0 N/A 17 APPLYING_LOG
SQL> recover managed standby database using current logfile disconnect from session;--这步必须操作,才能发现数据是实时同步的,只有操作此步骤,备库才能看到APPLYING_LOG
十三、查看主备模式状态
备:SQL> select database_role,protection_mode,protection_level,open_mode from v$database; DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL OPEN_MODE ---------------- -------------------- -------------------- ---------- PHYSICAL STANDBY MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE READ ONLY
至此ADG全部配置完毕。
十四、ADG功能测试(省略)
在主库上利用scott 账户建立表,看备库是否能立刻看到相关数据。
下一篇,继续研究ADG switchover and failover 切换以及三种模式的切换