单机的主备库,如果没有集群软件,当主备切换后,客户端连接串往往需要修改,有条件的地方将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
阅读(1288) | 评论(0) | 转发(0) |