在Oracle 11g中,data guard最吸引人的,除了active data guard的实时查询特性(即可以以只读方式打开物理standby数据库的同时MRP进程能继续做recover),快照备用数据库这个特性也是不错,比较适用于快速部署一个临时的与线上环境相同的测试数据库.它是通过还原点(restore point)和闪回数据库的原理(flashback database),可以以读/写方式打开物理备用数据库,对数据库进行修改,之后再根据还原点,恢复到物理备用数据库。
操作相当简单,以下测试:
一.物理备用数据库到快照备用数据库
--查看当前备用数据库的角色
SQL> select open_mode,database_role from v$database;
OPEN_MODE DATABASE_ROLE
-------------------- ----------------
READ ONLY WITH APPLY PHYSICAL STANDBY
--关闭并启动到mount
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 730714112 bytes
Fixed Size 2256832 bytes
Variable Size 482345024 bytes
Database Buffers 243269632 bytes
Redo Buffers 2842624 bytes
Database mounted.
--转换物理standby到快照standby
SQL> alter database convert to snapshot standby;
Database altered.
SQL> select status from v$instance;
STATUS
------------
MOUNTED
SQL> alter database open;
Database altered.
--查看当前备用数据库的角色
SQL> select open_mode,database_role from v$database;
OPEN_MODE DATABASE_ROLE
-------------------- ----------------
READ WRITE SNAPSHOT STANDBY
--可以看到,oracle 有建了一个还原点
SQL> select name,storage_size from v$restore_point;
NAME
--------------------------------------------------------------------------------
STORAGE_SIZE
------------
SNAPSHOT_STANDBY_REQUIRED_08/10/2015 05:33:52
52428800
--测试是否可以修改数据库
SQL> create table scott.test02 as select * from dba_objects;
Table created.
SQL> select count(1) from scott.test02;
COUNT(1)
----------
86267
二.快照备用数据库到物理备用数据库
--查看当前备用数据库的角色
SQL> select open_mode,database_role from v$database;
OPEN_MODE DATABASE_ROLE
-------------------- ----------------
MOUNTED SNAPSHOT STANDBY
--关闭并启动到mount
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 730714112 bytes
Fixed Size 2256832 bytes
Variable Size 482345024 bytes
Database Buffers 243269632 bytes
Redo Buffers 2842624 bytes
Database mounted.
--转换快照standby到物理standby
SQL> alter database convert to physical standby;
Database altered.
SQL> shutdown immediate;
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 730714112 bytes
Fixed Size 2256832 bytes
Variable Size 482345024 bytes
Database Buffers 243269632 bytes
Redo Buffers 2842624 bytes
Database mounted.
Database opened.
SQL> alter database recover managed standby database disconnect;
Database altered.
--查看当前备用数据库的角色
SQL> select open_mode,database_role from v$database;
OPEN_MODE DATABASE_ROLE
-------------------- ----------------
READ ONLY WITH APPLY PHYSICAL STANDBY
--查看在快照standby时建的测试表已经不存在了
SQL> select * from scott.test02;
select * from scott.test02
*
ERROR at line 1:
ORA-00942: table or view does not exist
备注:
物理standby是最高保护模式(maximum protection),是不能转换为snapshot standby的.
物理standby使用了standby redo log,在create restore point后,要alter system switch logfile;,以保证还原点的scn在物理standby库上是
归档的,不然可能无法成功闪回到还原点.
物理standby在切换为快照standby后,如果间隔很长时间,primary数据库产生的大量的重做日志,这样可以在转换为物理standby后,通过
对primary数据库的增量备份并recover到物理standby,来加快物理standby的还原速度.
原文地址:https://www.cnblogs.com/hftian/p/9334133.html