四、ADG三种模式切换及介绍
14、#ADG有三种(PROTECTION|AVAILABILITY|PERFORMANCE)模式,具体参考: 探索Oracle11gR2 之 DataGuard_03 三种保护模式
--primary操作步骤也就是命令之差:
SQL> select database_role,protection_mode,protection_level from v$database; ----当前为最大性能
DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
---------------- -------------------- --------------------
PRIMARY MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE
SQL>
SQL> alter database set standby database to maximize availability; ----切换为最大可用
Database altered.
SQL> select database_role,protection_mode,protection_level from v$database;
DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
---------------- -------------------- --------------------
PRIMARY MAXIMUM AVAILABILITY MAXIMUM AVAILABILITY
SQL> alter database set standby database to maximize protection; ----切换为最大保护
Database altered.
SQL> select database_role,protection_mode,protection_level from v$database;
DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
---------------- -------------------- --------------------
PRIMARY MAXIMUM PROTECTION MAXIMUM PROTECTION
SQL>
--#standby端切换到最大保护是需要重启数据库到mount模式的:
SQL> select database_role,protection_mode,protection_level from v$database; ----当前为最大性能
DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
---------------- -------------------- --------------------
PHYSICAL STANDBY MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE
SQL> alter database set standby database to maximize availability; ----切换为最大可用
Database altered.
SQL> select database_role,protection_mode,protection_level from v$database;
DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
---------------- -------------------- --------------------
PHYSICAL STANDBY MAXIMUM AVAILABILITY MAXIMUM AVAILABILITY
SQL> alter database set standby database to maximize protection; ----切换为最大保护模式报错,需要将standby端启动到mount状态切换.
alter database set standby database to maximize protection
*
ERROR at line 1:
ORA-01126: database must be mounted in this instance and not open in any instance
SQL> shutdown immediate ----将数据库启动到mount状态
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 1188511744 bytes
Fixed Size 1364228 bytes
Variable Size 754978556 bytes
Database Buffers 419430400 bytes
Redo Buffers 12738560 bytes
Database mounted.
SQL> alter database set standby database to maximize protection; ----再次切换为最大可用,成功。
Database altered.
SQL> recover managed standby database using current logfile disconnect from session;
Media recovery complete.
SQL> select database_role,protection_mode,protection_level from v$database;
DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
---------------- -------------------- --------------------
PHYSICAL STANDBY MAXIMUM PROTECTION MAXIMUM PROTECTION
五、切换测试
15、ADG做(switchover)切换测试
--primary 做如下操作
SQL> alter database commit to switchover to physical standby;
Database altered.
SQL> shutdown immediate
ORA-01012: not logged on
SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 1188511744 bytes
Fixed Size 1364228 bytes
Variable Size 754978556 bytes
Database Buffers 419430400 bytes
Redo Buffers 12738560 bytes
Database mounted.
Database opened.
SQL> alter database recover managed standby database disconnect from session;
Database altered.
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY TO PRIMARY
SQL>
--standby 端做如下操作
SQL> alter database commit to switchover to primary;
Database altered.
SQL> shutdown immediate
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 1188511744 bytes
Fixed Size 1364228 bytes
Variable Size 754978556 bytes
Database Buffers 419430400 bytes
Redo Buffers 12738560 bytes
Database mounted.
Database opened.
SQL> alter system switch logfile;
System altered.
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PRIMARY SESSIONS ACTIVE
SQL>
16、ADG做(fail over)切换测试
--standby 端检查状态
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ ONLY WITH APPLY
--我们通过shutdown abort方式人工模拟primary奔溃,直接关闭:
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ WRITE
SQL> shutdown abort
ORACLE instance shut down.
SQL>
--在standby端执行如下操作
SQL> startup mount;
ORACLE instance started.
Total System Global Area 1188511744 bytes
Fixed Size 1364228 bytes
Variable Size 754978556 bytes
Database Buffers 419430400 bytes
Redo Buffers 12738560 bytes
Database mounted.
SQL> alter system flush redo to \'pri\';
System altered.
SQL> select thread#, low_sequence#, high_sequence# from v$archive_gap;
no rows selected
--如果没有发现明显的gap现象,说明此次的failover不会有数据损失情况。在standby端,要进行关闭apply和结束应用动作。
SQL> alter database recover managed standby database cancel;
Database altered.
SQL> alter database recover managed standby database finish;
Database altered
SQL> select open_mode, switchover_status from v$database;
OPEN_MODE SWITCHOVER_STATUS
-------------------- --------------------
READ ONLY TO PRIMARY