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  1  instance ( s ) .
Service  " torcla.mycompany "  has  1  instance ( s ) .
Service  " torcla_DGMGRL.mycompany "  has  1  instance ( s ) .
Service  " torcla_XPT.mycompany "  has  1  instance ( s ) .
Service  " torclb.mycompany "  has  1  instance ( s ) .
Service  " torclb_DGMGRL.mycompany "  has  1  instance ( s ) .
Service  " torclb_XPT.mycompany "  has  1  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  1  instance ( s ) .
Service  " torcla.mycompany "  has  1  instance ( s ) .
Service  " torcla_DGB.mycompany "  has  1  instance ( s ) .
Service  " torcla_DGMGRL.mycompany "  has  1  instance ( s ) .
Service  " torcla_XPT.mycompany "  has  1  instance ( s ) .
Service  " torclb.mycompany "  has  1  instance ( s ) .
Service  " torclb_DGB.mycompany "  has  1  instance ( s ) .
Service  " torclb_DGMGRL.mycompany "  has  1  instance ( s ) .
Service  " torclb_XPT.mycompany "  has  1  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
相关文章
|
存储 SQL Oracle
Oracle使用expdp/impdp实现全库导入导出的整体流程
Oracle的全库导入,首先一点必须先创建数据库,创建了数据库,才能往该数据库导入所有数据。相对来说,使用Oracle进行数据导入导出还很有些“麻烦”的,大多数资料上来就是......
15097 0
Oracle使用expdp/impdp实现全库导入导出的整体流程
|
11月前
|
Ubuntu 芯片 Windows
掌握timedatectl命令:Ubuntu 系统时间管理指南
掌握timedatectl命令:Ubuntu 系统时间管理指南
2579 121
|
11月前
|
Oracle 安全 关系型数据库
Oracle Linux 9.7 发布 - Oracle 提供支持 RHEL 兼容发行版
Oracle Linux 9.7 发布 - Oracle 提供支持 RHEL 兼容发行版
745 114
Oracle Linux 9.7 发布 - Oracle 提供支持 RHEL 兼容发行版
|
7月前
|
SQL 人工智能 运维
【Skills专题】polardbx-sql :一句话帮你设计8亿行单表的 PolarDB-X 分区方案
PolarDB-X Skills 是专为AI代码智能体打造的数据库技能库,聚焦分布式分区设计。将PolarDB-X内核知识封装成可调用Skill,支持自然语言输入,自动生成精准、可执行的分区方案与DDL,覆盖SQL编写、运维及开发全场景。 更多精彩内容可关注“PolarDB”公众号
|
Oracle 网络协议 关系型数据库
Oracle DataGuard主备切换之自动切换
Oracle DataGuard主备切换之自动切换
1066 2
|
Oracle 关系型数据库 Linux
Rocky Linux 9.6 正式版发布 - RHEL 100% 1:1 兼容免费发行版
Rocky Linux 9.6 正式版发布 - RHEL 100% 1:1 兼容免费发行版
1666 0
Rocky Linux 9.6 正式版发布 - RHEL 100% 1:1 兼容免费发行版
|
Oracle 关系型数据库 Linux
Linux 关闭透明大页(transparent_hugepage)和 NUMA
有些情况下需要关闭Linux 服务器的 透明大页和 NUMA,比如安装 Oracle 数据库!
Linux 关闭透明大页(transparent_hugepage)和 NUMA
|
监控 Oracle 关系型数据库
"深度剖析:Oracle SGA大小调整策略——从组件解析到动态优化,打造高效数据库性能"
【8月更文挑战第9天】在Oracle数据库性能优化中,系统全局区(SGA)的大小调整至关重要。SGA作为一组共享内存区域,直接影响数据库处理能力和响应速度。本文通过问答形式介绍SGA调整策略:包括SGA的组成(如数据缓冲区、共享池等),如何根据负载与物理内存确定初始大小,手动调整SGA的方法(如使用`ALTER SYSTEM`命令),以及利用自动内存管理(AMM)特性实现智能调整。调整过程中需注意监控与测试,确保稳定性和性能。
1640 2
|
数据采集 传感器 人工智能
|
应用服务中间件 Shell Linux
使用logrotate定期切割nginx日志
使用logrotate定期切割nginx日志
1474 0