Automating Database Startup and Shutdown(开机启动和关闭oracle)
參考: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
人生有三宝:终身运动,终身学习,终身反醒.吸收新知,提高效率,懂得相处,成就自己,也成就他人,创造最高价值。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人