ADG 配置 见 http://my.oschina.net/1272149624/blog/618290
本节接上节继续——ADG switchover and failover 、三种模式的切换
查看ADG当前模式
主:
SQL> select database_role,protection_mode,protection_level from v$database; DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL ---------------- -------------------- -------------------- PRIMARY MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE
备:
SQL> select database_role,protection_mode,protection_level from v$database; DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL ---------------- -------------------- -------------------- PHYSICAL STANDBY MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE
--默认ADG为最大性能模式
切换为最大可用模式
SQL> alter database set standby database to maximize availability; 主: SQL> select database_role,protection_mode,protection_level from v$database; DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL ---------------- -------------------- -------------------- PRIMARY MAXIMUM AVAILABILITY MAXIMUM AVAILABILITY 备: 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; 主: SQL> select database_role,protection_mode,protection_level from v$database; DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL ---------------- -------------------- -------------------- PRIMARY MAXIMUM PROTECTION MAXIMUM PROTECTION 备: SQL> select database_role,protection_mode,protection_level from v$database; DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL ---------------- -------------------- -------------------- PHYSICAL STANDBY MAXIMUM PROTECTION MAXIMUM PROTECTION
********************* 三种模式间,具体细节区别,请自行建立相关实验测试 *********************
查看主备状态
主: SQL> select instance_name,status from v$instance; INSTANCE_NAME STATUS ---------------- ------------ primary OPEN 备: SQL> select instance_name,status from v$instance; INSTANCE_NAME STATUS ---------------- ------------ standby OPEN
switchover切换
SQL>alter database commit to switchover to physical standby with session shutdown; 查看主库状态 SQL> select database_role,protection_mode,protection_level from v$database; DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL ---------------- -------------------- -------------------- PHYSICAL STANDBY MAXIMUM PROTECTION UNPROTECTED SQL> select database_role,switchover_status from v$database; DATABASE_ROLE SWITCHOVER_STATUS ---------------- -------------------- PHYSICAL STANDBY RECOVERY NEEDED
查看备库状态 SQL> select database_role,protection_mode,protection_level from v$database; DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL ---------------- -------------------- -------------------- PHYSICAL STANDBY MAXIMUM PROTECTION MAXIMUM PROTECTION
备库:
SQL> alter database commit to switchover to primary with session shutdown;
Database altered.
查看备库状态:
SQL> select database_role,protection_mode,protection_level from v$database; DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL ---------------- -------------------- -------------------- PRIMARY MAXIMUM PROTECTION UNPROTECTED 查看主库状态: SQL> select database_role,switchover_status from v$database; DATABASE_ROLE SWITCHOVER_STATUS ---------------- -------------------- PHYSICAL STANDBY RECOVERY NEEDED
主备都执行:
shutdown immediate;
startup;
查看备库状态,发现成了primary角色
SQL> select database_role,protection_mode,protection_level from v$database; DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL ---------------- -------------------- -------------------- PRIMARY MAXIMUM PROTECTION MAXIMUM PROTECTION
查看主库状态,发现成了standby角色
SQL> select database_role,switchover_status from v$database; DATABASE_ROLE SWITCHOVER_STATUS ---------------- -------------------- PHYSICAL STANDBY TO PRIMARY
做测试
备: SQL> archive log list; Database log mode Archive Mode Automatic archival Enabled Archive destination /u01/app/oracle/fast_recovery_area Oldest online log sequence 40 Next log sequence to archive 41 Current log sequence 41 主: SQL> archive log list; Database log mode Archive Mode Automatic archival Enabled Archive destination /u01/app/oracle/fast_recovery_area Oldest online log sequence 39 Next log sequence to archive 0 Current log sequence 41 备: SQL> alter system switch logfile; System altered. SQL> archive log list; Database log mode Archive Mode Automatic archival Enabled Archive destination /u01/app/oracle/fast_recovery_area Oldest online log sequence 40 Next log sequence to archive 42 Current log sequence 42 主: SQL> archive log list; Database log mode Archive Mode Automatic archival Enabled Archive destination /u01/app/oracle/fast_recovery_area Oldest online log sequence 39 Next log sequence to archive 0 Current log sequence 42 查看备库switchover状态 SQL> select database_role,switchover_status from v$database; DATABASE_ROLE SWITCHOVER_STATUS ---------------- -------------------- PRIMARY TO STANDBY 查看主库switchover状态 SQL> select database_role,switchover_status from v$database; DATABASE_ROLE SWITCHOVER_STATUS ---------------- -------------------- PHYSICAL STANDBY NOT ALLOWED
---SWITCHOVER_STATUS好像不正常,不过后面测试却是可以的,具体原因,我再研究下下
***************至此,switchover 结束 *********
关于,swithover后,验证数据可行性,上面步骤是有问题的,留下悬念(提示,备库启动时,应该先启动到mount,再recover)