[DGMGRL]Dgmgrl管理Dataguard(1)

Dgmgrl表示Data Guard Manager Command Line Interface,用来管理维护Dataguard,而且该命令系统自带不需要额外安装,命令简单易上手,容易学习,比sqlplus用来更加简单一些.

一、初步认识Dgmgrl

[oracle@primary ~]$ 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> 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配置以及简单使用

--前提是已经安装Dataguard环境

1.开始配置参数

--主备库进行监听配置,增加如下红字内容

主库:

[oracle@primary ~]$ vim /u01/oracle/product/11.2.0/db_1/network/admin/listener.ora
# listener.ora Network Configuration File: /u01/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = primary)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

SID_LIST_LISTENER =
   (SID_LIST =
    (SID_DESC =
      (SDU=32767)
      (GLOBAL_DBNAME = orcl)
      (ORACLE_HOME = /u01/oracle/product/11.2.0/db_1)
      (SID_NAME = orcl)
      )
    (SID_DESC =
      (SDU=32767)
      (GLOBAL_DBNAME = orcl_DGMGRL)
      (ORACLE_HOME = /u01/oracle/product/11.2.0/db_1)
      (SID_NAME = orcl)
      )
   )

ADR_BASE_LISTENER = /u01/oracle

备库:

[oracle@standby dg]$ vim /u01/oracle/product/11.2.0/db_1/network/admin/listener.ora
# listener.ora Network Configuration File: /u01/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = standby)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

SID_LIST_LISTENER =
   (SID_LIST =
    (SID_DESC =
      (SDU=32767)
      (GLOBAL_DBNAME = dg)
      (ORACLE_HOME = /u01/oracle/product/11.2.0/db_1)
      (SID_NAME = dg)
      )
    (SID_DESC =
      (SDU=32767)
      (GLOBAL_DBNAME = dg_DGMGRL)
      (ORACLE_HOME = /u01/oracle/product/11.2.0/db_1)
      (SID_NAME = dg)
      )
   )


ADR_BASE_LISTENER = /u01/oracle

--添加完成后,重启监听


2.Dgmgrl添加主库

DGMGRL> create configuration orcl as primary database is "orcl" connect identifier is "orcl";
Error:
ORA-16525: the Data Guard broker is not yet available
ORA-06512: at "SYS.DBMS_DRS", line 157
ORA-06512: at line 1
--该错误原因是因为必须在主备库修改dg_broker_start才能执行

--语句含义:第一个orcl是配置的名称,这里可以随便填.PRIMARY DATABASE IS 'orcl' ,这儿的orcl是指database的db_unique_name,而connect identifier is ‘orcl′这里的orcl是指tnsname.ora连接到主库的net service name.


--在修改之前我们可以先看下主库监听和后台进程

监听状况:

[oracle@primary ~]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 14-JAN-2016 09:55:59

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Services Summary...
Service "orcl" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orcl_DGMGRL" has 1 instance(s).
  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully


--进程状态,没有dmon进程

[oracle@primary ~]$ ps -ef | grep dmon
oracle    7884  7849  0 09:58 pts/2    00:00:00 grep -i dmon

--发现2个文件不存在,并且dg_broker_start状态为FALSE

SQL> show parameter dg

NAME                     TYPE     VALUE
------------------------------------ ----------- ---------------------------------------------
dg_broker_config_file1             string     /u01/oracle/product/11.2.0/db_1/dbs/dr1orcl.dat
dg_broker_config_file2             string     /u01/oracle/product/11.2.0/db_1/dbs/dr2orcl.dat
dg_broker_start                    boolean    FALSE

[oracle@primary ~]$ ll /u01/oracle/product/11.2.0/db_1/dbs/dr*
ls: /u01/oracle/product/11.2.0/db_1/dbs/dr*: No such file or directory



3.修改dg_broker_start参数等于true,并查看相关变化(主备库都需要修改)

SQL> alter system set dg_broker_start=true scope=both;
System altered.


--后台进程可以发现,启动了一个dmon进程

[oracle@primary ~]$ ps -ef | grep dmon
oracle    6277     1  0 Jan13 ?        00:00:03 ora_dmon_orcl
oracle    7884  7849  0 09:58 pts/2    00:00:00 grep -i dmon


--继续Dgmgrl配置

DGMGRL> create configuration orcl as primary database is "orcl"connect identifier is "orcl";
Configuration "orcl" created with primary database "orcl"

--创建成功,再次看下监听状况,可以发现多出了一个服务,名字为orcl_DGB.

[oracle@primary ~]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 14-JAN-2016 09:55:59

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Services Summary...
Service "orcl" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orcl_DGB" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...

Service "orcl_DGMGRL" has 1 instance(s).
  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully


--系统中的2个文件此时也已经创建

[oracle@primary ~]$ ll /u01/oracle/product/11.2.0/db_1/dbs/dr*
-rw-r----- 1 oracle oinstall 20480 Jan 14 08:34 /u01/oracle/product/11.2.0/db_1/dbs/dr1orcl.dat
-rw-r----- 1 oracle oinstall 20480 Jan 14 07:16 /u01/oracle/product/11.2.0/db_1/dbs/dr2orcl.dat


4.增加Dataguard机器

DGMGRL> add database"dg" as connect identifier is "dg"  maintained asphysical;
Database "dg" added

--add database 'dg' ,这里的dg是指database的db_unique_name,而as connect identifier is dg这里的dg是指tnsname.ora连接到standby database的net service name.


5.启用配置

--执行报错,必须先enable configuration

DGMGRL> enable database orcl
Warning: ORA-16614: Data Guard broker configuration is disabled

DGMGRL> enable database dg;
Warning: ORA-16614: Data Guard broker configuration is disabled

--启动Configuration
DGMGRL> enable configuration
Enabled.
DGMGRL> show configuration

Configuration - orcl

  Protection Mode: MaxPerformance
  Databases:
    orcl - Primary database
    dg   - Physical standby database

Fast-Start Failover: DISABLED

Configuration Status:
SUCCESS


--再启动主备库,成功

DGMGRL> enable database orcl;
Enabled.
DGMGRL> enable database dg;
Enabled.

--执行下面命令后,如果在最后出现Database Status: SUCCESS表示启动成功

DGMGRL> show database verbose orcl
DGMGRL> show database verbose dg

6.检查配置,最后Database Status状态都必须是SUCCESS

DGMGRL> show database orcl

Database - orcl

  Role:            PRIMARY
  Intended State:  TRANSPORT-ON
  Instance(s):
    orcl

Database Status:
SUCCESS

DGMGRL> show database dg

Database - dg

  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:      0 Byte/s
  Real Time Query: ON
  Instance(s):
    dg

Database Status:
SUCCESS

DGMGRL> show configuration

Configuration - orcl

  Protection Mode: MaxPerformance
  Databases:
    orcl - Primary database
    dg   - Physical standby database

Fast-Start Failover: DISABLED

Configuration Status:
SUCCESS

DGMGRL> show configuration verbose

Configuration - orcl

  Protection Mode: MaxPerformance
  Databases:
    orcl - Primary database
    dg   - Physical standby database

  Properties:
    FastStartFailoverThreshold      = '30'
    OperationTimeout                = '30'
    FastStartFailoverLagLimit       = '30'
    CommunicationTimeout            = '180'
    ObserverReconnect               = '0'
    FastStartFailoverAutoReinstate  = 'TRUE'
    FastStartFailoverPmyShutdown    = 'TRUE'
    BystandersFollowRoleChange      = 'ALL'
    ObserverOverride                = 'FALSE'
    ExternalDestination1            = ''
    ExternalDestination2            = ''
    PrimaryLostWriteAction          = 'CONTINUE'

Fast-Start Failover: DISABLED

Configuration Status:
SUCCESS


7.总结

①.创建配置
create configuration orcl as primary database is "orcl" connectidentifier is "orcl";
②.添加备用库
add database "dg" as connect identifier is "dg" maintained as physical;
③.查看配置
show configuration
show configuration verbose
④.查看数据库或者实例
show database orcl
show database verbose orcl
show database dg
show database verbose dg

show instance orcl
show instance verbose orcl
show instance dg
show instance verbose dg

⑤.启用配置
enable configuration
enable database orcl
enable database dg

⑥.要启动dgmgrl要打开
alter system set dg_broker_start=true scope=both;
系统会启动一个进程ora_dmon_XXXX.并且会动态注册一个服务,命名为<oracle_sid>_DGB.<db_domain>

⑦.要建立两个dg_broker的配置文件。

SYS@orcl> show parameter dg

NAME                   TYPE     VALUE
----------------------- -----------------------------------------------------------------
dg_broker_config_file1  string   /u01/oracle/product/11.2.0/db_1/dbs/dr1orcl.dat
dg_broker_config_file2  string   /u01/oracle/product/11.2.0/db_1/dbs/dr2orcl.dat
dg_broker_start         boolean TRUE



参考博文:http://blog.itpub.net/267265/viewspace-1142649/

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页