DG主备切换遇到not allwod或者RESOLVABLE GAP解决办法
今天做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
- 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.
- 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.
- 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.
- 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.
- TO PRIMARY - The database is ready to switch to the primary role.
- TO STANDBY - The database is ready to switch to either the physical or logical standby role.
- 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.
- 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.
- 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.
- 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.
- FAILED DESTINATION - On a primary database, this status indicates that one or more standby destinations are in an error state.
- 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.
- 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.
- 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
DG主备切换遇到not allwod或者RESOLVABLE GAP解决办法的更多相关文章
- oracle DG 主备切换语句整理
今日花了一下午时间进行了Oracle DataGuard的切换练习,参考了网上好多文章,最后将一些语句进行摘录,以备以后查询使用.之后有时间会带来Oracle DG的搭建和切换全过程文章. DataG ...
- RAC+单实例场景下 DG主备切换,报ORA-01577
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMAR ...
- 使用broker进行Datagurd主备切换报ORA-12514异常
在使用Datagurd broker进行Datagurd主备切换时报ORA-12514监听异常, 详细信息如下: DGMGRL> switchover to xiaohe; Performing ...
- 物理DG主备库切换时遇到ORA-16139: media recovery required错误
在物理DG主备库切换时遇到ORA-16139: media recovery required错误 SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRI ...
- DG日志不应用,GAP,主备切换解决思路与办法
环境ORACLE 10G OS WINDOWS 对于DG故障解决思路,DG日志切换不进行应用,DG出现GAP解决方法,DG主备库切换, 当DG出现故障时,第一时间检测alert日志,服务器OS日志,网 ...
- Oracle 12C 物理Standby 主备切换switchover
Oracle 12C 物理Standby 主备切换switchover Oracle 12C 物理Standby 主备切换switchover Table of Contents 1. 简述 2. 切 ...
- Spark系列(五)Master主备切换机制
Spark Master主备切换主要有两种机制,之中是基于文件系统,一种是基于Zookeeper.基于文件系统的主备切换机制需要在Active Master挂掉后手动切换到Standby Master ...
- Nginx+Keepalived主备切换(包含nginx服务停止)
原文地址:http://blog.sina.com.cn/s/blog_79ac6aa80101bmed.html Nginx+Keepalived主备切换(包含nginx服务停止) 环境: VM中4 ...
- 在Windows Azure上配置VM主备切换(1)——Linux篇
对任何一个上线系统来说,高可用设计是不可或缺的一个环节,这样才可以确保应用可以持续.稳定的运行,而不是频繁的掉线.停机.高可用设计的核心思路很简单,就是消除一切单点故障,将单点链路或者节点升级为多点. ...
随机推荐
- JavaSE15-集合·其二
1.Set集合 1.1 Set集合概述和特点 Set集合的特点 元素存取无序 没有索引.只能通过迭代器或增强for循环遍历 不能存储重复元素 1.2 哈希值 哈希值简介 是JDK根据对象的地址或者字符 ...
- python 全局变量与局部变量 垃圾回收机制
掌握L.E.G.B(作用域) 掌握局部作用域修改全局变量 步骤- 1.命名空间和作用域 命名空间:变量名称与值的映射关系作用域:变量作用的区域,即范围. 注意:class/def/模块会产生作用域:分 ...
- MySQL数据库死锁分析
背景说明: 公司内部一套自建分布式交易服务平台,在POC稳定性压力测试的时候出现了数据库死锁.(InnoDB引擎)由于保密性,假设是app_test表死锁了. 现象: 发生异常:Deadlock fo ...
- Collections.synchronizedList 并发
1.背景 集合类中的map,大家一定熟悉,知道它非线程安全.使用的方法有两种,一种是在map上加同步器(锁),另一种是创建容器时使用Collections中的静态方法对map进行包装. java ap ...
- Spark内核-Spark Shuffle 解析
作者:十一喵先森 链接:https://juejin.im/post/5e1c41c6f265da3e152d1e62 来源:掘金 著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. ...
- Python高级语法-对象实例对象属性-Property总结(4.6.2)
@ 目录 1.说明 2.代码 关于作者 1.说明 property属性,返回的是值 不是callable的,也就是不能使用方法来调用 只能传入self,不能传入其他 用处,能返回局部数据,比如当分页的 ...
- SQL注入-DNS注入(一)
这篇文章相对来说比较入门,参考的文章是:https://www.jianshu.com/p/c805209244c2 0x00前言 前段时间在做盲注 分别是基于时间和基于布尔型的 说真的 这两种盲注真 ...
- SpringBoot进阶教程(六十七)RateLimiter限流
在上一篇文章nginx限流配置中,我们介绍了如何使用nginx限流,这篇文章介绍另外一种限流方式---RateLimiter. v限流背景 在早期的计算机领域,限流技术(time limiting)被 ...
- .net下com调用支持x86/x64
起因 项目涉及u3d/wpf端的渲染图形合成,采用了开源项目spout,为了便捷,采用了spout的com版本作为c#端的调用 项目调整后,细节已经捋清楚了. 但是考虑桌面应用采用anypc,根据运行 ...
- 初学者迭代python
#汉诺塔 def hanni(n,A,B,C): if n == 1: print (A,'-->',C) else: # 将n-1个盘子移动到B上 hanni(n-1,A,C,B) # 将第n ...