此功能实现在主down掉时,将备提升为住,实现业务不间断


前提条件:

主从数据库都要使用spfile:


数据同步的级别:
lgwr sync affirm

主从数据库都要运行在最高可用模式:
alter database set standby database to maximize availability;
select protection_mode,database_role,protection_level from v$database;

主从数据库都要有standby联机日志:
select * from v$standby_log;

从库要有standby日志的归档路径:
SQL> alter system set log_archive_dest_3='location=/home/oracle/aux1_stdlog VALID_FOR=(STANDBY_LOGFILES,STANDBY_ROLE) DB_UNIQUE_NAME=orcl'

主从数据库都要启动数据库的闪回功能:
select flashback_on from v$database;

如果显示为NO

关库然后执行

shutdown abort;

startup mount;

alter system set flash_back on;


环境检查完毕下面开始操作

1、主从数据库都要配置:

local_listener='连接自身的服务命名'

--on primary(130)
SQL> alter system set local_listener='to_130';

--on standby(140)
SQL> alter system set local_listener='to_140';


2、


查看归档终点是否有异常:

#col dest_name for a30

#col error for a20

#select dest_name,status,target,archiver,error,process from v$archive_dest;


3、-- on primary,standby

SQL> alter system set dg_broker_start=true;


4、-- on primary,standby

$ dgmgrl

DGMGRL> connect sys/oracle@to_130 (程序在哪启动都可,但要链接到主库)

创建中介配置:

DGMGRL> create configuration 'testBroker' as primary database is 'orcl'connect identifier is to_130

DGMGRL> SHOW DATABASE VERBOSE orcl

在中介配置中添加备用数据库:

DGMGRL> add database 'orcl2' as connect identifier is orcl2 maintained as physical;

查看broker配置状态:

DGMGRL> show configuration verbose;


启动broker配置:

DGMGRL> enable configuration

DGMGRL>  ENABLE FAST_START FAILOVER


修改快速故障转移的延迟时间(默认为30秒 ):

DGMGRL> edit configuration set property FastStartFailoverThreshold=120;


DGMGRL> show configuration


启动Observer监视器(on standby)

DGMGRL> start observer;

启动之后,该前台进程不会退出,会一直挂在这。 直到从其他窗口关闭!



在新的窗口再启动一个dgmgrl,查看快速转移配置:

DGMGRL> show configuration verbose;

DGMGRL> show database verbose orcl;

DGMGRL> show database verbose orcl2;


在数据库中查看快速转移状态:

-- on primary

SQL> col FS_FAILOVER_OBSERVER_HOST for a20

SQL> select fs_failover_observer_present,fs_failover_observer_host,fs_failover_threshold from v$database;

FS_FAIL FS_FAILOVER_OBSERVER FS_FAILOVER_THRESHOLD

------- -------------------- ---------------------

YES     alvin                                    0

-- on standby

SQL> col FS_FAILOVER_OBSERVER_HOST for a20

SQL> select fs_failover_observer_present,fs_failover_observer_host,fs_failover_threshold from v$database;

FS_FAIL FS_FAILOVER_OBSERVER FS_FAILOVER_THRESHOLD

------- -------------------- ---------------------

YES     alvin                                   30







--testing
 --on primary
  sql>shutdown abort;
 -- wait one minute
 --on old_standby change priary
DGMGRL> start observer;
Observer started
15:19:11.95  Monday, March 12, 2012
Initiating Fast-Start Failover to database "orcl"...
Performing failover NOW, please wait...
Failover succeeded, new primary is "orcl2"
15:19:18.67  Monday, March 12, 201



客户端配置网络,使其支持透明故障转移:

配置客户端TAF:

TAF=

(DESCRIPTION=

 (LOAD_BALANCE=on)

 (FAILOVER=on)

 (ADDRESS=(PROTOCOL=tcp) (HOST=10.10.10.130) (PORT=1521))

 (ADDRESS=(PROTOCOL=tcp) (HOST=10.10.10.140) (PORT=1521))

 (CONNECT_DATA=

    (SERVICE_NAME=orcl)

    (FAILOVER_MODE=

      (TYPE=select)

      (METHOD=basic))))