Automating Oracle Database Startup and Shutdown on Linux
oracle
VM
[root@localhost /]# su - oracle
[oracle@localhost /]# echo $ORACLE_BASE
Check environment variable
-- /oracle
[oracle@localhost /]# echo $ORACLE_HOME
-- /oracle/db10g
[oracle@localhost /]# echo $ORACLE_SID
-- oracle sid
root
root
root
oracle
/etc/oratab
[root@localhost /]# vi /etc/oratab
Modify $ORACLE_SID:$ORACLE_HOME:Y|N in /etc/oratab
# oracle sid:/oracle/db10g:N
Change value from N to Y for the scripts to start or shut down the database
oracle sid:/oracle/db10g:Y
VM
[root@localhost /]# echo $PATH
Check if $ORACLE_HOME/bin exists in path
[root@localhost /]# PATH=$PATH:/oracle/db10g/bin
Add $ORACLE_HOME/bin to the path if it is not found
$ORACLE_HOME/bin/dbstart
[root@localhost /]# vi /oracle/db10g/bin/dbstart
ORACLE_HOME_LISTNER=$ORACLE_HOME
Modify the value of ORACLE_HOME_LISTNER in $ORACLE_HOME/bin/dbstart
[root@localhost /]# su - oracle
[oracle@localhost /]# dbstart
Test the database startup and shutdown scripts
[oracle@localhost /]# dbshut
root
/etc/init.d/dbora
[root@localhost /]# cd /etc/init.d
[root@localhost init.d]# vi dbora
Create a file dbora in /etc/init.d
#!/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=/oracle/db10g
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
# Remove "&" if you don't want startup as a background process.
# su $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME" &
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"
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut $ORA_HOME"
rm -f /var/lock/subsys/dbora
;;
esac
root
root
root
/etc/init.d/dbora
Change privileges and permissions of /etc/init.d/oracle
[root@localhost init.d]# chgrp dba dbora
[root@localhost init.d]# chmod 755 dbora
[root@localhost /]# chkconfig --add dbora
Registers the service at run-levels 3,4, and 5 as well as to auto start
[root@localhost /]# chkconfig --level 345 dbora on
Display whether a service is on or off for each run-level
[root@localhost /]# chkconfig --list | grep oracle
[root@localhost /]# service dbora start
[root@localhost /]# service dbora stop
Test the startup and shutdown services