參考:http://download.oracle.com/docs/pdf/B10812_02.pdf
Use the dbstart and dbshut scripts to automate database startup and shutdown.
Perform the following tasks to set up these scripts so that they are called at system
startup and shutdown. Perform these steps for every new database that you want to
configure for automated startup and shutdown:
1. Log in as the root user.
2. Edit the oratab file for your platform:
■ Solaris:
/var/opt/oracle/oratab
Note: The procedure described in this section applies to
single-instance databases only.
See Also: For more information about system startup and
shutdown procedures, see the init command in your UNIX
system documentation.
Automating Startup and Shutdown
Starting and Stopping Oracle Software 2-11
■ Other operating systems:
/etc/oratab
Database entries in the oratab file appear in the following format:
SID:ORACLE_HOME:{Y|N}
In this example, Y or N specifies whether you want the scripts to start up or
shut down the database. For each database that you want to start up and shut
down, find the instance identifier (SID) for that database, identified by the SID
in the first field, and change the last field for each to Y.
3. Change directory to one of the following directories, depending on your
platform:
4. Create a file called dbora with the following contents. Change the value
specified for the ORACLE_HOME environment variable to an Oracle home
directory for your installation, and change the value of the ORACLE
environment variable to the username of the owner of the database installed in
the Oracle home directory (typically oracle):
#! /bin/sh -x
#
# Change the value of ORACLE_HOME to specify the correct Oracle home
# directory for you installation
ORACLE_HOME=/u01/app/oracle/product/10.1.0/db_1
#
# change the value of ORACLE to the login name of the
# oracle owner at your site
#
ORACLE=oracle
PATH=${PATH}:$ORACLE_HOME/bin
HOST=`hostname`
Platform Initialization File Directory
AIX /etc
Linux and Solaris /etc/init.d
HP-UX and Tru64 UNIX /sbin/init.d
Automating Startup and Shutdown
2-12 Administrator’s Reference
PLATFORM=`uname`
export ORACLE_HOME PATH
#
if [ ! "$2" = "ORA_DB" ] ; then
if [ "$PLATFORM" = "HP-UX" ] ; then
remsh $HOST -l $ORACLE -n "$0 $1 ORA_DB"
exit
else
rsh $HOST -l $ORACLE $0 $1 ORA_DB
exit
fi
fi
#
LOG=$ORACLE_HOME/startup.log
touch $LOG
chmod a+r $LOG
#
case $1 in
'start')
echo "$0: starting up" >> $LOG
date >> $LOG
# Start Oracle Net
if [ -f $ORACLE_HOME/bin/tnslsnr ] ; then
echo "starting Oracle Net Listener"
$ORACLE_HOME/bin/lsnrctl start >> $LOG 2>&1 &
fi
echo "Starting Oracle databases"
$ORACLE_HOME/bin/dbstart >> $LOG 2>&1 &
;;
'stop')
echo "$0: shutting down" >> $LOG
date >> $LOG
# Stop Oracle Net
if [ -f $ORACLE_HOME/bin/tnslsnr ] ; then
echo "stopping Oracle Net Listener"
$ORACLE_HOME/bin/lsnrctl stop >> $LOG 2>&1 &
fi
echo "stopping Oracle databases"
$ORACLE_HOME/bin/dbshut >> $LOG 2>&1 &
;;
Automating Startup and Shutdown
Starting and Stopping Oracle Software 2-13
*)
echo "usage: $0 {start|stop}"
exit
;;
esac
#
exit
5. Change the group of the dbora file to the OSDBA group (typically dba) and set
the permissions to 750:
# chgrp dba dbora
# chmod 750 dbora
6. Create symbolic links to the dbora script in the appropriate run-level script
directories, as follows:
Note: This script works only if a password has not been set for the
Oracle Net listener. If a password has been set for the listener, this
script cannot stop the listener. Also, if the listener name is not the
default name LISTENER, you must specify the listener name in the
stop and start commands:
$ORACLE_HOME/bin/lsnrctl {start|stop} listener_name
Platform Symbolic Links Commands
AIX # ln -s /etc/dbora /etc/rc.d/rc2.d/S99dbora
# ln -s /etc/dbora /etc/rc.d/rc2.d/K01dbora
HP-UX # ln -s /sbin/init.d/dbora /sbin/rc3.d/S990dbora
# ln -s /sbin/init.d/dbora /sbin/rc3.d/K001dbora
Linux # ln -s /etc/init.d/dbora /etc/rc.d/rc3.d/K01dbora
# ln -s /etc/init.d/dbora /etc/rc.d/rc3.d/S99dbora
# ln -s /etc/init.d/dbora /etc/rc.d/rc5.d/K01dbora
# ln -s /etc/init.d/dbora /etc/rc.d/rc5.d/S99dbora
Solaris # ln -s /etc/init.d/dbora /etc/rc3.d/K01dbora
# ln -s /etc/init.d/dbora /etc/rc3.d/S99dbora
Tru64 UNIX # ln -s /sbin/init.d/dbora /sbin/rc3.d/S99dbora
# ln -s /sbin/init.d/dbora /sbin/rc3.d/K01dbora
Use the dbstart and dbshut scripts to automate database startup and shutdown.
Perform the following tasks to set up these scripts so that they are called at system
startup and shutdown. Perform these steps for every new database that you want to
configure for automated startup and shutdown:
1. Log in as the root user.
2. Edit the oratab file for your platform:
■ Solaris:
/var/opt/oracle/oratab
Note: The procedure described in this section applies to
single-instance databases only.
See Also: For more information about system startup and
shutdown procedures, see the init command in your UNIX
system documentation.
Automating Startup and Shutdown
Starting and Stopping Oracle Software 2-11
■ Other operating systems:
/etc/oratab
Database entries in the oratab file appear in the following format:
SID:ORACLE_HOME:{Y|N}
In this example, Y or N specifies whether you want the scripts to start up or
shut down the database. For each database that you want to start up and shut
down, find the instance identifier (SID) for that database, identified by the SID
in the first field, and change the last field for each to Y.
3. Change directory to one of the following directories, depending on your
platform:
4. Create a file called dbora with the following contents. Change the value
specified for the ORACLE_HOME environment variable to an Oracle home
directory for your installation, and change the value of the ORACLE
environment variable to the username of the owner of the database installed in
the Oracle home directory (typically oracle):
#! /bin/sh -x
#
# Change the value of ORACLE_HOME to specify the correct Oracle home
# directory for you installation
ORACLE_HOME=/u01/app/oracle/product/10.1.0/db_1
#
# change the value of ORACLE to the login name of the
# oracle owner at your site
#
ORACLE=oracle
PATH=${PATH}:$ORACLE_HOME/bin
HOST=`hostname`
Platform Initialization File Directory
AIX /etc
Linux and Solaris /etc/init.d
HP-UX and Tru64 UNIX /sbin/init.d
Automating Startup and Shutdown
2-12 Administrator’s Reference
PLATFORM=`uname`
export ORACLE_HOME PATH
#
if [ ! "$2" = "ORA_DB" ] ; then
if [ "$PLATFORM" = "HP-UX" ] ; then
remsh $HOST -l $ORACLE -n "$0 $1 ORA_DB"
exit
else
rsh $HOST -l $ORACLE $0 $1 ORA_DB
exit
fi
fi
#
LOG=$ORACLE_HOME/startup.log
touch $LOG
chmod a+r $LOG
#
case $1 in
'start')
echo "$0: starting up" >> $LOG
date >> $LOG
# Start Oracle Net
if [ -f $ORACLE_HOME/bin/tnslsnr ] ; then
echo "starting Oracle Net Listener"
$ORACLE_HOME/bin/lsnrctl start >> $LOG 2>&1 &
fi
echo "Starting Oracle databases"
$ORACLE_HOME/bin/dbstart >> $LOG 2>&1 &
;;
'stop')
echo "$0: shutting down" >> $LOG
date >> $LOG
# Stop Oracle Net
if [ -f $ORACLE_HOME/bin/tnslsnr ] ; then
echo "stopping Oracle Net Listener"
$ORACLE_HOME/bin/lsnrctl stop >> $LOG 2>&1 &
fi
echo "stopping Oracle databases"
$ORACLE_HOME/bin/dbshut >> $LOG 2>&1 &
;;
Automating Startup and Shutdown
Starting and Stopping Oracle Software 2-13
*)
echo "usage: $0 {start|stop}"
exit
;;
esac
#
exit
5. Change the group of the dbora file to the OSDBA group (typically dba) and set
the permissions to 750:
# chgrp dba dbora
# chmod 750 dbora
6. Create symbolic links to the dbora script in the appropriate run-level script
directories, as follows:
Note: This script works only if a password has not been set for the
Oracle Net listener. If a password has been set for the listener, this
script cannot stop the listener. Also, if the listener name is not the
default name LISTENER, you must specify the listener name in the
stop and start commands:
$ORACLE_HOME/bin/lsnrctl {start|stop} listener_name
Platform Symbolic Links Commands
AIX # ln -s /etc/dbora /etc/rc.d/rc2.d/S99dbora
# ln -s /etc/dbora /etc/rc.d/rc2.d/K01dbora
HP-UX # ln -s /sbin/init.d/dbora /sbin/rc3.d/S990dbora
# ln -s /sbin/init.d/dbora /sbin/rc3.d/K001dbora
Linux # ln -s /etc/init.d/dbora /etc/rc.d/rc3.d/K01dbora
# ln -s /etc/init.d/dbora /etc/rc.d/rc3.d/S99dbora
# ln -s /etc/init.d/dbora /etc/rc.d/rc5.d/K01dbora
# ln -s /etc/init.d/dbora /etc/rc.d/rc5.d/S99dbora
Solaris # ln -s /etc/init.d/dbora /etc/rc3.d/K01dbora
# ln -s /etc/init.d/dbora /etc/rc3.d/S99dbora
Tru64 UNIX # ln -s /sbin/init.d/dbora /sbin/rc3.d/S99dbora
# ln -s /sbin/init.d/dbora /sbin/rc3.d/K01dbora