Oracle-Data-Guard之物理备库切换 发表于 2017-03-24 | 分类于 Oracle Data Guard 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051#on the primary database(0.0.0.188)SQL> select open_mode, database_role, switchover_status from v$database;OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS-------------------- ---------------- --------------------READ WRITE PRIMARY TO STANDBYSQL> alter database commit to switchover to standby;Database altered.SQL> select open_mode, database_role, switchover_status from v$database;OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS-------------------- ---------------- --------------------READ WRITE PHYSICAL STANDBY RECOVERY NEEDEDSQL> shutdown immediate;ORA-01092: ORACLE instance terminated. Disconnection forcedSQL> exitDisconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit ProductionWith the Partitioning option[oracle@hzvscmdb db]$ sqlplus / as sysdbaSQL*Plus: Release 11.2.0.2.0 Production on Fri Mar 24 01:15:49 2017Copyright (c) 1982, 2010, Oracle. All rights reserved.Connected to an idle instance.SQL> startup nomount;ORACLE instance started.Total System Global Area 6664212480 bytesFixed Size 2239072 bytesVariable Size 4328523168 bytesDatabase Buffers 2315255808 bytesRedo Buffers 18194432 bytesSQL> alter database mount standby database;Database altered.SQL> alter database recover managed standby database disconnect from session;Database altered.SQL> select open_mode, database_role, switchover_status from v$database;OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS-------------------- ---------------- --------------------MOUNTED PHYSICAL STANDBY TO PRIMARY 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125#on the standby database(0.0.0.189)SQL> select open_mode, database_role, switchover_status from v$database;OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS-------------------- ---------------- --------------------MOUNTED PHYSICAL STANDBY NOT ALLOWEDSQL> alter database commit to switchover to primary;alter database commit to switchover to primary*ERROR at line 1:ORA-16139: media recovery requiredSQL> alter database recover managed standby database disconnect from session;Database altered.SQL> alter database commit to switchover to primary;Database altered.SQL> select open_mode, database_role, switchover_status from v$database;OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS-------------------- ---------------- --------------------MOUNTED PRIMARY NOT ALLOWEDSQL> shutdown immediate;ORA-01109: database not openDatabase dismounted.ORACLE instance shut down.SQL> startup;ORACLE instance started.Total System Global Area 6664212480 bytesFixed Size 2239072 bytesVariable Size 4328523168 bytesDatabase Buffers 2315255808 bytesRedo Buffers 18194432 bytesDatabase mounted.Database opened.SQL> select open_mode, database_role, switchover_status from v$database;OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS-------------------- ---------------- --------------------READ WRITE PRIMARY RESOLVABLE GAPSQL> select open_mode, database_role, switchover_status from v$database;OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS-------------------- ---------------- --------------------READ WRITE PRIMARY TO STANDBY###Test the data from on the primary database(0.0.0.189) to the standby database (0.0.0.188)SQL> select count(*) from mp.tlog; COUNT(*)---------- 13000002--模拟插入数据SQL> select SEQUENCE#, APPLIED from v$archived_log; SEQUENCE# APPLIED---------- --------- 3070 YES 3070 NOSQL> select count(*) from mp.tlog; COUNT(*)---------- 14000002##check data on the standby database (0.0.0.188) SQL> alter database recover managed standby database cancel;Database altered.SQL> alter database open;Database altered.SQL> select open_mode, database_role, switchover_status from v$database;OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS-------------------- ---------------- --------------------READ ONLY PHYSICAL STANDBY NOT ALLOWEDSQL> select count(*) from mp.tlog; COUNT(*)---------- 13000002SQL> select SEQUENCE#, APPLIED from v$archived_log where SEQUENCE# > 3060; SEQUENCE# APPLIED---------- --------- 3061 YES 3062 YES 3063 YES 3064 YES 3065 YES 3066 YES 3067 YES 3068 YES 3069 YES 3070 YES--发现新的数据没有被应用。此时在 the primary database(0.0.0.189)SQL> alter system switch logfile;System altered.-- 此时查看the standby database (0.0.0.188)SQL> select count(*) from mp.tlog; COUNT(*)---------- 14000002