物理 DG 客户端无缝切换 -- 客户端 TAF 配置
项目客户一直想实现DataGuard的主备切换的自动化,即主库故障后自动切换到备库,并此过程要让应用感知。咨询了DG broker后,考虑到其可用性,易用性,和license问题,放弃了broker。但是物理备库切换到主库还是可以实现对应用透明的。之前我有篇歪门邪道的文章,通过linux系统的IP漂移设置,实现主备切换对应用的透明。对于oracle 11g的dataguard switchover,可以通过创建触发器方式实现自动切换。下面是主要操作步骤:
主库执行:
1. 创建 service
begin
DBMS_SERVICE.CREATE_SERVICE(service_name => 'dg_taf_pri',
network_name => 'dg_taf_pri',
aq_ha_notifications => TRUE,
failover_method => 'BASIC',
failover_type => 'SELECT',
failover_retries => 30,
failover_delay => 5);
end;
/
2. 创建存储过程,主库启动 service 监听
create or replace procedure dg_taf_proc is
v_role VARCHAR(30);
begin
select DATABASE_ROLE into v_role from V$DATABASE;
if v_role = 'PRIMARY' then
DBMS_SERVICE.START_SERVICE('dg_taf_pri');
else
DBMS_SERVICE.STOP_SERVICE('dg_taf_pri');
end if;
end;
/
select owner,object_name ,procedure_name from dba_procedures where procedure_name='dg_taf_proc'; --procedure_name 列出 package 中的 procedure 、 function
select owner,object_name ,procedure_name from dba_procedures where object_name='DG_TAF_PROC';
select distinct name,owner from dba_source where name like 'DG_TAF_PROC%';
3. 创建触发器,主备切换时触发
create or replace TRIGGER dg_taf_trg_startup
after startup or db_role_change on database
begin
dg_taf_proc;
end;
/
select trigger_name, trigger_name
from dba_triggers where trigger_name = 'DG_TAF_TRG_STARTUP';
4. 客户端配置:
dg_taf =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = tcp)(HOST = 12.12.12.123)(PORT = 1521))
(ADDRESS = (PROTOCOL = tcp)(HOST = 12.12.12.125)(PORT = 1521))
(LOAD_BALANCE = yes)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dg_taf_pri)
(FAILOVER_MODE =
(TYPE = session)
(METHOD = basic)
(RETRIES = 180)
(DELAY = 5)
)
)
)
【参考】
http://blog.itpub.net/26736162/viewspace-1811944/
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/16976507/viewspace-2636976/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/16976507/viewspace-2636976/