今天做switchover,环境是11.2.0.3+OEL5.7,开始时主备库状态都是正常的,符合直接切换条件:


主库:


SQL> select open_mode,database_role,switchover_status from v$database;




OPEN_MODE            DATABASE_ROLE    SWITCHOVER_STATUS


-------------------- ---------------- --------------------


READ WRITE           PRIMARY          TO STANDBY




备库:


SQL> select open_mode,database_role,switchover_status from v$database;




OPEN_MODE            DATABASE_ROLE    SWITCHOVER_STATUS


-------------------- ---------------- --------------------


READ ONLY WITH APPLY PHYSICAL STANDBY NOT ALLOWED




主库直接进行swichover:


SQL> alter database commit to switchover to physical standby;


alter database commit to switchover to physical standby


*


ERROR at line 1:


ORA-01093: ALTER DATABASE CLOSE only permitted with no sessions connected






SQL> select open_mode,database_role,switchover_status from v$database;




OPEN_MODE            DATABASE_ROLE    SWITCHOVER_STATUS


-------------------- ---------------- --------------------


READ WRITE           PRIMARY          LOG SWITCH GAP




提示有日志切换GAP,于是直接重启主库:


SQL> startup force


ORACLE instance started.




Total System Global Area  413372416 bytes


Fixed Size                  2228904 bytes


Variable Size             322964824 bytes


Database Buffers           83886080 bytes


Redo Buffers                4292608 bytes


Database mounted.


Database opened.


SQL> select open_mode,database_role,switchover_status from v$database;




OPEN_MODE            DATABASE_ROLE    SWITCHOVER_STATUS


-------------------- ---------------- --------------------


READ WRITE           PRIMARY          RESOLVABLE GAP




状态由LOG SWITCH GAP变成了RESOLVABLE GAP,从字面理解是主备库之间存在GAP,于是执行:




SQL> ALTER SYSTEM FLUSH REDO TO ora11dg2;




SQL> select open_mode,database_role,switchover_status from v$database;




OPEN_MODE            DATABASE_ROLE    SWITCHOVER_STATUS


-------------------- ---------------- --------------------


READ WRITE           PRIMARY          TO STANDBY




把主库REDO FLUSH到备库以后,以上状态消失,又重新回到之前的TO STANDBY状态了,可以重新进行SWITCHOVER了。


如果主库状态不是TO STANDBY,而是SESSION ACTIVE,就要加上WITH SESSION SHUTDOWN,否则不能切换成功,除此以外的其他状态,是不能直接进行转换的。备库通常的状态是NOT ALLOWED,当主库做了切换以后,会变成TO PRIMARY,所以通常是现在主库做ROLE TRANSITION,然后再在备库做。




以下是一些消除主备库之间GAP的命令和说明:




--主库,将所有未传送的redo传送给从库,target_db_name使用DB_UNIQUE_NAME 。


ALTER SYSTEM FLUSH REDO TO target_db_name;




--验证备库


SELECT UNIQUE THREAD# AS THREAD, MAX(SEQUENCE#) OVER (PARTITION BY thread#) AS LAST from V$ARCHIVED_LOG;




--如果必要,拷贝归档日志到从库,并进行注册


 ALTER DATABASE REGISTER PHYSICAL LOGFILE 'filespec1';




--重复上一步,知道确认所有归档完毕。


SELECT THREAD#, LOW_SEQUENCE#, HIGH_SEQUENCE# FROM V$ARCHIVE_GAP;




--查看目标日志传输路径状态和GAP状态


SELECT STATUS, GAP_STATUS FROM V$ARCHIVE_DEST_STATUS WHERE DEST_ID = 2;




--在目标备库上,停止日志应用


ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;




--在目标备库上


ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH;




--如果日志确定丢失,可以采用激活方式,但这样会有数据丢失。


--ALTER DATABASE ACTIVATE PHYSICAL STANDBY DATABASE;




--验证目标备库


SELECT SWITCHOVER_STATUS FROM V$DATABASE;




--开始切换,如果状态为“TO PRIMARY”,则WITH SESSION SHUTDOWN从句可以去掉。


ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN;




--打开新主库


ALTER DATABASE OPEN;




附一份DG主备库切换状态说明:




v$database

  1. NOT ALLOWED - On a primary database, this status indicates that there are no valid and enabled standby databases. On a standby database, this status indicates that a switchover request has not been received from the primary database.
  2. SESSIONS ACTIVE - The database has active sessions. On a physical standby database, the WITH SESSION SHUTDOWN SQL clause must be specified to perform a role transition while in this state. On a logical standby database, a role transition can be performed while in this state, but the role transition will not complete until all current transactions have committed.
  3. SWITCHOVER PENDING - On a physical standby database, this status indicates that a switchover request has been received from the primary database and is being processed. A physical standby database cannot switch to the primary role while in this transient state.
  4. SWITCHOVER LATENT - On a physical standby database, this status indicates that a switchover request was pending, but the original primary database has been switched back to the primary role.
  5. TO PRIMARY - The database is ready to switch to the primary role.
  6. TO STANDBY - The database is ready to switch to either the physical or logical standby role.
  7. TO LOGICAL STANDBY - The database has received a data dictionary from a logical standby database and is ready to switch to the logical standby role.
  8. RECOVERY NEEDED - On a physical standby database, this status indicates that additional redo must be applied before the database can switch to the primary role.
  9. PREPARING SWITCHOVER - On a primary database, this status indicates that a data dictionary is being received from a logical standby database in preparation for switching to the logical standby role. On a logical standby database, this status indicates that the data dictionary has been sent to the primary database and other standby databases.
  10. PREPARING DICTIONARY - On a logical standby database, this status indicates that the data dictionary is being sent to the primary database and other standby databases in preparation for switching to the primary role.
  11. FAILED DESTINATION - On a primary database, this status indicates that one or more standby destinations are in an error state.
  12. RESOLVABLE GAP - On a primary database, this status indicates that one or more standby databases have a redo gap that can be automatically resolved by fetching the missing redo from the primary database or from another standby database.
  13. UNRESOLVABLE GAP - On a primary database, this status indicates that one or more standby databases have a redo gap that cannot be automatically resolved by fetching the missing redo from the primary database or from another standby database.
  14. LOG SWITCH GAP - On a primary database, this status indicates that one or more standby databases are missing redo due to a recent log switch.

SWITCHOVER 示例:




原主库:


SQL> alter database commit to switchover to physical 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 NEEDED






SQL> shutdown abort


ORACLE instance shut down.


SQL> startup mount


ORACLE instance started.






Total System Global Area  413372416 bytes


Fixed Size                  2228904 bytes


Variable Size             331353432 bytes


Database Buffers           75497472 bytes


Redo Buffers                4292608 bytes


Database mounted.




原备库:


SQL> select open_mode,database_role,switchover_status from v$database;






OPEN_MODE            DATABASE_ROLE    SWITCHOVER_STATUS


-------------------- ---------------- --------------------


READ ONLY WITH APPLY PHYSICAL STANDBY TO PRIMARY






SQL> alter database commit to switchover to primary;






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 WRITE           PRIMARY          TO STANDBY




原主库(新备库):


SQL> alter database recover managed standby database using current logfile 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 RECOVERY NEEDED




此时刚转换好的新备库SWITCHOVER状态是RECOVERY NEEDED,这是正常的,主库切几次日志以后就会变成NOT ALLOWED状态了,另外这个时候由于是REDO APPLY模式,虽然是11g,但也是无法直接OPEN的,如果要OPEN,必须先停止REDO APPLY:




SQL> alter database open;


alter database open


*


ERROR at line 1:


ORA-10456: cannot open standby database; media recovery session may be in progress










SQL> alter database recover managed standby database cancel;






Database altered.






SQL> alter database open;






Database altered.




由于11g的ACTIVE DG功能(需要LISENCE,否则属于非法使用),所以即便在OPEN状态下,依然能够REDO APPLY:




SQL> alter database recover managed standby database disconnect;






Database altered.






SQL> select open_mode,database_role,switchover_status from v$database;






OPEN_MODE            DATABASE_ROLE    SWITCHOVER_STATUS


-------------------- ---------------- --------------------


READ ONLY WITH APPLY PHYSICAL STANDBY NOT ALLOWED




至此,整个SWITCHOVER就做完了,SWITCHOVER是不会丢失数据的(不同于FAILOVER),如果FAILOVER能做到没有GAP,也可以不丢数据,并且正常使用SWITCHOVER切换(见官方文档B25608,第8章)。




------------------------------------------------------------------


by aaron8219


原创文章,转载请注明链接,谢谢!


http://blog.chinaunix.net/uid-24612962-id-3842449.html

最新文章

  1. Asp.net+JS 分页
  2. PHP学习之登录以及后台商品展示
  3. .net程序员转行做手游开发经历(一)
  4. java内存配置
  5. Viking Village维京村落demo中的地面积水效果
  6. Thread的六种状态
  7. 玩转渗透神器Kali:Kali Linux作为主系统使用的正确姿势TIPS
  8. 关于echarts的那些事(地图标点,折线图,饼图)
  9. eclipse 用maven创建web项目
  10. docker方式mysql设置字符集
  11. 2.解决虚拟机中centos联网的问题
  12. 阻止form提交数据,通过ajax等上传数据
  13. 看我如何快速学习.Net(高可用数据采集平台)
  14. linux文件修改管理
  15. C++实现线性表的顺序存储结构
  16. git fatal: 拒绝合并无关的历史的错误解决
  17. 元素的数据存储-jQuery.data()与.data()
  18. void *指针的加减运算
  19. EIP权限工作流平台-升级说明(2018-12-04)
  20. C语言初步学习I/O函数scanf、getchar、printf和putchar

热门文章

  1. STL——容器(Set & multiset)的大小
  2. Flutter InkWell - Flutter每周一组件
  3. 一目了然的 Node.js Windows10 安装篇
  4. mysql锁机制 读书笔记
  5. IIS重写2.0 IIS伪静态 下载地址
  6. Autofac官方文档翻译--一、注册组件--3属性和方法注入
  7. SecureCRT SSH Linux中不显示彩色 字体颜色、文件夹和文件显示的颜色区别开解决办法
  8. flowable获取上级主管
  9. 记一次jedis并发使用问题JedisException: Could not return the resource to the pool
  10. 身份证前6位地址码+码表+MySQL