且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

[20140415]使用dgmgrl管理dataguard(1)

更新时间:2022-09-09 14:14:09

[20140415]使用dgmgrl管理dataguard(1).txt

前一段时间在看Apress.Expert.Consolidation.in.Oracle.Database.12c.Nov.2013.pdf电子文档,发现使用dgmgrl可以很好的管理dataguard,
这好这篇电子文档讲解还比较详细,自己基本按照该文档的介绍,熟悉与学习dgmgrl的命令语法以及一些基本概念。

首先dgmgrl 表示 Data Guard Manager Line Mode,个人感觉使用dgmgrl管理dataguard,主要是简单方便,而且该命令系统自带,自成文档,
很容易学习,比起使用sqlplus来更加简单一些。

$ dgmgrl
DGMGRL for Linux: Version 11.2.0.3.0 - 64bit Production

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

Welcome to DGMGRL, type "help" for information.
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 " to see syntax for individual commands

DGMGRL> help create

Creates a broker configuration

Syntax:

  CREATE CONFIGURATION AS
    PRIMARY DATABASE IS
    CONNECT IDENTIFIER IS ;

--可以发现建立一个配置语法很简单。

--按照文档介绍,建立wallet,实际上这个步骤完全可以省掉。这样就是提示行不需输入口令,提高管理的安全性。
--我基本按照文档的介绍来安装wallet。

1.建立wallet:
$ mkdir -p tns_admin
$ cd tns_admin
$ orapki wallet create -wallet . -auto_login_local
or
$ mkstore -wrl . -create

--感觉这两个结果是一样的。建立两个文件。

$ ll
total 8
-rw-------  1 oracle11g oinstall 3589 2014-04-04 11:50:13 cwallet.sso
-rw-------  1 oracle11g oinstall 3512 2014-04-04 11:50:13 ewallet.p12

2.配置tnsnames.ora:
$ cat tnsnames.ora
TEST =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.XXX.40)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = test.com)
    )
  )
--测试通过!


3.将连接信息添加到客户端的wallet里:

$ mkstore -wrl /home/oracle11g/tns_admin -createCredential test sys XXXXX
Oracle Secret Store Tool : Version 11.2.0.3.0 - Production
Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.

Enter wallet password:
Create credential oracle.security.client.connect_string1

4、配置客户端的sqlnet.ora,添加如下内容:

WALLET_LOCATION =
  (SOURCE =
    (METHOD = FILE)
    (METHOD_DATA =
      (DIRECTORY = /home/oracle11g/tns_admin )
    )
  )

SQLNET.WALLET_OVERRIDE=true

5.测试看看是否成功:
$ sqlplus /@test as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Tue Apr 15 12:09:06 2014
Copyright (c) 1982, 2011, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SYS@test> show user
USER is "SYS"
SYS@test>

6.修改.bash_profile文件,加入如下别名:
alias dgmgrl='/usr/local/bin/rlwrap -s 9999 -r -i  -f /home/oracle11g/dgmgrl.txt dgmgrl /@test'
--这样可以很好使用上下方向键。

7.补充dgmgrl.txt的建立方法:
$  dgmgrl /@test | tee /tmp/dgmgrl.txt
help
help add         
help connect     
help convert     
help create      
help disable     
help edit        
help enable      
help exit        
help failover    
help help        
help quit        
help reinstate   
help rem         
help remove      
help show        
help shutdown    
help sql         
help start       
help startup     
help stop        
help switchover  

--然后quit,整理编辑/tmp/dgmgrl.txt文件生成/home/oracle11g/dgmgrl.txt文件就ok了。内容如下:

add apply as auto
condition configuration connect convert create
database destinations disable
edit enable exit
failover fast_start force
help
identifier immediate instance is
logical
maintained maxavailability maxperformance maxprotection mode mount
nomount normal
observer off on only open
pfile physical preserve primary property protection
quit
read reinstate rem remove rename restrict
set show shutdown snapshot sql standby start startup state stop switchover
to
verbose
with write