Ilmar Kerm

Oracle, databases, Linux and maybe more

I’m currently involved in a project where we are replacing one company’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’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.
For more information on how I’ve used Oracle Grid Infrastructure to provide high availability for MySQL (or any other application), check out my page MySQL HA with Oracle Clusterware.

When I started testing this it was quite surprising that I didn’t find any Oracle Clusterware action script examples for Windows in Oracle documentation or even on google 🙂 Oracle documentation just refers that in Windows the action script has to be a batch script.

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 dbgp 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.
I named the action script: d:\scripts\dbgp.cmd

@echo off
@setlocal enableextensions enabledelayedexpansion
set action=%~1
set ORACLE_HOME=D:\app\oracle\product\10.2.0.5\db
set ORACLE_SID=dbgp
set TEMPFILE=d:\scripts\script.out
set CHECKSCRIPT=d:\scripts\check.sql
set OUTP=
set EXITCODE=0

if exist %TEMPFILE% (
  del %TEMPFILE%
)

if "%action%" == "start" goto :start
if "%action%" == "stop" goto :stop
if "%action%" == "check" goto :check
if "%action%" == "clean" goto :clean
goto :exit

:start
  %ORACLE_HOME%\bin\oradim -startup -sid %ORACLE_SID% -starttype srvc,inst > %TEMPFILE%
  call :setsize "%TEMPFILE%"
  if %size% gtr 0 call :checkoutput
  if exist %TEMPFILE% type %TEMPFILE%
  goto :exit

:stop
  %ORACLE_HOME%\bin\oradim -shutdown -sid %ORACLE_SID% -shuttype srvc,inst -shutmode immediate > %TEMPFILE%
  call :setsize "%TEMPFILE%"
  if %size% gtr 0 call :checkoutput
  if exist %TEMPFILE% type %TEMPFILE%
  goto :exit

:check
  %ORACLE_HOME%\bin\sqlplus /nolog @%CHECKSCRIPT% > %TEMPFILE%
  if %ERRORLEVEL% GTR 0 set EXITCODE=1
  goto :exit

:clean
  %ORACLE_HOME%\bin\oradim -shutdown -sid %ORACLE_SID% -shuttype srvc,inst -shutmode abort
  goto :exit

:setsize
  set size=%~z1
  goto :eof

:checkoutput
  set /p OUTP=<%TEMPFILE%
  if not "x%OUTP:DIM-=%" == "x%OUTP%" set EXITCODE=1
  if not "x%OUTP:ORA-=%" == "x%OUTP%" set EXITCODE=1
  goto :eof

:exit
  set OUTP=
  if exist sqlnet.log del sqlnet.log
  exit /b %EXITCODE%

Just for completeness, this script refers to d:\scripts\check.sql that is just used to run a quick database healt check, here is its contents:

whenever sqlerror exit failure
conn / as sysdba
select 1 from dual;
exit

WINDOWS SPECIFIC ONE TIME OPERATION: Before clusterware can execute the action script in Windows, you need to create OracleCRSToken_username 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.
Reference: Windows: How to Modify OS User Privileges for 11gR2 Grid Infrastructure and RAC Services (Needed for Backup To Network Shares) (Doc ID 1339053.1) steps 2 and 3.

set ORACLE_HOME=d:\app\11.2.0.4\grid
%ORACLE_HOME%\bin\crsuser add winrac1\oracle

.. it will show errors ..
.. but repeat the command on other node also ..

set ORACLE_HOME=d:\app\11.2.0.4\grid
%ORACLE_HOME%\bin\crsuser add winrac2\oracle

After that need to open services.msc and edit service OracleCRSToken_oracle. First set its startup type to Automatic and then on Log On As tab also set the oracle user password. After that start service OracleCRSToken_oracle and repeat these steps on all cluster nodes.

ADDING THE RESOURCE TO CLUSTERWARE: Adding the resource to cluster is the same as under Linux:

set ORACLE_HOME=d:\app\11.2.0.4\grid
%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"