Oracle 10g DataGuard学习(一)架构及概念介绍

从业这一行没多久,也没有什么经验,之前所接触到的客户数据库系统架构基本都是RAC或是单实例,又或是基于操作系统级别的双机环境,DataGuard架构的数据库系统遇到的相对较少,作为Oracle DB HA技术中一个重要的分支,在实际生产数据库环境中确实没有RAC用到的多。结果昨天一个使用Logical Standby DG的客户,要求去现场调整Primary DB Instance内存参数,这个操作是很简单,之前考认证时也演练过Physical DG,包括Switchover,但是确实没有认真看过官档,更别提DG的优化,于是决定看一看官档,详细了解一下DG的原理及优化方法,记录该过程,算是留个念想!

1-1 DG架构简介

DataGuard专门用来保护Oracle数据,可在提供最高级别的数据保护和可用性的同时,使Oracle数据库保持卓越的性能(对于这一说法,笔者认为也只是是相对而言,在Oracle的官方技术网站上有一个统计数据:远程镜像与DG相比,其生成的网络流量多7倍,网络I/O操作多27倍,而且远程镜像还有一个无法比拟DG的缺陷,远程镜像对Oracle事物一无所知,无法区分重做、撤消、数据块修改,控制文件写入等操作!),作为Oracle内核自带的一项功能,DataGuard和Oracle的其他高可用性技术集成在一起,比如RAC,RMAN,Oracle闪回技术等。在说DataGuard相关专业术语之前之前,先上个DG的结构图:


Figure 1-1/Figure 2-1说明了在DG架构中,主备数据库在地理位置上没有任何限制(只要确保主备数据库节点间网络通信及时间同步正常,即便主库在地球上,备库在月球上也没有问题!),这当然也包括主备数据库在同一台服务器上运行,但是这样做基本没有什么意义,因为如此一来,DG已无法提供最高级别的数据保护和可用性,而且还额外消耗服务器资源。因此DG最主要是用于容灾(包括同城或异地灾备),尽可能降低7*24小时不间断运行数据库系统计划停机或意外宕机的时间!

1-2 DG简单原理及相关概念

在Oracle 10g DG架构中的数据库共分为两种角色,一种称之为主库即生产数据库(Primary DB),另一种称为备用数据库(Standby DB又分为物理备库[Physical DB]和逻辑备库[Logical DB]),主库在同一时间只能有一个,而备库最多则可以有9个。主库主要支撑生产业务系统的正常运行,备库则是当主库出现计划内停机或意外宕机时迅速切换成主库继续支持业务的正常运行,也包将主库上的某些操作例如生成报表或大查询等操作放在备库上执行以降低主库的压力。

DataGuard运行机制遵循一个简单的原则:传输重做数据(主数据库即Primary DB传输Redo),然后应用重做数据(备用数据库即Standby DB应用Redo)重做数据中包括Oracle数据库恢复数据库事物所需要的所有信息,主数据库将重做数据传输给一个或多个独立备用数据库,DG备用数据库处于连续恢复状态,验证并应用重做数据,从而与主数据库保持同步。如果因为网络中断或备用数据库断电导致备用数据库与主数据库之间的连接临时中断,DG还会自动重新同步备用数据库,这个简单的架构使得当主数据库按计划停机或意外中断后,一个或多个备用数据库立即可供使用,从而恢复正常处理。其简单过程如下图


重做是DG操作的核心,因为备用数据库就是应用主库所传输的重做数据,从而保证备库与主库的数据同步,但对于重做的概念及基础知识,这里不在赘述,可查阅官方文档及相关Oracle技术丛书和网站!

由于DG提供两种不同的方法在备库上应用重做数据:Redo Apply(物理备用)和SQL Apply(逻辑备用),因此DG中的备库也就分为两种,一种是物理备库即Physical Standby DB,另一种为逻辑备库即Logical Standby DB,这二者的区别除了应用重做数据的方式不同外,还有两个最大的区别在于:①Physical Standby DB在应用主库传来的重做数据时只能启动到mount状态(不能open),当必要时需要在Physical Standby DB上执行某些查询时,此时只能将Physical Standby DB停止重做数据的应用(stop redo apply),然后以open read only方式打开Physical Standby DB执行某些查询;但对于Logical Standby DB而言,由于是采用SQL Apply的方式应用重做数据,因此可以以read/write模式open,很多应用上的大查询或是生成报表等操作就可以在Logical Standby DB上进行,大大减小了Primary DB的压力,除此以外还可以对已从Primary DB中同步到Logical Standby DB中本地表执行insert、update、delete等测试操作操作。②由于Physical Standby DB采用Redo Apply方式应用重做数据,因此Physical Standby DB则是Primary DB的一致copy,无论是磁盘上DB的数据块,还是DB中的schema和indexes都完全一致;而对于Logical Standby DB而言,与Primary DB拥有相同的逻辑信息,其物理结构及数据结构可以不同。

到这你可能会问,既然如此,为什么还要用Physical Standby,Logical Standb不但可以保持和主库的数据一致,而且还可以正常的open供应用使用,为什么还要用只能mount或是以read only方式openPhysical Standby,那是因为Logical  Standby由于是采用SQL Apply方式应用redo(即在备库中执行SQL语句)保持与主库数据的同步,而SQL语句必然会有某些数据类型不支持,比如ROWID、UROWID等数据类型,那在这种情况下,这些SQL所不支持的数据库类型数据就无法与主库同步,而Physical Standby由于是基于Redo Apply应用方式,因此不存在这种情况。所以在生产环境中需要结合实际情况进行分析选择,甚至有时会采用mixed模式投入生产。下图为Redo Apply和SQL Apply两种方式的DG示意图

以下为Oracle官方文档对于Primary DB、Physical Standby DB、Logical Standby DB的解释:

---Primary Database
A Data Guard configuration contains one production database, also referred to as the primary database, that functions in the primary role. This is the database that is accessed by most of your applications
The primary database can be either a single-instance Oracle database or an Oracle Real Application Clusters database.
---Physical standby database
Provides a physically identical copy of the primary database, with on disk database structures that are identical to the primary database on a block-for-block basis. The database schema, including indexes, are the same. A physical standby database is kept synchronized with the primary database, though Redo Apply, which recovers the redo data received from the primary database and applies the redo to the physical standby database.
A physical standby database can be used for business purposes other than disaster recovery on a limited basis.
---Logical standby database
Contains the same logical information as the production database, although the physical organization and structure of the data can be different. The logical standby database is kept synchronized with the primary database though SQL Apply, which transforms the data in the redo received from the primary database into SQL statements and then executing the SQL statements on the standby database.
A logical standby database can be used for other business purposes in addition to disaster recovery requirements. This allows users to access a logical standby database for queries and reporting purposes at any time. Also, using a logical standby database, you can upgrade Oracle Database software and patch sets with almost no downtime. Thus, a logical standby database can be used concurrently for data protection, reporting, and database upgrades.

PS: 未完待续…

发表评论

电子邮件地址不会被公开。

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>