Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3693239
  • 博文数量: 715
  • 博客积分: 1860
  • 博客等级: 上尉
  • 技术积分: 7745
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-07 08:51
个人简介

偶尔有空上来看看

文章分类

全部博文(715)

文章存档

2023年(75)

2022年(134)

2021年(238)

2020年(115)

2019年(11)

2018年(9)

2017年(9)

2016年(17)

2015年(7)

2014年(4)

2013年(1)

2012年(11)

2011年(27)

2010年(35)

2009年(11)

2008年(11)

分类: Oracle

2021-12-08 19:44:28


单机的主备库,如果没有集群软件,当主备切换后,客户端连接串往往需要修改,有条件的地方将IP设置为一个域名,例如 hrdb.huawei.com(仅是举例,如有雷同纯属巧合),然后切换DG,网络方面将这个域名指向备库IP(或F5分发到备库IP),客户端不用改动就可以继续访问数据库了。没有域名解析或F5怎么办?

用一个即将淘汰的技术 services_name,亲测oracle 19.9有效


  1. 创建一个服务:
  2. exec dbms_service.create_service(service_name=>'appservice',network_name=>'appservice')

  3. 连接串这样设置:
  4. ORCL =
  5.   (DESCRIPTION_LIST =
  6.        (FAILOVER = ON)
  7.        (LOAD_BALANCE = OFF)
  8.        (DESCRIPTION =
  9.          (ADDRESS_LIST =
  10.             (ADDRESS = (PROTOCOL = TCP)(HOST = bjdb)(PORT = 1521))
  11.         )
  12.        (CONNECT_DATA =
  13.             (SERVICE_NAME = appservice)
  14.         )
  15.     )
  16.        (DESCRIPTION =
  17.             (ADDRESS_LIST =
  18.             (ADDRESS = (PROTOCOL = TCP)(HOST = shdb)(PORT = 1521))
  19.           )
  20.          (CONNECT_DATA =
  21.             (SERVICE_NAME = appservice)
  22.          )
  23.        )
  24.   )
  25.   
  26. 主库创建触发器:
  27. CREATE OR REPLACE TRIGGER service_name_trg
  28.   AFTER DB_ROLE_CHANGE ON DATABASE
  29. DECLARE
  30.   role VARCHAR(30);
  31. BEGIN
  32.   SELECT DATABASE_ROLE INTO role FROM V$DATABASE;
  33.   IF role = 'PRIMARY' THEN
  34.     DBMS_SERVICE.START_SERVICE('appservice');
  35.   ELSE
  36.     DBMS_SERVICE.STOP_SERVICE('appservice');
  37.   END IF;
  38. END;
  39. /

  40. 重启主库

  41. 客户端测试
  42. sqlplus scott/tiger@orcl
  43. select host_name from v$instance; --连接到bjdb  北京
  44. 切换到备库
  45. sqlplus scott/tiger@orcl
  46. select host_name from v$instance; --连接到shdb  上海

  47. 透明,当然会话会中断,客户端需要能自动重新连接(tomcat连接池基本功能)。

官方推荐的技术 TAC



通过 srvctl 实现配置(开始找不同)

  1. --BASIC SERVICE
  2. srvctl add service -db mydb -service MYSERVICE
  3. –preferred inst1 -available inst2 -pdb mypdb -notification TRUE
  4. -drain_timeout 300 -stopoption IMMEDIATE -role PRIMARY

  5. --TAC
  6. $ srvctl add service -db mydb -service TACSERVICE
  7. -pdb mypdb –preferred inst1 -available inst2
  8. -failover_restore AUTO -commit_outcome TRUE
  9. -failovertype AUTO -replay_init_time 600
  10. -retention 86400 -notification TRUE
  11. -drain_timeout 300 -stopoption IMMEDIATE -role PRIMARY

  12. --AC
  13. $ srvctl add service -db mydb -service ACSERVICE
  14. -pdb mypdb -preferred inst1 -available inst2
  15. -failover_restore LEVEL1 -commit_outcome TRUE
  16. -failovertype TRANSACTION -session_state dynamic
  17. -replay_init_time 600 -retention 86400 -notification TRUE
  18. -drain_timeout 300 -stopoption IMMEDIATE -role PRIMARY
最好是RAC  ->  RAC的ADG,连接串例子
引自:bilibili.com/video/BV1AX4y1u7zm?spm_id_from=333.999.0.0

检查服务状态

  1. set pagesize 60
  2. set lines 120
  3. col Service_name format a30 trunc heading "Service"
  4. break on con_id skip1
  5. col Total_requests format 999,999,9999 heading "Requests"
  6. col Total_calls format 9,999,9999 heading "Calls in requests"
  7. col Total_protected format 9,999,9999 heading "Calls Protected"
  8. col Protected format 999.9 heading "Protected %"
  9. select con_id, service_name, total_requests,
  10. total_calls,total_protected,total_protected*100/NULLIF(total_calls,0) as
  11. Protected
  12. from(
  13. select * from
  14. (select a.con_id, a.service_name, c.name,b.value
  15. FROM gv$session a, gv$sesstat b, gv$statname c
  16. WHERE a.sid = b.sid
  17. AND a.inst_id = b.inst_id
  18. AND b.value != 0
  19. AND b.statistic# = c.statistic#
  20. AND b.inst_id = c.inst_id
  21. AND a.service_name not in ('SYS$USERS','SYS$BACKGROUND'))
  22. pivot(
  23. sum(value)
  24. for name in ('cumulative begin requests' as total_requests, 'cumulative end
  25. requests' as Total_end_requests, 'cumulative user calls in requests' as
  26. Total_calls, 'cumulative user calls protected by Application Continuity' as
  27. total_protected) ))
  28. order by con_id, service_name;


参考:oracle.com/goto/ac
阅读(1288) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~