Oracle Linux Service

(0 comments)

Unix系统下可以通过service方式在开机时自动启动数据库。

启动数据库的dbstart命令会读取/etc/oratab文件,添加数据库实例的SID定义,并将重启标志设为 'Y'。

*:/opt/oracle/product/9.2.0:N
mydb:/opt/oracle/product/9.2.0:Y

Oracle 9.0.2.4版本的dbstart/dbshut命令中,定义的参数文件名称是错误的,修改如下:

#  PFILE=${ORACLE_HOME}/dbs/init${ORACLE_SID}.ora
  PFILE=${ORACLE_HOME}/dbs/spfile${ORACLE_SID}.ora

创建服务管理文件:/etc/init.d/dbora

#!/bin/sh
# chkconfig: - 20 80
# 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=/opt/oracle/product/9.2.0
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
         su - $ORA_OWNER -c $ORA_HOME/bin/dbstart &
         su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" &
    ;;
    '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 &
         su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" &
    ;;
esac

设置系统启动时自动启动数据库和实例,并设置相关权限。

chmod 750 /etc/init.d/dbora
ln -s /etc/init.d/dbora /etc/rc0.d/K10dbora
ln -s /etc/init.d/dbora /etc/rc6.d/K10dbora
chkconfig dbora on
usermod -G dba root
usermod -G oinstall root

关机时自动关闭数据库,编辑/etc/rc.d/init.d/halt文件,添加关闭数据库的指令。在# Kill all processes. 这段代码前添加:

# Shutdown Oralce Database
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=$ORACLE_BASE/product/9.2.0.4
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
echo "Shutdowning ORACLE 9.2.0.4:"
su - oracle -c "$ORACLE_HOME/bin/lsnrctl stop"
su - oracle -c "$ORACLE_HOME/bin/dbshut"
sleep 10
Currently unrated

Comments

There are currently no comments

New Comment

required

required (not published)

optional

required