Automatic Oracle Startup and Shutdown for Linux

 Automatic Oracle Startup and Shutdown for Linux

 

 

 

Step 1.  Login as root

Step 2.  vi /etc/oratab/

       #*:/home/oracle/ora01:N

ORCL:/home/oracle/ora01:Y      (NàY)

Step 3.  ls $ORACLE_HOME/dbs  #check initORACLE_SID.ora file

 (If there is not the file, you must copy it from $ORACLE_HOME/admin/oracle/pfile/

The file name maybe like initORACLE_SID.ora%, so when you copy it, you must rename it.)

Step 4.   cp $ORACLE_HOME/admin/oracle/pfile/ initORACLE_SID.ora%

         $ORACLE_HOME/dbs

Step 5.   mv initORACLE_SID.ora%  initORACLE_SID.ora

Step 6.  Vi $ORACLE_HOME/bin/dbstart|dbshut

      conn / as sysdba à conn sys/PWD as sysdba

(There is an error that I can not resolve it, so I change the dbstart and dbshut script

conn / as sysdba

ERROR: ORA-01031: insufficient privileges)

Step 7.  Create the following file as /etc/rc.d/init.d/oracle:

#!/bin/sh

#

# /etc/rc.d/init.d/oracle

# Description: Starts and stops the Oracle database and listeners

# See how we were called.

case "$1" in

  start)

        echo -n "Starting Oracle Databases: "

        echo "----------------------------------------------------" >> /var/log/oracle

        date +"! %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle

        echo "----------------------------------------------------" >> /var/log/oracle

        su - oracle -c dbstart >> /var/log/oracle

        echo "Done."

        echo -n "Starting Oracle Listeners: "

        su - oracle -c "lsnrctl start" >> /var/log/oracle

        echo "Done."

        echo ""

        echo "----------------------------------------------------" >> /var/log/oracle

        date +"! %T %a %D : Finished." >> /var/log/oracle

        echo "----------------------------------------------------" >> /var/log/oracle

        touch /var/lock/subsys/oracle

        ;;

  stop)

        echo -n "Shutting Down Oracle Listeners: "

        echo "----------------------------------------------------" >> /var/log/oracle

        date +"! %T %a %D : Shutting Down Oracle Databases as part of system down." >> /var/log/oracle

        echo "----------------------------------------------------" >> /var/log/oracle

        su - oracle -c "lsnrctl stop" >> /var/log/oracle

        echo "Done."

        rm -f /var/lock/subsys/oracle

        echo -n "Shutting Down Oracle Databases: "

        su - oracle -c dbshut >> /var/log/oracle

        echo "Done."

        echo ""

        echo "----------------------------------------------------" >> /var/log/oracle

        date +"! %T %a %D : Finished." >> /var/log/oracle

        echo "----------------------------------------------------" >> /var/log/oracle

        ;;

  restart)

        echo -n "Restarting Oracle Databases: "

        echo "----------------------------------------------------" >> /var/log/oracle

        date +"! %T %a %D : Restarting Oracle Databases as part of system up." >> /var/log/oracle

        echo "----------------------------------------------------" >> /var/log/oracle

        su - oracle -c dbstop >> /var/log/oracle

        su - oracle -c dbstart >> /var/log/oracle

        echo "Done."

        echo -n "Restarting Oracle Listeners: "

        su - oracle -c "lsnrctl stop" >> /var/log/oracle

        su - oracle -c "lsnrctl start" >> /var/log/oracle

        echo "Done."

        echo ""

        echo "----------------------------------------------------" >> /var/log/oracle

        date +"! %T %a %D : Finished." >> /var/log/oracle

        echo "----------------------------------------------------" >> /var/log/oracle

        touch /var/lock/subsys/oracle

        ;;

  *)

        echo "Usage: oracle {start|stop|restart}"

        exit 1

esac

Step 8.  The following commands will ensure that the databases will come up in runlevels 2,3 and 4:

 

$ ln -s ../init.d/oracle /etc/rc.d/rc2.d/S99oracle

$ ln -s ../init.d/oracle /etc/rc.d/rc3.d/S99oracle

$ ln -s ../init.d/oracle /etc/rc.d/rc4.d/S99oracle

 

To stop the databases on reboot or restart we need the following links:

 

$ ln -s ../init.d/oracle /etc/rc.d/rc0.d/K01oracle          # Halting

$ ln -s ../init.d/oracle /etc/rc.d/rc6.d/K01oracle          # Rebooting

 

 

Step 8.  su – oracle

 

 

        dbstart

 

 

(check whether it works)

 

Step 9.  reboot

 

你可能感兴趣的:(oracle,linux,shutdown,startup,automatic)