Wednesday, December 12, 2012

Oracle 11g Auto Startup

Oracle 11g R2 Auto Startup on Linux 5.5

#########Create new File dbora in /etc/init.d/ file##########
cat >> /etc/init.d/dbora <<EOF
#!/bin/sh
# chkconfig: 345 99 10
# description: Oracle auto start-stop 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:
        # The following command assumes that the oracle login
        # will not prompt the user for any values
        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:
        # The following command assumes that the oracle login
        # will not prompt the user for any values
        su - $ORA_OWNER -c "/home/oracle/scripts/shutdown.sh >> /home/oracle/scripts/startup_shutdown.log 2>&1"
        rm -f /var/lock/subsys/dbora
        ;;
esac
EOF

########Change Permission ###############
chmod 750 /etc/init.d/dbora
############Set Run Level ##############
chkconfig --add dbora
#######Create Scripts Folder ############
mkdir -p /home/oracle/scripts
######Change Permission on Scripts Folder#
chown oracle.oinstall /home/oracle/scripts
#### Create Script for DB and Listener Startup ####
cat >> /home/oracle/scripts/startup.sh <<EOF
#!/bin/bash

export ORACLE_SID=DB11G
ORAENV_ASK=NO
. oraenv
ORAENV_ASK=YES

# Start Listener
lsnrctl start

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


cat >> /home/oracle/scripts/shutdown.sh <<EOF

#!/bin/bash

export ORACLE_SID=DB11G
ORAENV_ASK=NO
. oraenv
ORAENV_ASK=YES

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

# Stop Listener
lsnrctl stop
EOF


chmod u+x /home/oracle/scripts/startup.sh /home/oracle/scripts/shutdown.sh
chown oracle.oinstall /home/oracle/scripts/startup.sh /home/oracle/scripts/shutdown.sh
Now Restart your Server.
Best of Luck.

No comments:

Post a Comment