Tuesday 25 October 2011

Automatic Database Restart


To automate database startup and shutdown by using the dbstart and dbshut scripts:
  1. Log in as the root user.
  2. Edit the oratab file for the platform.
    To open the file, use one of the following commands:
    • On Solaris:
      # vi /var/opt/oracle/oratab
      
    • On AIX, HP-UX, and Linux:
      # vi /etc/oratab
      
    Database entries in the oratab file are displayed in the following format:
    SID:ORACLE_HOME:{Y|N|W}
    
    In this example, the values Y and N specify whether you want the scripts to start or shut down the database, respectively. For each database for which you want to automate shutdown and startup, first determine the instance identifier (SID) for that database, which is identified by the SID in the first field. Then, change the last field for each to Y.
    You can set dbstart to autostart a single-instance database that uses an Automatic Storage Management installation that is auto-started by Oracle Clusterware. This is the default behavior for an Automatic Storage Management cluster. If you want to do this, then you must change the oratab entry of the database and the Automatic Storage Management installation to use a third field with the value W and N, respectively. These values specify thatdbstart auto-starts the database only after the Automatic Storage Management instance is started.
    Note:
    If you add new database instances to the system and automate startup for them, then you must edit the entries for those instances in the oratab file.
  3. Change directory to one of the following depending on the operating system:
    PlatformInitialization File Directory
    AIX/etc
    Linux and Solaris/etc/init.d
    HP-UX/sbin/init.d
  4. Create a file called dbora, and copy the following lines into this file:
    Note:
    Change the value of the ORACLE_HOME environment variable to an Oracle home directory for the installation. Change the value of the ORACLE environment variable to the user name of the owner of the database installed in the Oracle home directory (typically, oracle).
    #! /bin/sh  -x
    #
    # Change the value of ORACLE_HOME to specify the correct Oracle home
    # directory for your installation.
    
    ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
    #
    # Change the value of ORACLE to the login name of the
    # oracle owner at your site.
    #
    ORACLE=oracle
    
    PATH=${PATH}:$ORACLE_HOME/bin
    HOST=`hostname`
    PLATFORM=`uname`
    export ORACLE_HOME PATH
    #
    if [ ! "$2" = "ORA_DB" ] ; then
       if [ "$PLATFORM" = "HP-UX" ] ; then
          remsh $HOST -l $ORACLE -n "$0 $1 ORA_DB"
          exit
       else
          rsh $HOST -l $ORACLE  $0 $1 ORA_DB
          if [ "$PLATFORM" = "Linux" ] ; then
              touch /var/lock/subsys/dbora
          fi
          exit
       fi
    fi
    #
    case $1 in
    'start')
            $ORACLE_HOME/bin/dbstart $ORACLE_HOME &
            ;;
    'stop')
            $ORACLE_HOME/bin/dbshut $ORACLE_HOME &
            ;;
    *)
            echo "usage: $0 {start|stop}"
            exit
            ;;
    esac
    #
    exit
    
    
    
    
    
    ####################### Or Use Below Script ##########################
    #!/bin/sh
    # chkconfig: 345 99 10
    # description: Oracle auto start-stop script.
    #
    # Set ORA_HOME to be equivalent to the $ORACLE_HOME
    # from which you wish to execute dbstart and dbshut;
    #
    # Set ORA_OWNER to the user id of the owner of the 
    # Oracle database in ORA_HOME.
    
    ORA_HOME=/u01/app/oracle/product/10.2.0/db_1
    #ORA_HOME=/u01/app/oracle/product/11.1.0/db_1
    #ORA_HOME=/u01/app/oracle/product/11.2.0/db_1
    ORA_OWNER=oracle
    
    if [ ! -f $ORA_HOME/bin/dbstart ]
    then
        echo "Oracle startup: cannot start"
        exit
    fi
    
    case "$1" in
        'start')
            # Start the Oracle databases:
            # The following command assumes that the oracle login 
            # will not prompt the user for any values
            su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME"
            touch /var/lock/subsys/dbora
            ;;
        'stop')
            # Stop the Oracle databases:
            # The following command assumes that the oracle login 
            # will not prompt the user for any values
            su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut $ORA_HOME"
            rm -f /var/lock/subsys/dbora
            ;;
    esac
    Note:
    This script can only stop Oracle Net listener for which a password has not been set. In addition, if the listener name is not the default name, LISTENER, then you must specify the listener name in the stop and start commands:
    $ORACLE_HOME/bin/lsnrctl {start|stop} listener_name
    
  5. Change the group of the dbora file to the OSDBA group (typically dba), and set the permissions to 750:
    # chgrp dba dbora
    # chmod 750 dbora
    
  6. Create symbolic links to the dbora script in the appropriate run-level script directories as follows.
    PlatformSymbolic Links Commands
    AIX
    # ln -s /etc/dbora /etc/rc.d/rc2.d/S99dbora
    # ln -s /etc/dbora /etc/rc.d/rc0.d/K01dbora
    
    HP-UX
    # ln -s /sbin/init.d/dbora /sbin/rc3.d/S990dbora
    # ln -s /sbin/init.d/dbora /sbin/rc0.d/K001dbora
    
    Linux
    # ln -s /etc/init.d/dbora /etc/rc.d/rc0.d/K01dbora
    # ln -s /etc/init.d/dbora /etc/rc.d/rc3.d/S99dbora
    # ln -s /etc/init.d/dbora /etc/rc.d/rc5.d/S99dbora
    
    Solaris
    # ln -s /etc/init.d/dbora /etc/rc0.d/K01dbora
    # ln -s /etc/init.d/dbora /etc/rc3.d/S99dbora
    

    http://www.oracle-base.com/articles/linux/AutomatingDatabaseStartupAndShutdownOnLinux.php

No comments: