物理DataGuard客戶端無縫切換--客戶端TAF 配置

panpong發表於2019-02-25

物理 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)

               )

        )

)

 


【參考】

【DATAGUARD】物理dg配置客戶端無縫切換 (八.3)--客戶端TAF 配置

http://blog.itpub.net/26736162/viewspace-1811944/

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/16976507/viewspace-2636976/,如需轉載,請註明出處,否則將追究法律責任。

相關文章