{"id":1127,"date":"2011-04-08T14:50:26","date_gmt":"2011-04-08T19:50:26","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=1127"},"modified":"2011-07-06T10:08:26","modified_gmt":"2011-07-06T15:08:26","slug":"automatically-switching-connections-over-with-dataguard-and-zero-code-changes","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2011\/04\/08\/automatically-switching-connections-over-with-dataguard-and-zero-code-changes\/","title":{"rendered":"Automatically switching connections over with Dataguard and zero code changes"},"content":{"rendered":"<p>In 10.2.0.4, I tested the ability of off the shelf code to automatically connect to a database that has been \u201cswitched over to\u201d.  A switchover is a graceful exchange of database responsibilities that prevents a split brain scenario where two databases are taking traffic at the same time.  In a switchover, dataguard guarantees, by design, that only one database can be the primary.<\/p>\n<p>My test consisted of:<\/p>\n<p>\u2022\tCluster database apptest \u2013 primary on server1<br \/>\n\u2022\tCluster database apptest \u2013 standby on server2<\/p>\n<p>I then ran a test that used an OracleDataSource and OracleConnectionCacheManager backed connection manager class that created ten connections to a URL that included both the primary and standby databases.  As mentioned, a standby database *cannot* take traffic, but the OracleDataSource handles all connection retrieval request exceptions \u201cgracefully&#8221;, with zero impact on the user.  The test inserted rows and printed out the status after each insert.<\/p>\n<p>After the test was running without issue for a minute or so, on the primary I issued an:<\/p>\n<pre lang=\"sql\">\r\nalter database commit to switchover to physical standby with session shutdown;\r\n<\/pre>\n<p>What this command does is, in order:<\/p>\n<p>1.\tPush all transactions to the standby that it does not yet possess<br \/>\n2.\tIssue a block and check the standby to ensure it has everything.<br \/>\n3.\tShuts itself down and changes its role to standby \u2013 At this point the application cannot get a connection for a brief period of time<\/p>\n<p>I then issued on the standby the following commands:<\/p>\n<pre lang=\"sql\">\r\nalter database commit to switchover to primary;\r\n!srvctl start service \u2013d apptest\r\n<\/pre>\n<p>As soon as the service came up when the last command above was issued, connections started coming in from my test.<\/p>\n<p>The following is what the user sees for a minute or so while the switchover occurs.<\/p>\n<pre lang=\"text\">\r\n08-APR-2011 14:48:54 * (CONNECT_DATA=(CID=(PROGRAM=JDBC Thin Client)(HOST=__jdbc__)(USER=root))(SERVICE_NAME=batch.home)) * (ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.100)(PORT=51052)) * establish * batch.home * 12514\r\nTNS-12514: TNS:listener does not currently know of service requested in connect descriptor\r\n08-APR-2011 14:48:54 * (CONNECT_DATA=(CID=(PROGRAM=JDBC Thin Client)(HOST=__jdbc__)(USER=root))(SERVICE_NAME=batch.home)) * (ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.100)(PORT=51051)) * establish * batch.home * 12514\r\nTNS-12514: TNS:listener does not currently know of service requested in connect descriptor\r\n\r\n\r\n08-APR-2011 14:48:54 * service_update * apptest1 * 0\r\n08-APR-2011 14:48:54 * service_update * apptest1 * 0\r\n\r\n\r\n08-APR-2011 14:48:54 * (CONNECT_DATA=(CID=(PROGRAM=JDBC Thin Client)(HOST=__jdbc__)(USER=root))(SERVICE_NAME=batch.home)) * (ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.100)(PORT=51055)) * establish * batch.home * 0\r\n08-APR-2011 14:48:54 * (CONNECT_DATA=(CID=(PROGRAM=JDBC Thin Client)(HOST=__jdbc__)(USER=root))(SERVICE_NAME=batch.home)) * (ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.100)(PORT=51056)) * establish * batch.home * 0\r\n<\/pre>\n<p>After the service was updated, you can see it begins to take connections in the last two entries of the window above.<\/p>\n<p>Switching back from the new primary to the old standby is just as easy.  The drawback to this is that you can\u2019t change the standby while it is in this mode.  <\/p>\n<p>As such, we couldn\u2019t have used this for tasks such as complete database upgrades, which change dictionary tables in the database.  However, for activities such as storage it is perfect.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In 10.2.0.4, I tested the ability of off the shelf code to automatically connect to a database that has been \u201cswitched over to\u201d. A switchover is a graceful exchange of database responsibilities that prevents a split brain scenario where two&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2011\/04\/08\/automatically-switching-connections-over-with-dataguard-and-zero-code-changes\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[19,22],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/1127"}],"collection":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/comments?post=1127"}],"version-history":[{"count":5,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/1127\/revisions"}],"predecessor-version":[{"id":1323,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/1127\/revisions\/1323"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1127"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}