Sunday, January 15, 2023

Client Connectivity in Data Guard Configuration | HA service

Client Connectivity in Data Guard Configuration





create database service on primary database server


exec DBMS_SERVICE.CREATE_SERVICE (service_name => 'ddb_ha', network_name => 'ddb_ha');



create or replace procedure start_db_ha_service

is

v_role VARCHAR(30);

begin

select DATABASE_ROLE into v_role from V$DATABASE;

if v_role = 'PRIMARY' then

DBMS_SERVICE.START_SERVICE('ddb_ha');

else

DBMS_SERVICE.STOP_SERVICE('ddb_ha');

end if;

end;

/





TRIGGER TO START SERVICE ON DB STARTUP:


create or replace TRIGGER db_hasrv_on_startup

after startup on database

begin

start_db_ha_service;

end;

/


TRIGGER TO START SERVICE ON DB ROLECHANGE:


create or replace TRIGGER db_hasrv_on_role_change

after db_role_change on database

begin

start_db_ha_service;

end;

/


Start the new service on primary


SQL> exec start_db_ha_service;

SQL> alter system archive log current;






SQL>

SQL>

SQL> exec DBMS_SERVICE.CREATE_SERVICE (service_name => 'ddb_ha', network_name => 'ddb_ha');


PL/SQL procedure successfully completed.


SQL> create or replace procedure start_db_ha_service

is

v_role VARCHAR(30);

begin

select DATABASE_ROLE into v_role from V$DATABASE;

if v_role = 'PRIMARY' then

DBMS_SERVICE.START_SERVICE('ddb_ha');

else

DBMS_SERVICE.STOP_SERVICE('ddb_ha');

end if;

end;

/  2    3    4    5    6    7    8    9   10   11   12


Procedure created.


SQL> create or replace TRIGGER db_hasrv_on_startup

after startup on database

begin

start_db_ha_service;

end;

/

  2    3    4    5    6

Trigger created.


SQL>

SQL> create or replace TRIGGER db_hasrv_on_role_change

after db_role_change on database

begin

start_db_ha_service;

end;

/  2    3    4    5    6


Trigger created.


SQL>

SQL>

SQL> exec start_db_ha_service;


PL/SQL procedure successfully completed.


SQL>

SQL> alter system archive log current;


System altered.


SQL> alter system archive log current;


System altered.


SQL> /


System altered.


SQL> /


System altered.


SQL>

SQL>



tnsnames.ora (client site)




DDB =

  (DESCRIPTION =

    (ADDRESS_LIST=

      (ADDRESS = (PROTOCOL = TCP)(HOST = 9.82.83.159)(PORT = 1521))

      (ADDRESS = (PROTOCOL = TCP)(HOST = 72.471.436.842)(PORT = 1521))

    )

   (CONNECT_DATA = (SERVICE_NAME = ddb_ha)

     (FAILOVER_MODE=(TYPE=SELECT)(METHOD=BASIC)(RETRIES=60)(DELAY=20))

   )

  )  

  

  

  

  

No comments:

Post a Comment

About the Author : Anurag Pandey | Database cloud Architect | Oracle | SQL Server | PostgreSQL | AI and Data Platform Enthusiast

Anurag Pandey is a Database Architect with expertise in Oracle, PostgreSQL, SQL Server, Linux, and enterprise database platforms and specializes in database architecture, performance tuning, high availability, disaster recovery, cloud modernization, and operational excellence. With extensive experience in enterprise-scale environments, Anurag is passionate about leveraging AI, automation, and modern data platforms to improve reliability, scalability, and business outcomes. He actively contributes to technical communities through knowledge sharing, architecture guidance, and thought leadership in database and data engineering domains.

Follow more articles at

Visit Blog

PostgreSQL Process Architecture Diagram and Details

PostgreSQL Process Architecture Diagram                            +------------------+                            |    POSTMASTER    |     ...