Humble Trader

Monday, January 02, 2006

Auto-start Oracle at Boot Time

Introduction:

This add Oracle Database Start to the boot sequence.

Aim:

To save us having to manually start Oracle when we reboot.

Requirements:

Orale is installed and at least one database has been built.

Procedure:

Set autostart in the oratab file:

  • Log in as oracle.
  • Open Terminal.
  • $ cd /etc
  • $ vi oratab
  • At the bottom of this file, there is a line for each created database reading something like; [SID]:[ORACLE_HOME]:N. Change the 'N' at the end of each line to 'Y'. e.g. change:
sta:/u01/app/oracle/10.2.0.1/db01:N
whs:/u01/app/oracle/10.2.0.1/db01:N
  • to:
sta:/u01/app/oracle/10.2.0.1/db01:Y
whs:/u01/app/oracle/10.2.0.1/db01:Y
  • Save and exit.
Fix the dbstart script:
  • $ cd $ORACLE_HOME/bin
  • $ vi dbstart
  • Find the line 'ORACLE_HOME_LISTNER=/ade/vikrkuma_new/oracle' - note that 'LISTENER is mis-spelled.
  • Change the path to the full Oracle Home path; '/u01/app/oracle/10.2.0.1/db01'
  • Save and exit.
Add Oracle to the boot sequence:
  • In a terminal:
    • $ su - root
    • Enter root's password.
  • # cd /etc/init.d
  • Create a new boot script:
    • # vi oracle10g
    • Put the following code into this script:
      • Best; download this (right-click the link and choose -Save Page As...-.
      • Or; cut and paste the following code:
#!/bin/sh
# chkconfig: 35 51 49
# 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/10.2.0.1/db01
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
echo
su - $ORA_OWNER -c $ORA_HOME/bin/dbstart
;;
'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
;;
'restart')
$0 stop
$0 start
echo
;;
*)
echo "usage: oracle10g {start | stop | restart}"
exit 1
;;
esac

exit 0
    • Save and exit.
  • Make the script executable:
    • # chmod 755 oracle10g
  • Test the script:
    • # ./oracle10g start
    • This will return with chora data if it installed and then a startup message for each available database:
Processing Database instance "sta": log file /u01/app/oracle/10.2.0.1/db01/start
up.log
Processing Database instance "whs": log file /u01/app/oracle/10.2.0.1/db01/start
up.log
    • # ./oracle10g restart
    • The instances restart.
    • # ./oracle10g stop
    • The instances are stopped.
  • Add the script to the boot sequence:
    • # chkconfig --add oracle10g
Testing:
  • Reboot the server and check the Oracle instances are auto-started.
    • Log in as oracle.
    • Open Terminal.
    • $ ps -ef | grep ora_pmon | grep -v grep
    • This should return with a process line for each running database:
oracle 2454 1 0 11:22 ? 00:00:00 ora_pmon_sta
oracle 2514 1 0 11:22 ? 00:00:00 ora_pmon_whs

0 Comments:

Post a Comment

<< Home