【前言】管理Oracle DataGuard的方式有三种:SQLPlus、OEM Grid Control、Broker;
先学习用SQLPlus进行切换,先了解其中的原理。
掌握了DataGuard的切换原理之后建议用Broker,因为这个工具会为你的Dataguard管理和切换带来很大的便利;
OEM Grid Control一般不建议使用,因为这个本身的配置也是一件非常麻烦的事情;
一、了解Data Guard Broker
【1】Data Guard Broker概述: Broker不是单独安装的功能,也不完全独立于Data Guard。它是标准Oracle数据库企业版安装的一部分,也是Data Guard的组成部分。Broker连接配置中的数据库,通过这个连接可以监控配置中数据库的健康状况。
【2】Broker的组成:主数据库上的Data Guard Monitor(DMON)中配置附加的所有数据库,所有的备库通过主库发出的命令进行变更;
二、创建和启用Broker
【1】环境说明:单机环境、数据库版本11.2.0.3、操作系统Centos
主库 | 备库 | |
Service | BEIJING | TIANJIN |
【2】准备工作
- 主库和备库都使用spfile
- 所有的数据库必须在mount(物理备库)或者open(主库和逻辑备库)状态
- 启用DG_BROKER_START
【3】操作步骤
3.1 启用dg_broker_start
SQL> show parameter dg_broker_start; NAME TYPE VALUE
SQL> !ps -ef|grep dmon SQL> alter system set dg_broker_start=TRUE scope=both; System altered.
SQL> show parameter dg_broker_start; NAME TYPE VALUE SQL> !ps -ef|grep dmon |
3.2 添加主库和备库
[oracle@db01 dbs]$ dgmgrl sys/oracle@BEIJING 连接到主库进行操作 Copyright (c) 2000, 2009, Oracle. All rights reserved. Welcome to DGMGRL, type "help" for information. Error: Configuration details cannot be determined by DGMGRL
添加主库 DGMGRL> create configuration JOEDG as primary database is beijing connect identifier is beijing;添加primary database的写法: DGMGRL> help create configuration Creates a broker configuration Syntax: CREATE CONFIGURATION <configuration name> AS configuration name:可以任意取名 database name:db_unique_name connect identifier:tnsnames文件配置的名称 DGMGRL> show database verbose BEIJING; Database - beijing Role: PRIMARY Properties: Database Status:
添加备库 DGMGRL> add database tianjin as connect identifier is tianjin maintained as physical; DGMGRL> help add database Adds a standby database to the broker configuration Syntax: ADD DATABASE <database name>
DGMGRL> show database verbose TIANJIN; Database - tianjin Role: PHYSICAL STANDBY Properties: Database Status:
DGMGRL> enable configuration; 启用以上配置 DGMGRL> show configuration; 查看当前配置 Configuration - joedg Protection Mode: MaxPerformance Fast-Start Failover: DISABLED Configuration Status: |
3.3 主从切换测试
[oracle@db01 trace]$ dgmgrl sys/oracle@BEIJING DGMGRL> switchover to tianjin; 切换的 Failed. Please complete the following steps to finish switchover: |
这时候主库已经是TIANJIN了,所以DGMGRL需要连接到TIANJIN
DGMGRL> show configuration; Configuration - joedg Protection Mode: MaxPerformance beijing - Physical standby database Fast-Start Failover: DISABLED Configuration Status: |
附切换时的主备库日志;
BEIJING的日志
Tue Dec 01 06:27:29 2015 |
TIANJIN数据库的日志
Error 12537 received logging on to the standby *********************************************************************** Fatal NI connect error 12514, connecting to: VERSION INFORMATION: |
3.4 启动BEIJING
SQL> startup mount; Total System Global Area 626327552 bytes SQL> ALTER DATABASE OPEN; Database altered. SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION; DGMGRL> show configuration; Configuration - joedg Protection Mode: MaxPerformance Fast-Start Failover: DISABLED Configuration Status: |
说明已经成功