微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用flashback database 特性将dataguard 的standby 库激活为read write的实现方法

可以利用10gflashback特性来实现激活为standby库为read write状态,standby库处于read write状态时可以在standby库上进行一些不能在主库上进行的测试工作,在完成之后可以将read write状态stnadbyflashback到原来的recover mount状态,下图为操作原理过程:


下为实验过程:

一.从库:

1. 设置flashback区域:

要使用这个特性就必须在standby库中设置flashback

在我的库中:

sql> show parameter DB_RECOVERY_FILE_DEST

NAME                                TYPE       VALUE

------------------------------------ ----------- ------------------------------

db_recovery_file_dest               string     /dg_flashback

db_recovery_file_dest_size          big integer  980M

 

2. Standby库取消redo日志的应用并创建一个数据库flashback 

sql> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;

Database altered.

 

sql> CREATE RESTORE POINT before_application_test GUaraNTEE FLASHBACK

 2 DATABASE;

Restore point created.

 

 主库

1.归档当前的日志文件,可从库确认这个flackbackSCN

sql> ALTER SYstem ARCHIVE LOG CURRENT;

System altered.

2.停止主库的日志传到从库:

sql> ALTER SYstem SET LOG_ARCHIVE_DEST_STATE_2=DEFER;

System altered.

 

三.激活为standby库为read write状态

1.激活为standby

sql> ALTER DATABASE ACTIVATE STANDBY DATABASE;

Database altered.

 

2,如果standb处于readonly状态时,强制重启到mount

sql> STARTUPMOUNTFORCE;

ORA-32004: obsolete and/or deprecated parameter(s) specified

ORACLE instance started.

Total System Global Area 218103808 bytes

Fixed Size                 1260984 bytes

Variable Size             83886664 bytes

Database Buffers         130023424 bytes

Redo Buffers               2932736 bytes

Database mounted.

 

3.standb改成 performance保护模式,并打开数据到read write状态,主库并不受standby库的影响,可以按正常的方式进行操作:

sql> ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE;

Database altered.

 

sql> ALTER DATABASE OPEN;

 

Database altered.

sql> select open_mode from v$database;

 

OPEN_MODE

----------

READ WRITE

这时可以进行各种test工作:我在主库建表t_flash,standby库建了一张f_t表:可以在flashback之后看他是否还存在:

 

在主库建:

sql> create table t_flash(name char(30));

Table created.

sql> insert into t_flash values('just a test');

1 row created.

 

sql> commit;

Commit complete.

从库建表f_t

sql> create table f_t( a int);

 

Table created.

 

sql> insert into f_t values(34);

 

1 row created.

 

sql> commit;

 

Commit complete.

 

 

三.将standbyflashbackbefore_application_tes时的SCN并重新置为physical standby role

1从库:

sql> STARTUP MOUNT FORCE;

ORA-32004: obsolete and/or deprecated parameter(s) specified

ORACLE instance started.

 

Total System Global Area 218103808 bytes

Fixed Size                 1260984 bytes

Variable Size             92275272 bytes

Database Buffers         121634816 bytes

Redo Buffers               2932736 bytes

Database mounted.

sql> FLASHBACK DATABASE TO RESTORE POINT before_application_test;

 

Flashback complete.

 

sql> ALTER DATABASE CONVERT TO PHYSICAL STANDBY;

 

Database altered.

 

sql> STARTUP MOUNT FORCE;

ORA-32004: obsolete and/or deprecated parameter(s) specified

ORACLE instance started.

 

Total System Global Area 218103808 bytes

Fixed Size                 1260984 bytes

Variable Size            100663880 bytes

Database Buffers         113246208 bytes

Redo Buffers               2932736 bytes

Database mounted.

sql> select * from v$archive_gap;  

 

no rows selected

 

sql> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE disCONNECT;

 

Database altered.

 

 

2.主库

 sql> ALTER SYstem SET LOG_ARCHIVE_DEST_STATE_2=ENABLE;

 

四.检查在standby库被激活时的分别在pirmary,standby库上建的表,此时在standby库中是否存在:

sql> alter database recover managed standby database cancel;

Database altered.

 

sql> alter database open read only;

 

Database altered.

---从库的表已经不存在:

sql> select * from f_t;

select * from f_t

             *

ERROR at line 1:

ORA-00942: table or view does not exist

 

主库的表已经通过archivelogapplystandby库中已经可以查询到了:

sql> select * from t_flash;

 

NAME

------------------------------

just a test

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐