Oracle 11g中的snapshot standby特性
在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的還原速度.