关于DataGuard的三种保护模式实验

Data Guard是Oracle高可用性HA的重要解决方案。针对不同的系统保护需求,DG提供了三种不同类型的保护模式(Protection Mode),分别为:最大保护(Maximum Protection)、最大可用(Maximum Availability)和最大性能(Maximum performance)。在实际应用场景下,我们需要根据不同的业务场景和数据可用性需求,来设置DG环境的保护类型。

1、三种保护模式Protection Mode

三种保护模式是DG的核心概念。DG本质上是一种基于Redo Log的数据同步机制。Undo和Redo是Oracle早期奠定行业地位的核心技术。Undo负责记录事务操作的前镜像,而Redo负责记录事务操作的后镜像。在Oracle事务commit的动作中,写入日志文件是一个一定需要完成的动作。写入日志文件之后,即使立刻出现严重的实例终止事件,在重新启动实例的时候也会进行实例恢复动作,将事务落实。

在DG环境中,无论采用何种初始化方法,都是确保一个Primary和Standby的初始化数据一致,之后Primary一端接收的事务类型操作,均会以归档日志串列的方式传递到Standby端的standby redo log和归档日志列表中,最后重复应用这些日志,实现Primary和Standby端一致。

Primary和Standby是相互为备份的冗余结构,Standby跟随Primary的情况,反映了HA结构的可用性级别。理论上,最保险的策略是一个事务要保证在Primary和Standby上都提交了,才返回给用户说已经完成。这样是可以保证主备库完全一致的最保险做法。另一个极端情况,就是主库“自顾自”进行事务处理,独立将日志进行传输,也不用管日志是否传输到或者应用到。

针对不同的传输情况,DG区分为三种保护类型:

ü  最大可用模式Maximum Availability

在官方文档中,对这种模式的描述如下:

“This protection mode provides the highest level of data protection that is possible without compromising the availability of a primary database. Transactions do not commit until all redo data needed to recover those transactions has been written to the online redo log and to the standby redo log on at least one synchronized standby database. If the primary database cannot write its redo stream to at least one synchronized standby database, it operates as if it were in maximum performance mode to preserve primary database availability until it is again able to write its redo stream to a synchronized standby database.”

Maximum Availability模式下,事务只有在所有相关日志都被传输到至少一个Standby端日志的时候,才可以正式提交。但是,如果Primary在传输日志的过程中,发现所有standby端都不能进行传输,模式会退化到最大性能模式(Maximum Performance)工作方式。应该说,Maximum Availability是一种自适应的保护模式,当出现问题的时候,DG会退而求其次,确保Primary主库事务进行。

ü  最大性能模式(Maximum Performance)

官方文档中介绍如下:“This protection mode provides the highest level of data protection that is possible without affecting the performance of a primary database. This is accomplished by allowing transactions to commit as soon as all redo data generated by those transactions has been written to the online log. Redo data is also written to one or more standby databases, but this is done asynchronously with respect to transaction commitment, so primary database performance is unaffected by delays in writing redo data to the standby database(s).

This protection mode offers slightly less data protection than maximum availability mode and has minimal impact on primary database performance.

This is the default protection mode.”

最大性能模式是在不影响主库工作情况下,可以提供的最高数据保护级别。当事务进行提交的时候,主库不会去确认日志是否写入到备库中,更不会确认是否被apply。这种方式下,主库的工作性能是不会收到备库提交应用的影响的。当然,这种保护模式会有一定的事务数据丢失,但是绝对不会出现数据误提交的情况。

对DG而言,最大性能模式是默认的保护模式。当我们完成了DG安装之后,就自动进入了Maximum Performance模式。

ü  最大保护模式(Maximum Protection)

最大保护模式在官方中的描述为:

“This protection mode ensures that no data loss will occur if the primary database fails. To provide this level of protection, the redo data needed to recover a transaction must be written to both the online redo log and to the standby redo log on at least one synchronized standby database before the transaction commits. To ensure that data loss cannot occur, the primary database will shut down, rather than continue processing transactions, if it cannot write its redo stream to at least one synchronized standby database.

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/26ec8205c4e6344b974a6d904d309600.html