DGMGRL 是甲骨文公司开发一种管理小程序,方便于管理主备模式下多台备库,已经备库和主库之间的切换,灾难切换,主库恢复和自动检测。说白了类似于MYSQL的MHA软件。 只不过它不是单独的软件,而是ORACLE数据库的后台进程。并且主库和备库都有该进程!
有了它,你就不用敲太多的命令和检查下必要的环境。小仙有次主库挂了,启用备库拿出一些命令语句才完成。这里时间就浪费了很多! 如果有了DGMGRL,就一个命令就能完成,相对来说速度就快了很多,让业务中断时间更少。 如果应用端的TNS做了负载均衡和高可用的话,基本上主库挂了,后台DGMGRL把备库启用成主库,业务应用在间隔一段时间就开始转移到新主库操作。 说白了就是自动完成业务切换和业务恢复! 尤其是深夜,DBA就不用起床了!以下操作是搭建DGMGRL,假设你的主备已经搭建好,或者已经跑业务情况下:
一开启FLASH BACK功能
主库SQL>select name,flashback_on from v$database;
NAME FLASHBACK_ON
--------- ------------------
orcl NO
主库SQL>show parameter recovery
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest string /u01/ora_flash/orcl
db_recovery_file_dest_size big integer 4122M
主库SQL>alter database flashback on;
Database altered.
Elapsed: 00:00:01.60
--同时启动DGMGRL进程并扩大恢复期,其实这个是逻辑的,并非一开始就占了100GB的系统磁盘空间
主库SQL> alter system set db_recovery_file_dest_size=100G scope=both;
主库SQL> alter system set dg_broker_start=true scope=both;
备库部分
--取消恢复:
备库SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
备库SQL> alter system set db_recovery_file_dest_size=100G scope=both;
备库SQL>alter database flashback on;
--即时应用当前日志: 同时启动DGMGRL进程
备库SQL> alter database recover managed standby database using current logfile disconnect;
备库SQL> alter system set dg_broker_start=true scope=both;
二 修改主备的DG参数 使其成为最大可用模式
--主库LINUX系统中
[oracle@dbmater ~]dgmgrl
DGMGRL for Linux: Version 11.2.0.4.0 - 64bit Production
Copyright (c) 2000, 2009, Oracle. All rights reserved.
Welcome to DGMGRL, type "help" for information.
--连接主库
DGMGRL> connect sys/oracle@orclms
Connected.
--调用帮助信息,英文与中文信息取决于系统环境
DGMGRL> help
The following commands are available:
add Adds a standby database to the broker configuration
connect Connects to an Oracle database instance
convert Converts a database from one type to another
create Creates a broker configuration
disable Disables a configuration, a database, or fast-start failover
edit Edits a configuration, database, or instance
enable Enables a configuration, a database, or fast-start failover
exit Exits the program
failover Changes a standby database to be the primary database
help Displays description and syntax for a command
quit Exits the program
reinstate Changes a database marked for reinstatement into a viable standby
rem Comment to be ignored by DGMGRL
remove Removes a configuration, database, or instance
show Displays information about a configuration, database, or instance
shutdown Shuts down a currently running Oracle database instance
sql Executes a SQL statement
start Starts the fast-start failover observer
startup Starts an Oracle database instance
stop Stops the fast-start failover observer
switchover Switches roles between a primary and standby database
Use "help <command>" to see syntax for individual commands
--可以直接查看某个命令的帮助信息
DGMGRL> help create
Creates a broker configuration
Syntax:
CREATE CONFIGURATION <configuration name> AS
PRIMARY DATABASE IS <database name>
CONNECT IDENTIFIER IS <connect identifier>;
--创建DGMGRL主库配置文件
DGMGRL> create configuration dg_broker_master as primary database is orclms connect identifier is orclms;
Configuration "dg_broker_master" created with primary database "orclms"
--显示配置文件内容
DGMGRL> show configuration;
Configuration - dg_broker_master
Protection Mode: MaxAvailability
Databases:
orclms - Primary database
Fast-Start Failover: DISABLED
Configuration Status:
DISABLED
--使配置文件有效
DGMGRL> enable configuration;
Enabled.
--加入备库
DGMGRL> add database orcldg as connect identifier is orcldg maintained as physical;
Database "orcldg" added
--这里的参数要说明一下.add database ‘dbsalve′ ,这儿的dbsalve是指database的db_unique_name,
而AS CONNECT IDENTIFIER IS dbsalve这里的dbsalve是指tnsname.ora连接到standby database的net service name.
DGMGRL> show configuration;
Configuration - dg_broker_master
Protection Mode: MaxAvailability
Databases:
orclms - Primary database
orcldg - Physical standby database (disabled)
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS
--有效备库
DGMGRL> enable database orcldg;
Enabled.
--显示主和备库所有属性信息
DGMGRL> show database verbose orclms;
Database - orclms
Role: PRIMARY
Intended State: TRANSPORT-ON
Instance(s):
orcl
Properties:
DGConnectIdentifier = 'orclms'
ObserverConnectIdentifier = ''
LogXptMode = 'SYNC'
DelayMins = '0'
Binding = 'optional'
MaxFailure = '0'
MaxConnections = '1'
ReopenSecs = '300'
NetTimeout = '30'
RedoCompression = 'DISABLE'
LogShipping = 'ON'
PreferredApplyInstance = ''
ApplyInstanceTimeout = '0'
ApplyParallel = 'AUTO'
StandbyFileManagement = 'AUTO'
ArchiveLagTarget = '0'
LogArchiveMaxProcesses = '4'
LogArchiveMinSucceedDest = '1'
DbFileNameConvert = ''
LogFileNameConvert = ''
FastStartFailoverTarget = ''
InconsistentProperties = '(monitor)'
InconsistentLogXptProps = '(monitor)'
SendQEntries = '(monitor)'
LogXptStatus = '(monitor)'
RecvQEntries = '(monitor)'
ApplyLagThreshold = '0'
TransportLagThreshold = '0'
TransportDisconnectedThreshold = '30'
SidName = 'orcl'
StaticConnectIdentifier = '(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=dbmater)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCLMS_DGMGRL)(INSTANCE_NAME=orcl)(SERVER=DEDICATED)))'
StandbyArchiveLocation = '/u01/ora_archive/orcl'
AlternateLocation = ''
LogArchiveTrace = '0'
LogArchiveFormat = '%t_%s_%r.dbf'
TopWaitEvents = '(monitor)'
Database Status:
SUCCESS
DGMGRL> show database verbose orcldg;
Database - orcldg
Role: PHYSICAL STANDBY
Intended State: APPLY-ON
Transport Lag: 0 seconds (computed 0 seconds ago)
Apply Lag: 0 seconds (computed 0 seconds ago)
Apply Rate: 155.00 KByte/s
Real Time Query: ON
Instance(s):
orcl
Properties:
DGConnectIdentifier = 'orcldg'
ObserverConnectIdentifier = ''
LogXptMode = 'SYNC'
DelayMins = '0'
Binding = 'OPTIONAL'
MaxFailure = '0'
MaxConnections = '1'
ReopenSecs = '300'
NetTimeout = '30'
RedoCompression = 'DISABLE'
LogShipping = 'ON'
PreferredApplyInstance = ''
ApplyInstanceTimeout = '0'
ApplyParallel = 'AUTO'
StandbyFileManagement = 'AUTO'
ArchiveLagTarget = '0'
LogArchiveMaxProcesses = '5'
LogArchiveMinSucceedDest = '1'
DbFileNameConvert = '/u02/ora_data/orcl, u02/ora_data/orcl'
LogFileNameConvert = '/u02/ora_data/orcl, u02/ora_redo/orcl'
FastStartFailoverTarget = ''
InconsistentProperties = '(monitor)'
InconsistentLogXptProps = '(monitor)'
SendQEntries = '(monitor)'
LogXptStatus = '(monitor)'
RecvQEntries = '(monitor)'
ApplyLagThreshold = '0'
TransportLagThreshold = '0'
TransportDisconnectedThreshold = '30'
SidName = 'orcl'
StaticConnectIdentifier = '(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=dbslave)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=orcldg_DGMGRL)(INSTANCE_NAME=orcl)(SERVER=DEDICATED)))'
StandbyArchiveLocation = '/u01/ora_archive/orcl'
AlternateLocation = ''
LogArchiveTrace = '0'
LogArchiveFormat = '%t_%s_%r.dbf'
TopWaitEvents = '(monitor)'
Database Status:
SUCCESS
--添加服务名
我们还需要修改监听listener.ora文件.我们必须添加一个静态注册的service_name为db_unique_name_DGMGRL.db_domain,这个service_name会在DGMGRL重启数据库的时候用到.通过DGMGRL重启数据库时DMON进程会先将数据库关闭,然后DGMGRL在通过静态监听中的service_name连接到数据库,发送启动的命令.如果不这么做的话,在做switch over的时候我们容易遇到TNS-12514错误
listener.ora:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = bjdb_DGMGRL)
(SERVICE_NAME = bjdb)
(SID_NAME = TestDB12)
(ORACLE_HOME = u01/app/oracle/product/11.2.0/dbhome_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
alter system set service_names='orcldg,orcldg_DGMGRL' scope=both;
alter system set service_names='orclms,orclms_DGMGRL' scope=both;
如何SWITCH? 如何FAILOVER? 如何自动FAILOVER 呢? 敬请期待下一篇





