1.创建一个物理Standby数据库
2.Standby数据库取消managed recovery
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
3.主库配置
1)主库修改LOG_ARCHIVE_DEST_2参数
ALTER SYSTEM SET log_archive_dest_2 = ‘SERVICE=PRODDG VALID_FOR=(ONLINE_LOGFILES,STANDBY_ROLE) DB_UNIQUE_NAME=PRODDG‘ SCOPE=SPFILE;
2)主库建立Logminer数据字典
EXECUTE DBMS_LOGSTDBY.BUILD;
4.备库设置
1)切换到逻辑备库
ALTER DATABASE RECOVER TO LOGICAL STANDBY PRODDG;
2)重启实例,并且reset log
SHUTDOWN IMMEDIATE STARTUP mount ALTER DATABASE OPEN RESETLOGS;
3)standby开启sql apply
ALTER DATABASE START LOGICAL STANDBY APPLY;
5.验证
1)主库创建一个用户
SQL> alter system switch logfile; System altered. SQL> create user hxy identified by hxy; User created. SQL> grant dba to hxy; Grant succeeded. SQL> alter system switch logfile; System altered. SQL> conn hxy/hxy Connected. SQL> select * from tab; no rows selected SQL> create table t1 as select * from dba_users; Table created. SQL> alter system switch logfile; System altered. SQL> select count(*) from t1; COUNT(*) ---------- 23
2)备库查看alert日志
Sun Apr 27 23:25:11 2014 LOGMINER: Begin mining logfile for session 1 thread 1 sequence 123, /dsg/oracle11/PRODDG/arch/log1_123_839354331.arc LOGMINER: End mining logfile for session 1 thread 1 sequence 123, /dsg/oracle11/PRODDG/arch/log1_123_839354331.arc Sun Apr 27 23:25:12 2014 RFS[2]: Opened log for thread 1 sequence 124 dbid 251192667 branch 839354331 Sun Apr 27 23:26:19 2014 RFS LogMiner: Registered logfile [/dsg/oracle11/PRODDG/arch/log1_124_839354331.arc] to LogMiner session id [1] Sun Apr 27 23:26:19 2014 LOGMINER: Begin mining logfile for session 1 thread 1 sequence 124, /dsg/oracle11/PRODDG/arch/log1_124_839354331.arc LOGMINER: End mining logfile for session 1 thread 1 sequence 124, /dsg/oracle11/PRODDG/arch/log1_124_839354331.arc RFS[2]: Opened log for thread 1 sequence 125 dbid 251192667 branch 839354331
数据库中验证
SQL> conn hxy/hxy Connected. SQL> select * from tab; TNAME TABTYPE CLUSTERID ------------------------------ ------- ---------- T1 TABLE SQL> select count(*) from t1; COUNT(*) ---------- 23
可见,主库备库数据一致!
6.总结
配置Logical DataGuard最主要的还是配置好Physical DataGuard,并且主备库最好使用spfile启动数据库,方便切换成Logical Standby的时候修改参数
如果数据库是RAC,配置请参考官方文档Data Guard Concepts and Administration 11g Release 2 (11.2)之 Creating a Logical Standby Database