使用DGMGRL一步一步配置DataGuard Broker

在这篇文章里面,主要介绍如何一步一步使用DGMGRL工具配置DataGuard Broker.其实很多人都写过这样的文章,这里我自己也写一篇,目的是增加点记忆.毕竟好记性不如烂笔头.同时我写东西喜欢先介绍一下这东西的原理再开始进行实践性的操作,有的哥们写文章写的让我很郁闷,只有怎么搭的,连原理也不介绍一下,对新手来说,写点原理性的再加点实践我觉得才是最好的.跑了题了,言归正传吧,使用DataGuard Broker能更加容易的管理和维护多个Standby Database.如下图所示,如果我们的Standby Database比较多的情况下,我们都得一个一个进行手工配置管理,太过于麻烦,而DataGuard Broker可以在一个地方对所有数据库进行统一的配置和管理,这些配置会自动同步到各个数据库中,简化了我们的管理.同时它还能使用一个简单的命令进行failover和switch over,并能够通过配置自动进行failover,最后它还具备monitor的功能,因此这个工具的用处还是比较大的.

dgbkr006

那么DataGuard Broken的工作原理是怎样的呢?这里简单介绍一下.Oracle DataGuard Broker分为Client Side和Server Side.Client Side很好理解,就是我们可以通过EM和DGMGRL两种工具对服务端进行管理和维护.

dgbkr008 (1)

而Server side会有一个配置文件和一个后台进程叫Data Guard Broker monitor process(DMON).

DMON:它是一个用来管理Broker的后台进程,这个进程负责本地数据库与standby数据库的DMON进程进行通讯,当主库上接收到一个请求的时候,它会协调其他数据库上的DMON进程处理相应的请求,比如switch over.同时会更新本地系统中的配置文件,并与standby数据库上的DMON进程进行通信,更新Standby上的配置文件.

配置文件:这个比较好理解,就是保存了Broker管理的所有数据库的状态信息,包括数据库的属性.

介绍了基本的原理后,接下来,我就开始一步一步的搭建我们的DataGuard Broker.我这里参考的文档是:Step by Step How to Create Dataguard Broker Configuration [ID 984622.1].我把步骤重新规划了一下:

  • 1.主库设置
  • 2.备库设置
  • 3.创建DataGuard Broker配置
  • 4.添加standby database到配置
  • 5.开启配置
  • 6.验证配置和switch over

这里先介绍一下我的环境

Database Name dg1 dg1
Database Unqie Name dg1 dg2
Net Service Name dg1 dg2
Version 11.2.0.3 for x86_64 11.2.0.3 for x86_64

1.主库设置

DB_BROKER_CONFIG_FILEn参数用于指定DataGuard配置文件的路径,DG_BROKER_START参数设置实例启动的时候是否自动启动Broken.

SQL> alter system set dg_broker_config_file1='/oracle/app/oracle/product/11.2.0/db_1/dbs/dr1dg1.dat' scope=both sid='*'; ;
System altered.

SQL> alter system set dg_broker_config_file2='/oracle/app/oracle/product/11.2.0/db_1/dbs/dr2dg1.dat' scope=both sid='*'; ;
System altered.

SQL> alter system set DG_BROKER_START=TRUE scope=both sid='*';
System altered.

设置完上面的参数后,我们还需要修改监听listener.ora文件.我们必须添加一个静态注册的service_name为db_unique_name_DGMGRL.db_domain,这个service_name会在DGMGRL重启数据库的时候用到.通过DGMGRL重启数据库时DMON进程会先将数据库关闭,然后DGMGRL在通过静态监听中的service_name连接到数据库,发送启动的命令.如果不这么做的话,在做switch over的时候我们容易遇到TNS-12514错误,

SID_LIST_LISTENER = (
SID_LIST = (
SID_DESC = (GLOBAL_DBNAME = dg1_DGMGRL)
(SERVICE_NAME  = dg1)
(SID_NAME      = dg1)
(ORACLE_HOME   = /oracle/app/oracle/product/11.2.0/db_1)
)
)

这里需要说明的是GLOBAL_DBNAME=<db_unique_name>_DGMGRL,<db_domain>.
SERVICE_NAME=<db_unique_name>,<db_domain>.
SID_NAME=echo $ORACLE_SID.
ORACLE_HOME=echo $ORACLE_HOME
2.备库设置

和主库设置一样,同样需要设置DB_BROKER_CONFIG_FILEn参数和DG_BROKER_START参数.还有静态监听.

SQL> alter system set dg_broker_config_file1='/oracle/app/oracle/product/11.2.0/db_1/dbs/dr1dg2.dat' scope=both sid='*';
System altered.

SQL> alter system set dg_broker_config_file2='/oracle/app/oracle/product/11.2.0/db_1/dbs/dr2dg2.dat' scope=both sid='*';
System altered.

SQL> alter system set DG_BROKER_START=TRUE scope=both sid='*';
System altered.

SID_LIST_LISTENER = (
SID_LIST = (
SID_DESC = (GLOBAL_DBNAME = dg2_DGMGRL)
(SERVICE_NAME  = dg2)
(SID_NAME      = dg2)
(ORACLE_HOME   = /oracle/app/oracle/product/11.2.0/db_1)
)
)

3.创建DataGuard Broker配置

在主库上使用dgmgrl连接到数据库.创建配置.

[oracle@dg1 admin]$ dgmgrl
DGMGRL for Linux: Version 11.2.0.1.0 - 64bit Production

Copyright (c) 2000, 2009, Oracle. All rights reserved.

Welcome to DGMGRL, type "help" for information.
DGMGRL> connect sys/oracle
Connected.
DGMGRL> CREATE CONFIGURATION 'dg1_config' as PRIMARY DATABASE IS 'dg1' connect identifier is 'dg1';
Configuration "dg1_config" created with primary database "dg1"

这里的参数要说明一下.dg1_config是配置的名称,这里可以随便填.PRIMARY DATABASE IS ‘dg1’ ,这儿的dg1是指database的db_unique_name,而connect identifier is ‘dg1’这里的dg1是指tnsname.ora连接到主库的net service name.

我们可以使用show confiruration查看配置信息.

DGMGRL> show configuration;

Configuration - dg1_config

Protection Mode: MaxPerformance
Databases:
dg1 - Primary database

Fast-Start Failover: DISABLED

Configuration Status:
DISABLED

4.添加standby database到配置

DGMGRL> add database 'dg2'  AS CONNECT IDENTIFIER IS dg2 MAINTAINED AS PHYSICAL;
Database "dg2" added

这里的参数要说明一下.add database ‘dg2’ ,这儿的dg2是指database的db_unique_name,而AS CONNECT IDENTIFIER IS dg2 这里的dg2是指tnsname.ora连接到standby database的net service name.

DGMGRL> show configuration;

Configuration - dg1_config

Protection Mode: MaxPerformance
Databases:
dg1 - Primary database
dg2 - Physical standby database

Fast-Start Failover: DISABLED

Configuration Status:
DISABLED

5.开启配置

DGMGRL> enable Configuration;

Enabled.
DGMGRL> DGMGRL>
DGMGRL>
DGMGRL> show Configuration;

Configuration - dg1_config

Protection Mode: MaxPerformance
Databases:
dg1 - Primary database
dg2 - Physical standby database

Fast-Start Failover: DISABLED

Configuration Status:
SUCCESS

6.验证swictover

DGMGRL> switchover to 'dg2';
Performing switchover NOW, please wait...
New primary database "dg2" is opening...
Operation requires shutdown of instance "dg1" on database "dg1"
Shutting down instance "dg1"...
ORACLE instance shut down.
Operation requires startup of instance "dg1" on database "dg1"
Starting instance "dg1"...
ORACLE instance started.
Database mounted.
Switchover succeeded, new primary is "dg2"

------------dg1

SQL> select database_role,switchover_status from v$database;

DATABASE_ROLE    SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY NOT ALLOWED

-----------dg2

SQL> select database_role,switchover_status from v$database;

DATABASE_ROLE    SWITCHOVER_STATUS
---------------- --------------------
PRIMARY          TO STANDBY

至此,整个配置过程结束!

参考文档:Step by Step How to Create Dataguard Broker Configuration [ID 984622.1].


分享到: 更多

Post a Comment

Your email is never published nor shared. Required fields are marked *