Wednesday, December 12, 2012

Oracle Startup/Shutdown scripts

For Oracle 11gR2 you have the opportunity to use Oracle Restart, but to use it you must install Grid Infrastructure. If you don't want to use GI, you can use the scripts below:

vi /etc/init.d/dbora


#!/bin/sh
chkconfig: 345 99 10
# description: Oracle automatic startup/shutdown script.
#
# Set ORA_OWNER to the user id of the owner of the Oracle database software.

ORA_OWNER=oracle

case "$1" in
    'start')
        # Start the Oracle databases:
        su - $ORA_OWNER -c "/home/oracle/scripts/startup.sh >> /home/oracle/scripts/startup_shutdown.log 2>&1"
        touch /var/lock/subsys/dbora
        ;;
    'stop')
        # Stop the Oracle databases:
        su - $ORA_OWNER -c "/home/oracle/scripts/shutdown.sh >> /home/oracle/scripts/startup_shutdown.log 2>&1"
        rm -f /var/lock/subsys/dbora
        ;;
esac

chmod 750 dbora

vi /home/oracle/scripts/startup.sh

#!/bin/bash

export ORACLE_SID=DB11G
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export PATH=$PATH:$ORACLE_HOME/bin

# Start Listener
lsnrctl start

# Start Database
sqlplus / as sysdba << EOF
STARTUP;
EXIT;
EOF

chmod 755 startup.sh

vi /home/oracle/scripts/shutdown.sh

#!/bin/bash

export ORACLE_SID=sapcc
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export PATH=$PATH:$ORACLE_HOME/bin

# Start Listener
lsnrctl stop

# Start Database
sqlplus / as sysdba << EOF
SHUTDOWN IMMEDIATE;
EXIT;
EOF

chmod 755 shutdown.sh

Running scripts as root:

/etc/init.d/dbora stop
/etc/init.d/dbora start

Running as service:

chkconfig --add dbora
chkconfig --list dbora
dbora           0:off   1:off   2:off   3:on    4:on    5:on    6:off

service dbora stop
service dbora start