Oracle 11g 建立Logical standby 测试环境搭建 For Windows

建立逻辑standby,首先需要一个已经配置好的物理standby,还需要满足一些条件才能进行转换,具体条件请查询官方文档,这里是测试环境并且是裸库所以可以直接进行转换。

http://docs.oracle.com/cd/E11882_01/server.112/e41134/create_ls.htm#SBYDB4730

测试环境:

操作系统平台:Windows7 旗舰版64位

Oracle版本:11.2.0.1.0 32bit

机器:Primary(sid:orcldb)、Standby(sid:orcldb)

DataGuard类型:Physical STANDBY


一、创建物理standby

详细步骤可以参考:Oracle 11g DataGuard 测试环境搭建 For windows


二、创建逻辑standby

这里是Oracle的一些指引

Table 4-2 Creating a Logical Standby Database

Reference Task Database

Section 4.2.1

Create a Physical Standby Database

Primary

Section 4.2.2

Stop Redo Apply on the Physical Standby Database

Standby

Section 4.2.3

Prepare the Primary Database to Support a Logical Standby Database

Primary

Section 4.2.4

Transition to a Logical Standby Database

Standby

Section 4.2.5

Open the Logical Standby Database

Standby

Section 4.2.6

Verify the Logical Standby Database Is Performing Properly

Standby


2.1 停止物理standby的应用归档

SQL> alter database recover managed standby database cancel;
 
Database altered


2.2 主库建立数据字典

SQL> EXECUTE DBMS_LOGSTDBY.BUILD;
 
PL/SQL procedure successfully completed


2.3 转化为logical standby

SQL>  ALTER DATABASE RECOVER TO LOGICAL STANDBY orcl;
 
ALTER DATABASE RECOVER TO LOGICAL STANDBY orcl
 
ORA-19953: 不应打开数据库

关闭实例后挂载,重新执行转化

SQL>  ALTER DATABASE RECOVER TO LOGICAL STANDBY orcl;
 

Database altered

关闭实例后挂载,查看数据库角色。

SQL> select DATABASE_ROLE from v$database;
 
DATABASE_ROLE
----------------
LOGICAL STANDBY


2.4 修改primary / logical standby参数

把primary standby的日志文件分开来存放。

SQL> alter system set  LOG_ARCHIVE_DEST_1='LOCATION=E:\app\admin\oradata\archive VALID_FOR=(ONLINE_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=primary';
 
System altered
 
SQL> alter system set  LOG_ARCHIVE_DEST_3='LOCATION=E:\app\admin\oradata\archive2 VALID_FOR=(STANDBY_LOGFILES,STANDBY_ROLES) DB_UNIQUE_NAME=primary';
 
System altered
 
SQL> alter system set LOG_ARCHIVE_DEST_STATE_3=ENABLE;
 
System altered


把logical standby的日志文件分开来存放。

SQL> alter system set log_archive_dest_1='LOCATION=e:\app\admin\oradata\archive VALID_FOR=(ONLINE_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=standby';
 
System altered
 
SQL> alter system set log_archive_dest_3='LOCATION=e:\app\admin\oradata\archive2 VALID_FOR=(STANDBY_LOGFILES,STANDBY_ROLE) DB_UNIQUE_NAME=standby';
 
System altered

SQL> alter system set LOG_ARCHIVE_DEST_STATE_3=ENABLE;
 
System altered


2.5 打开logical standby 数据库

SQL> alter database open resetlogs;
 
Database altered
 
SQL> select database_role from v$database;
 
DATABASE_ROLE
----------------
LOGICAL STANDBY
 
SQL> select max(sequence#) from v$log_history;
 
MAX(SEQUENCE#)
--------------


2.6 添加standby联机日志文件

SQL> SELECT GROUP#, BYTES FROM V$LOG
  2  ;
 
    GROUP#      BYTES
---------- ----------
         1   52428800
         2   52428800
         3   52428800
 
SQL> SELECT GROUP#, BYTES FROM V$STANDBY_LOG;
 
    GROUP#      BYTES
---------- ----------
         4   52428800
         5   52428800
         6   52428800

新增多一组standby redolog

SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 7 'E:\APP\ADMIN\ORADATA\ORCL\ONLINELOG\redo07.log' SIZE 50m;  
 
Database altered
 
SQL> select * from v$logfile;
 
    GROUP# STATUS  TYPE    MEMBER                                                                           IS_RECOVERY_DEST_FILE
---------- ------- ------- -------------------------------------------------------------------------------- ---------------------
         1         ONLINE  E:\APP\ADMIN\ORADATA\STANDBY\ONLINELOG\O1_MF_1_B9H6KDDC_.LOG                     NO
         1         ONLINE  E:\APP\ADMIN\FLASH_RECOVERY_AREA\STANDBY\ONLINELOG\O1_MF_1_B9H6KFQJ_.LOG         YES
         2         ONLINE  E:\APP\ADMIN\ORADATA\STANDBY\ONLINELOG\O1_MF_2_B9H6KH7T_.LOG                     NO
         2         ONLINE  E:\APP\ADMIN\FLASH_RECOVERY_AREA\STANDBY\ONLINELOG\O1_MF_2_B9H6KJK1_.LOG         YES
         3         ONLINE  E:\APP\ADMIN\ORADATA\STANDBY\ONLINELOG\O1_MF_3_B9H6KL48_.LOG                     NO
         3         ONLINE  E:\APP\ADMIN\FLASH_RECOVERY_AREA\STANDBY\ONLINELOG\O1_MF_3_B9H6KMLC_.LOG         YES
         4         STANDBY E:\APP\ADMIN\ORADATA\ORCL\ONLINELOG\REDO04.LOG                                   NO
         5         STANDBY E:\APP\ADMIN\ORADATA\ORCL\ONLINELOG\REDO05.LOG                                   NO
         6         STANDBY E:\APP\ADMIN\ORADATA\ORCL\ONLINELOG\REDO06.LOG                                   NO
         7         STANDBY E:\APP\ADMIN\ORADATA\ORCL\ONLINELOG\REDO07.LOG                                   NO



2.7 应用重做日志

SQL> alter database start logical standby apply;
 
Database altered

停止应用重做

SQL> alter database stop logical standby apply ;


2.8 测试数据同步

主库:

create user usr1 identified by usr1;

grant connect,resource to usr1;

conn usr1/usr1

create table test1(comment varchar2(10));

insert into test1 values(comment varchar2(10));

commit;

alter system switch logfile;

备库:

查看test1表是否有数据

注:不要使用sys等用户来测试

Logical standby创建成功。



你可能感兴趣的:(Oracle 11g 建立Logical standby 测试环境搭建 For Windows)