{"id":279,"date":"2016-01-14T22:51:21","date_gmt":"2016-01-14T21:51:21","guid":{"rendered":"https:\/\/ilmarkerm.eu\/blog\/?p=279"},"modified":"2017-11-13T18:22:52","modified_gmt":"2017-11-13T17:22:52","slug":"sample-code-oracle-grid-infrastructure-action-script-for-windows","status":"publish","type":"post","link":"https:\/\/ilmarkerm.eu\/blog\/2016\/01\/sample-code-oracle-grid-infrastructure-action-script-for-windows\/","title":{"rendered":"Sample code: Oracle Grid Infrastructure action script for Windows"},"content":{"rendered":"<p>I&#8217;m currently involved in a project where we are replacing one company&#8217;s entire hardware platform. They also have Oracle database 10.2.0.5 (that we cannot upgrade right now) and what is really unusual for me, is that this Oracle database runs under Windows (and we cannot migrate to another platform). We also decided to use Oracle Grid Infrastructure (aka Oracle Clusterware) 11.2.0.4 to implement active-passive standby server for this database. Why? Because Windows Cluster was not an option, we didn&#8217;t have RAC licenses, Oracle Clusterware is free (if you are protecting Oracle software or running on Oracle OS) and we have really good previous experience with it under Linux.<br \/>\nFor more information on how I&#8217;ve used Oracle Grid Infrastructure to provide high availability for MySQL (or any other application), check out my page <a href=\"\/blog\/mysql-high-availability-with-oracle-clusterware\/\">MySQL HA with Oracle Clusterware<\/a>.<\/p>\n<p>When I started testing this it was quite surprising that I didn&#8217;t find any Oracle Clusterware action script examples for Windows in Oracle documentation or even on google \ud83d\ude42 Oracle documentation just refers that in Windows the action script has to be a batch script.<\/p>\n<p>This is the example action script I came up with to manage stand alone Oracle 10.2.0.5 database. It uses oradim to start and stop the database instance <strong>dbgp<\/strong> and a small sqlplus script to check if the database instance is alive. Tested using Oracle Grid Infrastructure 11.2.0.4 under Windows 2008R2.<br \/>\nI named the action script: <strong>d:\\scripts\\dbgp.cmd<\/strong><\/p>\n<p><script src=\"https:\/\/gist.github.com\/ilmarkerm\/6a5995f7d23fb707562d18c10c397771.js\"><\/script><\/p>\n<p>Just for completeness, this script refers to <strong>d:\\scripts\\check.sql<\/strong> that is just used to run a quick database healt check, here is its contents:<\/p>\n<pre><code>whenever sqlerror exit failure\nconn \/ as sysdba\nselect 1 from dual;\nexit\n<\/code><\/pre>\n<p><strong>WINDOWS SPECIFIC ONE TIME OPERATION:<\/strong> Before clusterware can execute the action script in Windows, you need to create <strong>OracleCRSToken_username<\/strong> service for the OS user who is executing the script. In my setup both Oracle Clusterware, managed database and the action script are executed by the local user WINRAC1\\oracle and on the second node as WINRAC2\\oracle. It is actually easier if you use domain user, please check the referred note.<br \/>\nReference: <strong>Windows: How to Modify OS User Privileges for 11gR2 Grid Infrastructure and RAC Services (Needed for Backup To Network Shares) (Doc ID 1339053.1)<\/strong> steps 2 and 3.<\/p>\n<pre><code>set ORACLE_HOME=d:\\app\\11.2.0.4\\grid\n%ORACLE_HOME%\\bin\\crsuser add winrac1\\oracle\n\n.. it will show errors ..\n.. but repeat the command on other node also ..\n\nset ORACLE_HOME=d:\\app\\11.2.0.4\\grid\n%ORACLE_HOME%\\bin\\crsuser add winrac2\\oracle\n<\/code><\/pre>\n<p>After that need to open <strong>services.msc<\/strong> and edit service <strong>OracleCRSToken_oracle<\/strong>. First set its startup type to <strong>Automatic<\/strong> and then on <strong>Log On As<\/strong> tab also set the <strong>oracle<\/strong> user password. After that start service <strong>OracleCRSToken_oracle<\/strong> and repeat these steps on all cluster nodes.<\/p>\n<p><strong>ADDING THE RESOURCE TO CLUSTERWARE:<\/strong> Adding the resource to cluster is the same as under Linux:<\/p>\n<pre><code>set ORACLE_HOME=d:\\app\\11.2.0.4\\grid\n%ORACLE_HOME%\\bin\\crsctl add resource oradb_dbgp -type cluster_resource -attr \"ACTION_SCRIPT=d:\\scripts\\dbgp.cmd, CHECK_INTERVAL=60, RESTART_ATTEMPTS=2, PLACEMENT=favored, HOSTING_MEMBERS=winrac1\"\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m currently involved in a project where we are replacing one company&#8217;s entire hardware platform. They also have Oracle database 10.2.0.5 (that we cannot upgrade right now) and what is really unusual for me, is that this Oracle database runs under Windows (and we cannot migrate to another platform). We also decided to use Oracle [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[17,4,45],"class_list":["post-279","post","type-post","status-publish","format-standard","hentry","category-blog-entry","tag-cluster","tag-oracle","tag-windows"],"_links":{"self":[{"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/posts\/279","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/comments?post=279"}],"version-history":[{"count":8,"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/posts\/279\/revisions"}],"predecessor-version":[{"id":399,"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/posts\/279\/revisions\/399"}],"wp:attachment":[{"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/media?parent=279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/categories?post=279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/tags?post=279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}