单机的主备库,如果没有集群软件,当主备切换后,客户端连接串往往需要修改,有条件的地方将ip设置为一个域名,例如 hrdb.huawei.com(仅是举例,如有雷同纯属巧合),然后切换dg,网络方面将这个域名指向备库ip(或f5分发到备库ip),客户端不用改动就可以继续访问数据库了。没有域名解析或f5怎么办?
用一个即将淘汰的技术 services_name,亲测oracle 19.9有效
-
创建一个服务:
-
exec dbms_service.create_service(service_name=>'appservice',network_name=>'appservice')
-
-
连接串这样设置:
-
orcl =
-
(description_list =
-
(failover = on)
-
(load_balance = off)
-
(description =
-
(address_list =
-
(address = (protocol = tcp)(host = bjdb)(port = 1521))
-
)
-
(connect_data =
-
(service_name = appservice)
-
)
-
)
-
(description =
-
(address_list =
-
(address = (protocol = tcp)(host = shdb)(port = 1521))
-
)
-
(connect_data =
-
(service_name = appservice)
-
)
-
)
-
)
-
-
主库创建触发器:
-
create or replace trigger service_name_trg
-
after db_role_change on database
-
declare
-
role varchar(30);
-
begin
-
select database_role into role from v$database;
-
if role = 'primary' then
-
dbms_service.start_service('appservice');
-
else
-
dbms_service.stop_service('appservice');
-
end if;
-
end;
-
/
-
-
重启主库
-
-
客户端测试
-
sqlplus scott/tiger@orcl
-
select host_name from v$instance; --连接到bjdb 北京
-
切换到备库
-
sqlplus scott/tiger@orcl
-
select host_name from v$instance; --连接到shdb 上海
-
-
透明,当然会话会中断,客户端需要能自动重新连接(tomcat连接池基本功能)。
官方推荐的技术 tac
通过 srvctl 实现配置(开始找不同)
-
--basic service
-
srvctl add service -db mydb -service myservice
-
–preferred inst1 -available inst2 -pdb mypdb -notification true
-
-drain_timeout 300 -stopoption immediate -role primary
-
-
--tac
-
$ srvctl add service -db mydb -service tacservice
-
-pdb mypdb –preferred inst1 -available inst2
-
-failover_restore auto -commit_outcome true
-
-failovertype auto -replay_init_time 600
-
-retention 86400 -notification true
-
-drain_timeout 300 -stopoption immediate -role primary
-
-
--ac
-
$ srvctl add service -db mydb -service acservice
-
-pdb mypdb -preferred inst1 -available inst2
-
-failover_restore level1 -commit_outcome true
-
-failovertype transaction -session_state dynamic
-
-replay_init_time 600 -retention 86400 -notification true
-
-drain_timeout 300 -stopoption immediate -role primary
最好是rac -> rac的adg,连接串例子
引自:bilibili.com/video/bv1ax4y1u7zm?spm_id_from=333.999.0.0
检查服务状态
-
set pagesize 60
-
set lines 120
-
col service_name format a30 trunc heading "service"
-
break on con_id skip1
-
col total_requests format 999,999,9999 heading "requests"
-
col total_calls format 9,999,9999 heading "calls in requests"
-
col total_protected format 9,999,9999 heading "calls protected"
-
col protected format 999.9 heading "protected %"
-
select con_id, service_name, total_requests,
-
total_calls,total_protected,total_protected*100/nullif(total_calls,0) as
-
protected
-
from(
-
select * from
-
(select a.con_id, a.service_name, c.name,b.value
-
from gv$session a, gv$sesstat b, gv$statname c
-
where a.sid = b.sid
-
and a.inst_id = b.inst_id
-
and b.value != 0
-
and b.statistic# = c.statistic#
-
and b.inst_id = c.inst_id
-
and a.service_name not in ('sys$users','sys$background'))
-
pivot(
-
sum(value)
-
for name in ('cumulative begin requests' as total_requests, 'cumulative end
-
requests' as total_end_requests, 'cumulative user calls in requests' as
-
total_calls, 'cumulative user calls protected by application continuity' as
-
total_protected) ))
-
order by con_id, service_name;
参考:oracle.com/goto/ac
阅读(1053) | 评论(0) | 转发(0) |