1.环境
DB:Oracle RAC 19.3 x64
OS:Centos 7.8
DB_NAME:ora193
SID:ora1931,ora1932
pdb:pdb1
scanip:192.168.188.115
2.实现步骤
1)创建服务
[oracle@ora19c1~]$ srvctl add service -d ora193 -s s_pdb1 -r ora1931,ora1932 -P basic -e select -m basic -z 180 -w 5 -pdb pdb1
--注:
1)-d,-db:指定服务针对的数据库名。
2)-s,-service:指定要创建服务的名字。
3)-r,-preferred:指定创建服务的偏向实例名。
4)-P,-tafpolicy:指定创建服务的TAF策略。
5)-e,-failovertype:指定创建服务的失败切换类型。
6)-m,-failovermethod:指定创建服务的失败切换方法。
7)-z,-failoverretry:指定创建服务的失败切换重试次数。
8)-w,-failoverdelay:指定创建服务的失败切换重试时间间隔,单位为秒。
9)-pdb pdb1:指定创建服务针对的插件数据库的名字。
2)查看服务
[oracle@ora19c1~]$ srvctl config service -d ora193 -s s_pdb1
Service name: s_pdb1
Server pool:
Cardinality: 2
Service role: PRIMARY
Management policy: AUTOMATIC
DTP transaction: false
AQ HA notifications: false
Global: false
Commit Outcome: false
Failover type: SELECT
Failover method: BASIC
Failover retries: 180
Failover delay: 5
Failover restore: NONE
Connection Load Balancing Goal: LONG
Runtime Load Balancing Goal: NONE
TAF policy specification: BASIC
Edition:
Pluggable database name: pdb1
Hub service:
Maximum lag time: ANY
SQL Translation Profile:
Retention: 86400 seconds
Replay Initiation Time: 300 seconds
Drain timeout:
Stop option:
Session State Consistency: DYNAMIC
GSM Flags: 0
Service is enabled
Preferred instances: ora1931,ora1932
Available instances:
CSS critical: no
3)启动服务
--注:
1)新创建的服务,默认不会开启。
[oracle@ora19c1~]$ srvctl status service -db ora193 -service s_pdb1
Service s_pdb1 is not running.
[oracle@ora19c1~]$ srvctl start service -db ora193 -service s_pdb1
[oracle@ora19c1~]$ srvctl status service -db ora193 -service s_pdb1
Service s_pdb1 is running on instance(s) ora1931,ora1932
4.看集群资源
[grid@rac19c2 ~]$ crsctl stat res -t
--------------------------------------------------------------------------------
Name Target State Server State details
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.LISTENER.lsnr
ONLINE ONLINE rac19c1 STABLE
ONLINE ONLINE rac19c2 STABLE
ora.chad
ONLINE ONLINE rac19c1 STABLE
ONLINE ONLINE rac19c2 STABLE
ora.net1.network
ONLINE ONLINE rac19c1 STABLE
ONLINE ONLINE rac19c2 STABLE
ora.ons
ONLINE ONLINE rac19c1 STABLE
ONLINE ONLINE rac19c2 STABLE
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.ASMNET1LSNR_ASM.lsnr(ora.asmgroup)
1 ONLINE ONLINE rac19c1 STABLE
2 ONLINE ONLINE rac19c2 STABLE
3 ONLINE OFFLINE STABLE
ora.CRS.dg(ora.asmgroup)
1 ONLINE ONLINE rac19c1 STABLE
2 ONLINE ONLINE rac19c2 STABLE
3 OFFLINE OFFLINE STABLE
ora.DATA.dg(ora.asmgroup)
1 ONLINE ONLINE rac19c1 STABLE
2 ONLINE ONLINE rac19c2 STABLE
3 OFFLINE OFFLINE STABLE
ora.FRA.dg(ora.asmgroup)
1 ONLINE ONLINE rac19c1 STABLE
2 ONLINE ONLINE rac19c2 STABLE
3 OFFLINE OFFLINE STABLE
ora.LISTENER_SCAN1.lsnr
1 ONLINE ONLINE rac19c1 STABLE
ora.asm(ora.asmgroup)
1 ONLINE ONLINE rac19c1 Started,STABLE
2 ONLINE ONLINE rac19c2 Started,STABLE
3 OFFLINE OFFLINE STABLE
ora.asmnet1.asmnetwork(ora.asmgroup)
1 ONLINE ONLINE rac19c1 STABLE
2 ONLINE ONLINE rac19c2 STABLE
3 OFFLINE OFFLINE STABLE
ora.cvu
1 ONLINE ONLINE rac19c1 STABLE
ora.ora193.db
1 ONLINE ONLINE rac19c1 Open,HOME=/u01/app/o
racle/product/19.3.0
/db_1,STABLE
2 ONLINE ONLINE rac19c2 Open,HOME=/u01/app/o
racle/product/19.3.0
/db_1,STABLE
ora.ora193.s_pdb1.svc
1 OFFLINE OFFLINE STABLE
2 OFFLINE OFFLINE STABLE
ora.qosmserver
1 ONLINE ONLINE rac19c1 STABLE
ora.rac19c1.vip
1 ONLINE ONLINE rac19c1 STABLE
ora.rac19c2.vip
1 ONLINE ONLINE rac19c2 STABLE
ora.scan1.vip
1 ONLINE ONLINE rac19c1 STABLE
--------------------------------------------------------------------------------
3.测试透明失败切换
1)客户端创建tnsname:scan_spdb1,向客户端tnsnames.ora文件中添加如下内容并保存。
193_spdb1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.188.115)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME =s_pdb1)
)
)
2)用新建的scan_spdb1连接数据库
d:\> sqlplus test/test@193_spdb1
SQL> set linesize 300
SQL> select * from v$instance;
INSTANCE_NUMBER INSTANCE_NAME HOST_NAME VERSION VERSION_LEGACY VERSION_FULL STARTUP_TIME STATUS PAR THREAD# ARCHIVE LOG_SWITCH_WAIT LOGINS SHU DATABASE_STATUS INSTANCE_ROLE ACTIVE_ST BLO CON_ID
--------------- ---------------- ---------------------------------------------------------------- ----------------- ----------------- ----------------- -------------- ------------ --- ---------- ------- --------------- ---------- --- ----------------- ------------------ --------- --- ----------
INSTANCE_MO EDITION FAMILY DATABASE_TYPE
----------- ------- -------------------------------------------------------------------------------- ---------------
1 ora1931 rac19c1 19.0.0.0.0 19.0.0.0.0 19.3.0.0.0 14-8月 -20 OPEN YES 1 STOPPED ALLOWED NO ACTIVE PRIMARY_INSTANCE NORMAL NO 0
REGULAR EE RAC
SQL> show parameter instance_name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
instance_name string ora1931
3)关闭当前连接实例ora1931
[grid@rac19c2 ~]$ srvctl stop instance -d ora193 -i ora1931 -f
4)再次查看前述客户端连接实例
SQL> /
INSTANCE_NUMBER INSTANCE_NAME HOST_NAME VERSION VERSION_LEGACY VERSION_FULL STARTUP_TIME STATUS PAR THREAD# ARCHIVE LOG_SWITCH_WAIT LOGINS SHU DATABASE_STATUS INSTANCE_ROLE ACTIVE_ST BLO CON_ID
--------------- ---------------- ---------------------------------------------------------------- ----------------- ----------------- ----------------- -------------- ------------ --- ---------- ------- --------------- ---------- --- ----------------- ------------------ --------- --- ----------
INSTANCE_MO EDITION FAMILY DATABASE_TYPE
----------- ------- -------------------------------------------------------------------------------- ---------------
2 ora1932 rac19c2 19.0.0.0.0 19.0.0.0.0 19.3.0.0.0 14-8月 -20 OPEN YES 2 STOPPED ALLOWED NO ACTIVE PRIMARY_INSTANCE NORMAL NO 0
REGULAR EE RAC
SQL> show parameter instance_name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
instance_name string ora1932
4)由上可知,客户端的连接实例已由原来的ora1931自动透明切换为ora1932