Background information:
After the main library is switched switchover or failover, the client is able to obtain its own connection to the main library.
Environment modification:
1. Modify $oracle_home/network/admin/tnsnames.ora
priocm=
(DESCRIPTION =
(address_list=
(address = (PROTOCOL = TCP) (HOST = ocm1.example.com) (PORT = 1521)) --Main library
(address = (PROTOCOL = TCP) (HOST = ocm2.example.com) (PORT = 1521)) --Reserve
library
(connect_data =
(service_name = priocm) --Specify SERVICE name
)
2. Create and start a service in the main library
Begin
Dbms_service.create_service (' priocm ', ' priocm '); --service_name,network_name end
;
/
begin
Dbms_service. Start_service (' priocm ');
End;
/
3. Create a startup trigger in the main library and turn off the service when Database_role is a non-master library
Create or replace trigger Priocmtrigg after startup on database
declare
v_role varchar ();
Begin
Select Database_role into V_role from V$database;
If V_role = ' PRIMARY ' then
dbms_service. Start_service (' priocm ');
else
Dbms_service. Stop_service (' priocm ');
End If;
End;
/
4. Modify Servicefailover Parameters
Begin
Dbms_service.modify_service
(' priocm ',
failover_method => ' BASIC ',-- BASIC: Refers to creating a connection to another instance when a node failure is perceived. Preconnect: A connection that establishes all instances at the same time when a connection is initially established, and when a failure occurs, it is immediately possible to switch to another link
failover_type => ' select ', --session and select, These 2 methods are automatically rolled back for uncommitted transactions, which differ in the processing of the SELECT statement, where the SELECT statement that the user is executing is transferred to the new instance, the subsequent result set continues to return on the new node, and the returned recordset is discarded.
failover_retries =>- -Number of retries
failover_delay => 1); --Retry interval time end
;
/
Switch Experiment:
Simulate connecting through service (PRIOCM) on the client
[ORACLE@OCM1 admin]$ sqlplus sys/oracle@priocm as Sysdba sql*plus:release 11.2.0.3.0 Production on
Sun June 25 16:07:3 3 2017
Copyright (c) 1982, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition release 11.2.0.3.0-production with
the partitioning, OLAP, Data Mining and real application testing options
sys@priocm> Select Db_unique_name,name,database_role, Switchover_status from V$database; --Connect to the current main library
db_unique_name NAME database_role switchover_status
------------------------- --------------------------------------------------
aux PROD3 PRIMARY to STANDBY
------ ----------------------------------------------------------------------------------------------------------
Omit switchover process, http://blog.csdn.net/u013169075/article/details/73555409
--------------------------------- -------------------------------------------------------------------------------
Switchover once again simulates the connection through the service (PRIOCM) on the client
sys@priocm>/Select Db_unique_name,name,database_role,switchover_status from V$database * ERROR in line 1:ora-03113: End-of-file on communication channel--trying to manipulate the main library throw error Process id:4810 session id:28 Serial: Not connected to Oracle Sys@priocm> exit disconnected from Oracle Database 11g Enterprise Edition release 11.2.0.3.0 -Production with the partitioning, OLAP, Data Mining and real application testing options--try to connect to the main library [ORACLE@OCM1 ~]$ SQLPL US sys/oracle@priocm as Sysdba sql*plus:release 11.2.0.3.0 Production on Sun June 16:49:45 2017 Copyright (c) 1982, 2 011, Oracle.
All rights reserved. Connected to:oracle Database 11g Enterprise Edition release 11.2.0.3.0-production with the partitioning, OLAP, Data Min ing and real application testing options sys@priocm> Select Db_unique_name,name,database_role,switchover_status from V$database; --connected to the new main library db_unique_name NAME database_role switchover_status---------------------------------------------------------------------------PROD3 PROD3 PRIMARY FAILED Destination
reference materials:
Http://www.oracle.com/technetwork/cn/articles/database-performance/oracle-rac-connection-mgmt-1650424-zhs.html
https://uhesse.com/2009/08/19/connect-time-failover-transparent-application-failover-for-data-guard/