racle 11g dataguard已經能夠臨時打開可讀寫備庫,打開後能夠進行更改,作壓力測試等工做,完成後不用進行從新恢復備庫直接能夠將角色更改成standby繼續應用管理日誌。sql
理備庫的初始狀態是正在應用日誌,咱們執行下面的命令生成快照數據庫,數據庫
SQL> alter database convert to snapshot standby;oracle
alter database convert to snapshot standby測試
*rest
ERROR at line 1:日誌
ORA-38784: Cannot create restore point 'SNAPSHOT_STANDBY_REQUIRED_11/23/201210:49:53'.blog
ORA-01153: an incompatible media recovery is activeget
看到了報錯信息,不過從報錯信息中,咱們也能看到,實際上所謂的快照數據庫,Oracle是利用了閃回數據庫的功能,首先他要生成一個restore point,flash
也就是未來閃回數據庫的起點。it
正確的操做是中止日誌應用,而後把數據庫轉換成快照數據庫
SQL> recover managed standby database cancel;
Media recovery complete.
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 name,open_mode,database_role,flashback_on from v$database;
NAME OPEN_MODE DATABASE_ROLE FLASHBACK_ON
---------
DB01 READ WRITE SNAPSHOT STANDBY RESTORE POINT ONLY
接下來就能夠作操做了,若是有壓力測試需求在這個狀態下能夠進行
SQL> create table d(x int,y char(3));
Table created.
SQL> insert into d values(100,'t');
1 row created.
SQL> commit;
Commit complete.
SQL> select * from t;
no rows selected
SQL> select * from d;
X Y
---
100 t
若是要改回原來的物理備庫狀態,要關閉數據庫,在mount狀態下執行命令
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 634679296 bytes
Fixed Size 2231032 bytes
Variable Size 411043080 bytes
Database Buffers 218103808 bytes
Redo Buffers 3301376 bytes
Database mounted.
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 634679296 bytes
Fixed Size 2231032 bytes
Variable Size 411043080 bytes
Database Buffers 218103808 bytes
Redo Buffers 3301376 bytes
Database mounted.
Database opened.
數據庫狀態已是物理備庫,固然剛纔作的操做也看不到了,好比說D表
SQL>select name,open_mode,database_role,flashback_on from v$database;
NAME OPEN_MODE DATABASE_ROLE FLASHBACK_ON
---------
DB01 READ ONLY PHYSICAL STANDBY NO
SQL> select * from d;
select * from d
*
ERROR at line 1:
ORA-00942: table or view does not exist
開啓日誌應用模式
SQL> recover managed standby database disconnect;
Media recovery complete.
SQL> select name,open_mode,database_role,flashback_on from v$database;
NAME OPEN_MODE DATABASE_ROLE FLASHBACK_ON
---------
DB01 READ ONLY WITH APPLY PHYSICAL STANDBY NO
在主庫上:
SQL> create table d(x number);
Table created.
SQL> insert into d values(1);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
回到備庫:
SQL> select * from d;
X
1