1.物理备库转换成快照备库:
1.1查看备库当前状态,处于只读、实时恢复模式:
SQL> SELECT database_role, switchover_status, open_mode, protection_mode, protection_level FROM v$database;
DATABASE_ROLE SWITCHOVER_STATUS OPEN_MODE PROTECTION_MODE PROTECTION_LEVEL
---------------- -------------------- -------------------- -------------------- --------------------
PHYSICAL STANDBY NOT ALLOWED READ ONLY WITH APPLY MAXIMUM AVAILABILITY MAXIMUM AVAILABILITY
1.2取消日志应用:
SQL> alter database recover managed standby database cancel;
SQL> SELECT database_role, switchover_status, open_mode, protection_mode, protection_level FROM v$database;
DATABASE_ROLE SWITCHOVER_STATUS OPEN_MODE PROTECTION_MODE PROTECTION_LEVEL
---------------- -------------------- -------------------- -------------------- --------------------
PHYSICAL STANDBY NOT ALLOWED READ ONLY MAXIMUM AVAILABILITY MAXIMUM AVAILABILITY
1.3执行转换:
SQL> alter database convert to snapshot standby;
SQL> SELECT database_role, switchover_status, open_mode, protection_mode, protection_level FROM v$database;
DATABASE_ROLE SWITCHOVER_STATUS OPEN_MODE PROTECTION_MODE PROTECTION_LEVEL
---------------- -------------------- -------------------- -------------------- --------------------
SNAPSHOT STANDBY NOT ALLOWED MOUNTED MAXIMUM AVAILABILITY UNPROTECTED
SQL> SELECT database_role, switchover_status, open_mode, protection_mode, protection_level FROM v$database;
DATABASE_ROLE SWITCHOVER_STATUS OPEN_MODE PROTECTION_MODE PROTECTION_LEVEL
---------------- -------------------- -------------------- -------------------- --------------------
PHYSICAL STANDBY RECOVERY NEEDED READ ONLY MAXIMUM AVAILABILITY MAXIMUM AVAILABILITY
SQL> alter database recover managed standby database using current logfile disconnect from session;
1.4打开数据库:
SQL> alter database open;
SQL> SELECT database_role, open_mode FROM v$database;
DATABASE_ROLE OPEN_MODE
---------------- --------------------
SNAPSHOT STANDBY READ WRITE
2.验证快照standby:
SQL> create tablespace snapshotbs datafile‘/u01/app/oradata/testdb/snapshotbs01.dbf‘ size 10M;
SQL> column name format a50;
SQL> SELECT name FROM v$datafile;
NAME
--------------------------------------------------
/u01/app/oradata/testdb/system01.dbf
/u01/app/oradata/testdb/sysaux01.dbf
/u01/app/oradata/testdb/undotbs01.dbf
/u01/app/oradata/testdb/users01.dbf
/u01/app/oradata/testdb/example01.dbf
/u01/app/oradata/testdb/snapshotbs01.dbf
SQL> create table snapshotable( id int, namevarchar2(30)) tablespace snapshotbs;
SQL> SELECT table_name, tablespace_name FROM user_tables WHERE table_name=‘SNAPSHOTABLE‘;
TABLE_NAME TABLESPACE_NAME
------------------------------ ------------------------------
SNAPSHOTABLE SNAPSHOTBS
SQL> insert into snapshotable values( 1, ‘Test Snapshot Standby‘);
SQL> commit;
SQL> SELECT * FROM snapshotable;
ID NAME
---------- --------------------------------------------------
1 Test Snapshot Standby
SQL> alter system switch logfile;
3.切换还原成物理备库
3.1关闭数据库:
SQL> SELECT database_role, open_mode FROM v$database;
DATABASE_ROLE OPEN_MODE
---------------- --------------------
SNAPSHOT STANDBY READ WRITE
SQL> alter database convert to physical standby;
alter database convert to physical standby
*
ERROR at line 1:
ORA-01126: database must be mounted in this instance and notopen in any instance
SQL> shutdown immediate;
3.2启动到mount状态:
SQL> startup mount;
3.3进行切换
SQL> alter database convert to physical standby;
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01507: database not mounted
3.4重启数据库,并置于open状态:
SQL> shutdown abort;
SQL> startup;
3.5应用日志
SQL> SELECT database_role, open_mode FROM v$database;
DATABASE_ROLE OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY READ ONLY
SQL> SELECT database_role, switchover_status, open_mode,protection_mode, protection_level FROM v$database;
DATABASE_ROLE SWITCHOVER_STATUS OPEN_MODE PROTECTION_MODE PROTECTION_LEVEL
---------------- -------------------- -------------------- -------------------- --------------------
PHYSICAL STANDBY RECOVERY NEEDED READ ONLY MAXIMUM AVAILABILITY MAXIMUM AVAILABILITY
SQL> alter database recover managed standby database using current logfile disconnect from session;
SQL> SELECT database_role, open_mode FROM v$database;
DATABASE_ROLE OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY READ ONLY WITH APPLY
SQL>
SQL> SELECT name FROM v$datafile;
NAME
--------------------------------------------------
/u01/app/oradata/testdb/system01.dbf
/u01/app/oradata/testdb/sysaux01.dbf
/u01/app/oradata/testdb/undotbs01.dbf
/u01/app/oradata/testdb/users01.dbf
/u01/app/oradata/testdb/example01.dbf
SQL> SELECT * FROM snapshotable;
SELECT * FROM snapshotable
*
ERROR at line 1:
ORA-00942: table or view does not exist