One .1 BLOG Document structure chart
One .2 Preface
One .2.1 Reading guide
Technology enthusiasts , After reading this article , You can master the following skills , You can also learn something else you don't know ,~O(∩_∩)O~:
① Data Guard Broker Configuration of
② Fast-Start Failover Configuration of
③ Oracle DataGuard Client of TAF To configure
④ Use DGMGRL To manage the database
⑤ Physics dg Management and maintenance of some sql
⑥ DataGuard Client special configuration
Be careful : This article BLOG I use yellow background and red font to show the places that need special attention in the code part of , For example, in the following example ,thread 1 The maximum archive log number for is 33,thread 2 The maximum archive log number for is 43 It's something that needs special attention .
List of Archived Logs in backup set 11
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- ------------------- ---------- ---------
1 32 1621589 2015-05-29 11:09:52 1625242 2015-05-29 11:15:48
1 33 1625242 2015-05-29 11:15:48 1625293 2015-05-29 11:15:58
2 42 1613951 2015-05-29 10:41:18 1625245 2015-05-29 11:15:49
2 43 1625245 2015-05-29 11:15:49 1625253 2015-05-29 11:15:53
If there are any mistakes or imperfections in this article, please correct them ,ITPUB Message or QQ All can , Your criticism is the biggest motivation of my writing .
One .2.2 Introduction to the experimental environment
project |
Main library |
dg library |
db type |
Single instance |
Single instance |
db version |
11.2.0.3 |
11.2.0.3 |
db Storage |
FS type |
FS type |
ORACLE_SID |
oradg11g |
oradgphy |
db_name |
oradg11g |
oradg11g |
host IP Address : |
192.168.59.130 |
192.168.59.130 |
OS Version and kernel edition |
RHEL6.5 64 position ,2.6.32-504.16.2.el6.x86_64 |
RHEL6.5 64 position ,2.6.32-504.16.2.el6.x86_64 |
OS hostname |
rhel6_lhr |
rhel6_lhr |
One .2.3 Links to related reference articles
dg A series of articles :
【DATAGUARD】 Establish physical backup and logical backup based on the same host ( One ): http://blog.itpub.net/26736162/viewspace-1448197/
【DATAGUARD】 Establish physical backup and logical backup based on the same host ( Two ): http://blog.itpub.net/26736162/viewspace-1448207/
【DATAGUARD】 Establish physical backup and logical backup based on the same host ( 3、 ... and ): http://blog.itpub.net/26736162/viewspace-1481972/
【DATAGUARD】 Establish physical backup and logical backup based on the same host ( Four )-- Add a physical dg node :http://blog.itpub.net/26736162/viewspace-1484878/
【DATAGUARD】 Physics dg Of switchover Switch ( 5、 ... and ) :http://blog.itpub.net/26736162/viewspace-1753111/
【DATAGUARD】 Physics dg Of failover Switch ( 6、 ... and ): http://blog.itpub.net/26736162/viewspace-1753130/
【DATAGUARD】 Physics dg Recovery in the case of lost archive files in the main library ( 7、 ... and ) : http://blog.itpub.net/26736162/viewspace-1780863/
【DATAGUARD】 Physics dg Configure client seamless switching ( 8、 ... and .1)--Data Guard Broker Configuration of :http://blog.itpub.net/26736162/viewspace-1811839/
【DATAGUARD】 Physics dg Configure client seamless switching ( 8、 ... and .2)--Fast-Start Failover Configuration of :http://blog.itpub.net/26736162/viewspace-1811936/
【DATAGUARD】 Physics dg Configure client seamless switching ( 8、 ... and .3)-- client TAF To configure :http://blog.itpub.net/26736162/viewspace-1811944/
【DATAGUARD】 Physics dg Configure client seamless switching ( 8、 ... and .4)--ora-16652 and ora-16603 error :http://blog.itpub.net/26736162/viewspace-1811947/
One .2.4 Brief introduction
This article blog Is based on cuug The content of the open class , I do the practical operation myself , Video can refer to :http://blog.itpub.net/26736162/viewspace-1624453/ , I won't write more about it , hold cuug The content is direct copy Come here , I think it's more useful .
This technology, if you don't know , It's not ORACLE master
This technology, if you don't know , You can't say that you will DataGuard
This technology, if you don't know ,......
This online course , When the primary and standby databases are switched , How to start a service, Ensure that the client connection can continue , And it can continue select Query operation , No matter which server the primary and secondary libraries are on ; At the same time to ensure that the new customer connection without any problems . There are not many examples on the Internet of this course , Mr. Chen spent nearly a year searching for human flesh , Just recently , I can't wait to share it with you .
1、DataGuard Configuration of ( Fast )
2、 establish service
3、 Create trigger
4、 Active / standby database switching test
Because there is so much , I'm going to divide it into 4 This is a chapter to share with you , Paste a picture , Don't strange , There is also a chapter on how to solve the problems in the experiment .
This is the second section ,Fast-Start Failover Configuration of .
One .3 Experimental part
One .3.1 The goal of the experiment
complete Oracle DataGuard Client of TAF To configure , And test seamless switching .
One .3.2 client TAF To configure
One .3.2.1 First, configure a TAF Of service
This service will send a notification to the client when the database fails , Allow query statements to continue running after a failover .
Run on the main library side :
14:51:45 SQL> begin
14:52:10 2 DBMS_SERVICE.CREATE_SERVICE(service_name => 'dg_taf_lhr',
14:52:10 3 network_name => 'dg_taf_lhr',
14:52:10 4 aq_ha_notifications => TRUE,
14:52:10 5 failover_method => 'BASIC',
14:52:10 6 failover_type => 'SELECT',
14:52:10 7 failover_retries => 30,
14:52:10 8 failover_delay => 5);
14:52:10 9 end;
14:52:10 10 /
PL/SQL Process completed successfully .
Elapsed time : 00: 00: 00.07
14:52:10 SQL>
One .3.2.2 Set up a stored procedure , Used to invoke service, Make sure to run only in the main library
We create a stored procedure to do this , If the current database is the master, it starts the service , If it's a standby library, stop .
Main library execution :
14:54:58 SQL> create or replace procedure dg_taf_proc_lhr is
14:59:46 2 v_role VARCHAR(30);
14:59:46 3 begin
14:59:46 4 select DATABASE_ROLE into v_role from V$DATABASE;
14:59:46 5 if v_role = 'PRIMARY' then
14:59:46 6 DBMS_SERVICE.START_SERVICE('dg_taf_lhr');
14:59:46 7 else
14:59:46 8 DBMS_SERVICE.STOP_SERVICE('dg_taf_lhr');
14:59:46 9 end if;
14:59:46 10 end;
14:59:46 11 /
Process created .
Elapsed time : 00: 00: 00.07
One .3.2.3 establish 1 A trigger to ensure that the service can run
Create two triggers , Let the database run this stored procedure during startup and role transition . Used as a database open when , No need to restart the database , If it's the main library, execute the stored procedure . When the database switches , If it's the main library, execute the stored procedure .
Main library execution :
14:59:47 SQL> create or replace TRIGGER dg_taf_trg_startup_lhr
14:59:53 2 after startup or db_role_change on database
14:59:53 3 begin
14:59:53 4 dg_taf_proc_lhr;
14:59:53 5 end;
14:59:53 6 /
Trigger created
Elapsed time : 00: 00: 00.26
14:59:54 SQL>
One .3.2.4 Start the newly created service
Execute the stored procedure on the main library ( Or restart the database , Execution is triggered when the database is started dg_taf_proc The trigger of ), Switch logs in the main database , Apply the changes to the standby Library
Main library execution :
14:59:54 SQL> exec dg_taf_proc_lhr ;
PL/SQL Process completed successfully .
Elapsed time : 00: 00: 00.01
15:06:57 SQL> alter system switch logfile;
The system has changed .
Elapsed time : 00: 00: 01.02
15:20:01 SQL>
[oracle@rhel6_lhr ~]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 29-9 month -2015 15:07:32
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.59.130)(PORT=1521)))
LISTENER Of STATUS
------------------------
Alias LISTENER
edition TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start date 29-9 month -2015 12:14:49
Normal operation time 0 God 2 Hours 52 branch 43 second
Tracking level off
Security ON: Local OS Authentication
SNMP OFF
Listener parameter file /u01/app/grid/11.2.0/network/admin/listener.ora
Listening endpoint profile ...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.59.130)(PORT=1521)))
Service summary ..
service "+ASM" contain 1 An example .
example "+ASM", state READY, The 1 A handler ...
service "PLSExtProc" contain 1 An example .
example "PLSExtProc", state UNKNOWN, The 1 A handler ...
service "dg_taf_lhr.lhr.com" contain 1 An example .
example "oradg11g", state READY, The 1 A handler ...
service "ora11g" contain 1 An example .
example "ora11g", state UNKNOWN, The 1 A handler ...
service "oradg11g" contain 1 An example .
example "oradg11g", state UNKNOWN, The 1 A handler ...
service "oradg11g.lhr.com" contain 2 An example .
example "oradg11g", state UNKNOWN, The 1 A handler ...
example "oradg11g", state READY, The 1 A handler ...
service "oradg11gXDB.lhr.com" contain 2 An example .
example "oradg11g", state READY, The 1 A handler ...
example "oradgphy", state READY, The 1 A handler ...
service "oradg11g_DGB.lhr.com" contain 1 An example .
example "oradg11g", state READY, The 1 A handler ...
service "oradg11g_DGMGRL.lhr.com" contain 1 An example .
example "oradg11g", state UNKNOWN, The 1 A handler ...
service "oradglg" contain 1 An example .
example "oradglg", state UNKNOWN, The 1 A handler ...
service "oradgphy" contain 1 An example .
example "oradgphy", state UNKNOWN, The 1 A handler ...
service "oradgphy.lhr.com" contain 2 An example .
example "oradgphy", state UNKNOWN, The 1 A handler ...
example "oradgphy", state READY, The 1 A handler ...
service "oradgphy_DGB.lhr.com" contain 1 An example .
example "oradgphy", state READY, The 1 A handler ...
service "oradgphy_DGMGRL.lhr.com" contain 1 An example .
example "oradgphy", state UNKNOWN, The 1 A handler ...
service "oradgss" contain 1 An example .
example "oradgss", state UNKNOWN, The 1 A handler ...
service "orclasm.lhr.com" contain 1 An example .
example "orclasm", state UNKNOWN, The 1 A handler ...
Command executed successfully
One .3.2.5 Query in the backup database , Confirm that the trigger and memory have been applied to the standby database
15:21:21 SQL> select trigger_name, trigger_name
15:22:09 2 from dba_triggers where trigger_name = 'DG_TAF_TRG_STARTUP_LHR';
TRIGGER_NAME TRIGGER_NAME
------------------------------ ------------------------------
DG_TAF_TRG_STARTUP_LHR DG_TAF_TRG_STARTUP_LHR
Elapsed time : 00: 00: 00.09
15:22:09 SQL>
15:24:28 SQL> select d.owner,d.OBJECT_NAME
15:24:54 2 from dba_procedures d
15:24:54 3 where d.OBJECT_NAME = 'DG_TAF_PROC_LHR';
OWNER OBJECT_NAME
------------------------------ ------------------------------
SYS DG_TAF_PROC_LHR
Elapsed time : 00: 00: 00.05
15:24:54 SQL>
One .3.2.6 client tnsnames To configure
dg_taf =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = tcp)(HOST = 192.168.59.130)(PORT = 1521))
(ADDRESS = (PROTOCOL = tcp)(HOST = 192.168.59.130)(PORT = 1521))
(LOAD_BALANCE = yes)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dg_taf_lhr.lhr.com)
(FAILOVER_MODE =
(TYPE = session)
(METHOD = basic)
(RETRIES = 180)
(DELAY = 5)
)
)
)
notes : my dg Because the environment is deployed on the same machine , therefore host equally , The production environment must be different .
One .3.3 Verify the client's TAF
Let's talk about the testing process first , First of all we have windows Environment tnsnames, then cmd Connect to dg Environmental Science , Execute a long query (select * from (select * from sys.dba_objects);), At this time in dgmgrl Medium manual shutdown abort Drop the main library , So connected cmd There will be a pause in the middle , wait for fast-start failover After switching , Then continue to return the result .
The active / standby switching does not affect the user's select operation , But if it is dml operation , Then all transactions are rolled back :
D:\Users\xiaomaimiao>sqlplus lhr/lhr@dg_taf
SQL*Plus: Release 11.2.0.1.0 Production on Tue Sep 29 15:37:20 2015
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> set line 9999
SQL> col name format a10
SQL> col FS_FAILOVER_OBSERVER_HOST format a20
SQL> col DB_UNIQUE_NAME format a15
SQL> select dbid,name, DB_UNIQUE_NAME,RESETLOGS_CHANGE#,current_scn,protection_mode,protection_level,database_role,force_logging,open_mode,switchover_status from v$database;
DBID NAME DB_UNIQUE_NAME RESETLOGS_CHANGE# CURRENT_SCN PROTECTION_MODE PROTECTION_LEVEL DATABASE_ROLE FOR OPEN_MODE SWITCHOVER_STATUS
---------- ---------- --------------- ----------------- ----------- -------------------- -------------------- ---------------- --- -------------------- --------------------
1403587593 ORADG11G oradg11g 2575356 2604578 MAXIMUM AVAILABILITY MAXIMUM AVAILABILITY PRIMARY YES READ WRITE TO STANDBY
SQL> SELECT d.DBID,
2 d.DB_UNIQUE_NAME,
3 d.FORCE_LOGGING,
4 d.FLASHBACK_ON,
5 DATAGUARD_BROKER,
6 d.FS_FAILOVER_STATUS,
7 d.FS_FAILOVER_CURRENT_TARGET,
8 d.FS_FAILOVER_THRESHOLD,
9 d.FS_FAILOVER_OBSERVER_PRESENT,
10 d.FS_FAILOVER_OBSERVER_HOST
11 FROM v$database d;
DBID DB_UNIQUE_NAME FOR FLASHBACK_ON DATAGUAR FS_FAILOVER_STATUS FS_FAILOVER_CURRENT_TARGET FS_FAILOVER_THRESHOLD FS_FAIL FS_FAILOVER_OBSERVER
---------- --------------- --- ------------------ -------- ---------------------- ------------------------------ --------------------- ------- --------------------
1403587593 oradg11g YES YES ENABLED SYNCHRONIZED oradgphy 30 YES rhel6_lhr
SQL>
You can see that it's connected to the main library .
Cmd Get stuck , wait for observer After switching cmd The interface continues to query :
15:44:42.75 2015 year 9 month 29 Japan Tuesday
Creating database "oradgphy" Start fast start failover ...
Fail over now , Please wait a moment ...
Fail over succeeded , The new main database is "oradgphy"
15:44:49.93 2015 year 9 month 29 Japan Tuesday
SQL> set line 9999
SQL> col name format a10
SQL> col FS_FAILOVER_OBSERVER_HOST format a20
SQL> col DB_UNIQUE_NAME format a15
SQL> select dbid,name, DB_UNIQUE_NAME,RESETLOGS_CHANGE#,current_scn,protection_mode,protection_level,database_role,force_logging,open_mode,switchover_status from v$database;
DBID NAME DB_UNIQUE_NAME RESETLOGS_CHANGE# CURRENT_SCN PROTECTION_MODE PROTECTION_LEVEL DATABASE_ROLE FOR OPEN_MODE SWITCHOVER_STATUS
---------- ---------- --------------- ----------------- ----------- -------------------- -------------------- ---------------- --- -------------------- --------------------
1403587593 ORADG11G oradgphy 2605058 2605468 MAXIMUM AVAILABILITY RESYNCHRONIZATION PRIMARY YES READ WRITE NOT ALLOWED
SQL> SELECT d.DBID,
2 d.DB_UNIQUE_NAME,
3 d.FORCE_LOGGING,
4 d.FLASHBACK_ON,
5 DATAGUARD_BROKER,
6 d.FS_FAILOVER_STATUS,
7 d.FS_FAILOVER_CURRENT_TARGET,
8 d.FS_FAILOVER_THRESHOLD,
9 d.FS_FAILOVER_OBSERVER_PRESENT,
10 d.FS_FAILOVER_OBSERVER_HOST
11 FROM v$database d;
DBID DB_UNIQUE_NAME FOR FLASHBACK_ON DATAGUAR FS_FAILOVER_STATUS FS_FAILOVER_CURRENT_TARGET FS_FAILOVER_THRESHOLD FS_FAIL FS_FAILOVER_OBSERVER
---------- --------------- --- ------------------ -------- ---------------------- ------------------------------ --------------------- ------- --------------------
1403587593 oradgphy YES YES ENABLED REINSTATE REQUIRED oradg11g 30 YES rhel6_lhr
SQL>
After switching , Stored procedure started on standby library TAF Of service , When the client reconnects , Automatically connected to the current main library ( The original library ).
@ thus , stay DG In the environment of client TAF Configuration is basically complete .
One .3.4 Digression :Java Configuration in
One .3.4.1 Use tnsnames To configure
Link to the original text :http://aijuans.iteye.com/blog/1488998
Format 1 : Oracle JDBC Thin using a ServiceName:
jdbc:oracle:thin:@//<host>:<port>/<service_name>
Example: jdbc:oracle:thin:@//192.168.2.1:1521/XE
Notice the format here ,@ In the back //, This is related to the use of SID The main difference .
This format is Oracle Recommended format , Because for clusters , For each node SID It's different , however SERVICE_NAME It does include all nodes .
Format two : Oracle JDBC Thin using an SID:
jdbc:oracle:thin:@<host>:<port>:<SID>
Example: jdbc:oracle:thin:192.168.2.1:1521:X01A
Note: Support for SID is being phased out. Oracle recommends that users switch over to usingservice names.
Format three :Oracle JDBC Thin using a TNSName:
jdbc:oracle:thin:@<TNSName>
Example: jdbc:oracle:thin:@GL
Note:
Support for TNSNames was added in the driver release 10.2.0.1
Two . test
2.1 preparation :
Oracle yes 11gR2
Listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = dave)
(ORACLE_HOME =D:\app\Administrator\product\11.2.0\dbhome_1)
(SID_NAME = NEWCCS)
)
)
Tnsnames.ora
DVD =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = dave)
)
)
2.3 Use service_name:dave
take 2.2 Chaste dbUrl Changed to the following :
String dbUrl = "jdbc:oracle:thin:@//127.0.0.1:1521/dave";
Output results :
MGMT_VIEW--97
ANQING--94
DVD--93
SYSMAN--95
If in 11g The following error was encountered in the :
test run Java class , Report errors :
java.sql.SQLException: The Network Adapter could not establish the connection
You can try to replace the corresponding jdbc connection driver, The description on the official website is as follows :
JDBC Thin Driver 11g Causes"Java.Sql.Sqlexception: Io Exception: The Network Adapter Could NotEstablish The Connection" While Connecting to Oracle Database 11g [ID947653.1]
Change the JDBC connection driver class inyour application server from:
oracle.jdbc.driver.OracleDriver
to
oracle.jdbc.OracleDriver
2.4 Use TNS name: dvd
String dbUrl = "jdbc:oracle:thin:@dvd";
An error is as follows :
java.sql.SQLException: Unknown host specified
The problem is that JVM No, oracle.net.tns_admin Of system property. The solution is 2 Kind of :
Method 1 : Start up VM Add the following parameters :
-Doracle.net.tns_admin=D:\app\Administrator\product\11.2.0\dbhome_1\NETWORK\ADMIN
Method 2 : stay java Add... To the code :
System.setProperty("oracle.net.tns_admin","D:\\app\\Administrator\\product\\11.2.0\\dbhome_1\\NETWORK\\ADMIN");
After adding , Can be normal in JDBC Use in tnsnama 了 .
Java Code
1. 2.2 test 1, Use SID:newccs
2.
3. [java] view plaincopy
4.
5. import java.sql.*;
6.
7. public class jdbc {
8. String dbUrl = "jdbc:oracle:thin:@127.0.0.1:1521:newccs";
9. String theUser = "dave";
10. String thePw = "dave";
11. Connection c = null;
12. Statement conn;
13. ResultSet rs = null;
14.
15. public jdbc() {
16. try {
17. Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
18. c = DriverManager.getConnection(dbUrl, theUser, thePw);
19. conn = c.createStatement();
20. } catch (Exception e) {
21. e.printStackTrace();
22. }
23. }
24.
25. public boolean executeUpdate(String sql) {
26. try {
27. conn.executeUpdate(sql);
28. return true;
29. } catch (SQLException e) {
30. e.printStackTrace();
31. return false;
32. }
33. }
34.
35. public ResultSet executeQuery(String sql) {
36. rs = null;
37. try {
38. rs = conn.executeQuery(sql);
39. } catch (SQLException e) {
40. e.printStackTrace();
41. }
42. return rs;
43. }
44.
45. public void close() {
46. try {
47. conn.close();
48. c.close();
49. } catch (Exception e) {
50. e.printStackTrace();
51. }
52. }
53.
54. public static void main(String[] args) {
55. ResultSet rs;
56. jdbc conn = new jdbc();
57. rs = conn.executeQuery("select * from dave where rownum<5");
58. try {
59. while (rs.next()) {
60. System.out.println(rs.getString("username")+"--"+rs.getString("user_id"));
61. }
62. } catch (Exception e) {
63. e.printStackTrace();
64. }
65. }
66. }
67.
68. --- Normal output :
69. MGMT_VIEW--97
70. ANQING--94
71. DVD--93
72. SYSMAN--95
One .3.4.2 Don't use tnsname
jdbc:oracle:thin:@
(description=
(ADDRESS_LIST =
(address=(protocol=tcp)(host=192.168.1.44)(port=1521))
(address=(protocol=tcp)(host=192.168.1.45)(port=1521))
(address=(protocol=tcp)(host=192.168.1.46)(port=1521))
(load_balance=yes)
)
(connect_data =
(service_name=ORACMS)
(failover_mode =
(type=session)
(method=basic)
(retries=5)
(delay=15)
)
)
)
-- Annotated TNS Connection string
jdbc:oracle:thin:@
(description=
(ADDRESS_LIST =
(address=(protocol=tcp)(host=192.168.1.44)(port=1521))
(address=(protocol=tcp)(host=192.168.1.45)(port=1521))
(address=(protocol=tcp)(host=192.168.1.46)(port=1521))
(load_balance=yes)// Indicates whether the load is balanced
)
(connect_data =
//(server = dedicated)// This parameter represents the dedicated server mode
(service_name=ORACMS)// The name of the service to operate the database
(failover_mode =// How to deal with the connection failure
(type=session)//TYPE =SESSION When an instance of a well connected session fails , The system will automatically switch the session to other available instances , The foreground application does not need to initiate a connection again , But what the session is doing SQL Need to be re executed .
(method=basic)// The initial connection is to connect a pin
(retries=5)// The number of times the connection was retried after the connection failed
(delay=15)// Delay time to try again after connection failure ( In seconds )
)
)
)
One .4 summary
This is the third section , Please check out section 4 : dgmgrl Common errors in maintenance .