Data Guard Broker系列之二:Data Guard Broker配置实战

简介:

配置之前DG环境状态

测试的DG环境安装在同一个机器上,当前两个数据库处于同步的状态,两个实例的名字分别是TORCLA和TORCLB,数据库的名字TORCL,数据库DB_DOMAIN设置为mycompany,其他的设置如下。

listener.ora设置

L_dg =
   
( address =
        
( protocol = tcp ) ( host = orainst . desktop . mycompany . com ) ( port = 8000 ) ( queuesize = 32 )
   
)
log_file_L_torcla_001 =/ tmp / L_torclb_001 . log
SID_LIST_L_dg =
  
( SID_LIST  =
    
( SID_DESC =
      
( ORACLE_HOME =/ data1 / dg / 10.2.0.2 / A10db )
      
( SID_NAME = torcl )
    
)
   
)

本地tnsname.ora的设置

torcl . mycompany =
 
( DESCRIPTION =
        
( ENABLE = BROKEN )
        
( ADDRESS_LIST =
                
( ADDRESS = ( PROTOCOL = TCP )( HOST = orainst . desktop . mycompany . com )( PORT = 8000 ))
        
)
        
( CONNECT_DATA =
                
( SID = torcl )
        
)
  
)
 
torcla . mycompany =
 
( DESCRIPTION =
        
( SDU 32767 )
        
( ADDRESS_LIST =
                
( ADDRESS = ( PROTOCOL = TCP )( HOST = orainst . desktop . mycompany . com )( PORT = 8000 ))
                
( ADDRESS = ( PROTOCOL = TCP )( HOST = orainst . desktop . mycompany . com )( PORT = 8000 ))
        
)
        
( CONNECT_DATA =
                
( SERVICE_NAME = torcla . mycompany )
                
( SERVER = DEDICATED )
        
)
  
)
 
torclb . mycompany =
 
( DESCRIPTION =
        
( SDU 32767 )
        
( ADDRESS_LIST =
                
( ADDRESS = ( PROTOCOL = TCP )( HOST = orainst . desktop . mycompany . com )( PORT = 8000 ))
                
( ADDRESS = ( PROTOCOL = TCP )( HOST = orainst . desktop . mycompany . com )( PORT = 8000 ))
        
)
        
( CONNECT_DATA =
                
( SERVICE_NAME = torclb . mycompany )
                
( SERVER = DEDICATED )
        
)
  
)

DG的相关设置

 

-- 保护模式
SYS @ torclb SELECT  DATABASE_ROLE ,   PROTECTION_MODE OPEN_MODE SWITCHOVER_STATUS FROM  V $ DATABASE ;
DATABASE_ROLE          PROTECTION_MODE             OPEN_MODE         SWITCHOVER_STATUS
------------------
-- ------------------------- --------------- --------------------
primary                MAXIMUM  PERFORMANCE         READ WRITE        SESSIONS  ACTIVE
 
-- 日志归档相关设置
SYS @ torclb show  parameter  log_archive_dest_1
NAME                                   TYPE                                VALUE
----------------------------------
-- --------------------------------- ------------------------------
log_archive_dest_1                     string                              location = " /data1/dg/databases/
                                                                       torclb/redolog
" valid_for = ( ONL
                                                                       
INE_LOGFILE , ALL_ROLES )
 
SYS @ torclb show  parameter  log_archive_dest_2
NAME                                   TYPE                                VALUE
----------------------------------
-- --------------------------------- ------------------------------
log_archive_dest_1                     string                              SERVICE = torcla . mycompany valid_fo
                                                                       
tr = ( online_logfile primary_ro
                                                                       
tle ) REOPEN = 60 OPTIONAL LGWR S
                                                                       
tYNC AFFIRM db_unique_name = torcla

broker设置准备工作

下面按照上一篇文章所列出的准备工作清单一一做一遍。

设置primary和standby使用spfile

不管是primary数据库还是standby数据库都要完成这一步,设置完毕后重启下数据库使设置生效。

 

--在当前的 primary
SYS @ torclb create  spfile = ' /data1/dg/10.2.0.2/A10db/dbs/spfiletorclb.ora from  pfile ;
File  created .
--在当前的
standby
SYS @ torcla create  spfile = ' /data1/dg/10.2.0.2/A10db/dbs/spfiletorclb.ora from  pfile ;
File  created .

然后修改init文件设定spfile参数:

-- primary的init文件
$
cat  inittorclb . ora
spfile = ' spfiletorclb.ora '
 
-- standby的init文件
$
cat  inittorcla . ora
spfile = ' spfiletorcla.ora '

配置DG_BROKER_CONFIG_FILEn

这里我们的DG_BROKER_CONFIG_FILEn不做特别的设置,使用默认的$ORACLE_HOME/dbs目录以及两个默认的文件名dr1.dat和dr2.dat。

当然也可以用sqlplus通过下面语句设定不同的目录,要注意在两个数据库上面都要设置:

alter  system  set  dg_broker_config_file1 = ' /data1/dg/10.2.0.2/A10db/dbs/dr1torcla.dat ' ;
alter  system  set  dg_broker_config_file2 = ' /data1/dg/10.2.0.2/A10db/dbs/dr2torcla.dat '

设置local_listener

这一步设置是为了保证一些service name能正确的被注册上。

SYS @ torcla alter  system  set  local_listener = ' (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=orainst.desktop.mycompany.com)(PORT=8000))) scope = both ;
System  altered .

添加静态的_unique_name_DGMGRL.db_domain注册

在当前的测试环境中primary和standby是在同一机器上面,因此这个service name的设置也是在同一个listener.ora文件上,设置完了以后的listener.ora如下

L_dg =
   
( address =
        
( protocol = tcp ) ( host = orainst . desktop . mycompany . com ) ( port = 8000 ) ( queuesize = 32 )
   
)
log_file_L_torcla_001 =/ tmp / L_torclb_001 . log
SID_LIST_L_dg =
  
( SID_LIST  =
    
( SID_DESC =
      
( ORACLE_HOME =/ data1 / dg / 10.2.0.2 / A10db )
      
( SID_NAME = torcl )
    
)
     
( SID_DESC =
      
( ORACLE_HOME =/ data1 / dg / 10.2.0.2 / A10db )
      
( SID_NAME = torcla )
      
( GLOBAL_DBNAME = torcla_DGMGRL . mycompany )
    
)
     
( SID_DESC =
      
( ORACLE_HOME =/ data1 / dg / 10.2.0.2 / A10db )
      
( SID_NAME = torclb )
      
( GLOBAL_DBNAME = torclb_DGMGRL . mycompany )
    
)
  
)
设置tnsmaes.ora
torcla_DGMGRL.mycompany = 
(DESCRIPTION= 
   (ADDRESS= (PROTOCOL = TCP)(HOST = orainst.desktop.mycompany.com)(PORT = 8000))
   (CONNECT_DATA= 
     (SERVICE_NAME=
torcla_DGMGRL.mycompany))) 

torclb_DGMGRL.mycompany = 
(DESCRIPTION= 
   (ADDRESS= (PROTOCOL = TCP)(HOST = orainst.desktop.mycompany.com)(PORT = 8000))
   (CONNECT_DATA= 
     (SERVICE_NAME=
torclb_DGMGRL.mycompany)))

设置完毕后记得重启下listener,然后查看一下设置的效果:

oracle @ orainst [ torcla ]:~
$
lsnrctl service L_dg | grep ' Service  '
Service  " torcl "   has  instance ( s ) .
Service  " torcla.mycompany has  instance ( s ) .
Service  " torcla_DGMGRL.mycompany has  instance ( s ) .
Service  " torcla_XPT.mycompany has  instance ( s ) .
Service  " torclb.mycompany has  instance ( s ) .
Service  " torclb_DGMGRL.mycompany has  instance ( s ) .
Service  " torclb_XPT.mycompany has  instance ( s ) .

从上面的listener上注册的服务我们可以看到动态注册的_XPT已经有了,说明local_listener设置正确,_DGMGRL也配置正确。

 

设置dg_broker_start为TRUE

这一步是启动Data Guard broker monitor(DMON)进程,在两个数据库上面都运行下下面的命令

alter  system  set  dg_broker_start = true  scope = both ;

然后查看下结果,先看进程是否起来了

oracle @ orainst [ torcla ]:~
$
ps  - ef | grep dmon | grep  - v grep
oracle     19389       1    0 09 : 51  ?         00 : 00 : 00 ora_dmon_torcla
oracle     19420       1    0 09 : 51  ?         00 : 00 : 00 ora_dmon_torclb

可以看到两个dmon进程都起来了,接下来看看service name _DGB有没有被正确的注册上

oracle @ orainst [ torcla ]:~
$
lsnrctl  service  L_dg grep  ' Service  '
Service  " torcl has  instance ( s ) .
Service  " torcla.mycompany has  instance ( s ) .
Service  " torcla_DGB.mycompany has  instance ( s ) .
Service  " torcla_DGMGRL.mycompany has  instance ( s ) .
Service  " torcla_XPT.mycompany has  instance ( s ) .
Service  " torclb.mycompany has  instance ( s ) .
Service  " torclb_DGB.mycompany has  instance ( s ) .
Service  " torclb_DGMGRL.mycompany has  instance ( s ) .
Service  " torclb_XPT.mycompany has  instance ( s ) .

可以看到service name _DGB也正常的注册上了,到现在我们前期的准备工就已经全部完成了。

配置broker

现在我们可以来配置broker了,为了保证配置过程不会因为权限问题导致问题,我们始终都是用sys连接数据库的。

首先使用DGMGRL连接到primary机器上,运行下面的命令:

oracle @ orainst [ torcla ]:~
$
dgmgrl  sys / 12345 @ torclb . mycompany
DGMGRL  for  Linux Version 10.2.0.2.0  -  Production
 
Copyright ( c ) 2000 2005 Oracle All  rights  reserved .
 
Welcome  to  DGMGRL ,   type  " help for  information .
Connected .
DGMGRL show  configuration
Error ORA - 16532 Data  Guard  broker  configuration  does  not  exist
Configuration  details  can not  be  determined  by  DGMGRL

当前还没有任何的配置信息,现在创建一个配置

 

DGMGRL create  configuration  ' FSF as
primary  database  is  ' torclb '
connect  identifier  is  torclb . mycompany ;
Configuration  " FSF created  with  primary  database  " torclb "

这样我们就创建了一个名为FSF的broker配置,接下来把standby机器也就入到配置中

 

DGMGRL add  database  ' torcla as
connect  identifier  is  torcla . mycompany
maintained  as  physical ;
Database  " torcla added

就这两步,broker的最基本配置就完成了,这下可以用show configuration来看成果了。

DGMGRL show  configuration
Configuration
  
Name :                 FSF
  
Enabled :              NO
  
Protection Mode :      MaxPerformance
  
Fast - Start  Failover DISABLED
  
Databases :
    
torclb  -  primary  database
    
torcla  -  Physical  standby  database
 
Current  status  for  " FSF " :
DISABLED
可以看到torclb是primary数据库,而torcla是physical standby数据库,不过这是的broker配置的状态是禁用的,说明我们的两个数据库是没有被broker管理的,只是加入到了broker配置中了而已,接下来启用一下。
DGMGRL enable  configuration
Enabled .
DGMGRL show  configuration
Configuration
  
Name :                 FSF
  
Enabled :              YES
  
Protection Mode :      MaxPerformance
  
Fast - Start  Failover DISABLED
  
Databases :
    
torclb  -  primary  database
    
torcla  -  Physical  standby  database
 
Current  status  for  " FSF " :
SUCCESS

这样就成了,一个成功的broker配置完成,挺简单的。

最后我们做一个switchover来检验下成果吧,具体的switchover的过程在后面再介绍。

DGMGRL switchover  to  torcla
Performing  switchover  NOW please  wait ...
Operation  requires  shutdown  of  instance  " torclb on  database  " torclb "
Shutting  down  instance  " torclb " ...
ORA - 01109 database  not  open
 
Database  dismounted .
ORACLE  instance  shut down .
Operation  requires  shutdown  of  instance  " torcla on  database  " torcla "
Shutting  down  instance  " torcla " ...
ORA - 01109 database  not  open
 
Database  dismounted .
ORACLE  instance  shut down .
Operation  requires  startup  of  instance  " torclb on  database  " torclb "
Starting  instance  " torclb " ...
ORACLE  instance  started .
Database  mounted .
Operation  requires  startup  of  instance  " torcla on  database  " torcla "
Starting  instance  " torcla " ...
ORACLE  instance  started .
Database  mounted .
Switchover  succeeded new  primary  is  " torcla "
DGMGRL show  configuration
 
Configuration
  
Name :                 FSF
  
Enabled :              YES
  
Protection Mode :      MaxPerformance
  
Fast - Start  Failover DISABLED
  
Databases :
    
torclb  -  Physical  standby  database
    
torcla  -  Primary  database
 
Current  status  for  " FSF " :
SUCCESS
我们已经成功的将primary数据库却换成了torcla,用一个简单的命令,这个就是broker的优势所在,简单!

参考至:http://www.dbabeta.com/2009/learn-data-guard-broker_a-broker-example.html

如有错误,欢迎指正

邮箱:czmcj@163.com

作者:czmmiao  文章出处:http://czmmiao.iteye.com/blog/2124742
相关文章
|
7月前
|
数据库
SAP ABAP 系统进行 client 拷贝时遇到的 63999 table too wide during client copy 错误消息
SAP ABAP 系统进行 client 拷贝时遇到的 63999 table too wide during client copy 错误消息
49 0
|
Oracle 关系型数据库 Linux
12c Data Guard Broker 配置
12c Data Guard Broker 配置,18c Data Guard Broker 配置
1822 0
|
Oracle 关系型数据库 数据库