Next Previous Contents

6. 自动启动及停止

6.1 dbstartdbstop

Oracle 资料库的自动启动及停止可籍 Oracle 提供的 dbstartdbshut 档达成 (在 7.3.3.0.0 中)。这些文档又耍依靠 /etc/oratab 存在才能使用(虽然更改 dbshutdbstart 档可使解除这限制。)

/etc/oratab 档格式如下:


SID:ORACLE_HOME:AUTO

例如


orcl:/home/oracle/7.3.3.0.0:Y
leaveup:/home/oracle/7.3.2.1.0:N

6.2 init.drc.d

要在开机关机时自动启动和结朿资料库的话,你需要修改 Linux 的启动命令稿。这并不困难,不过,我需要指出这些改动因应不同的 Linux 发行版本(slackware, debian, redhat 等)而有所不同。我这些例子适用于 Redhat 5.0。要为你所用的 Linux 作出修改,请先参考你手头上的 Linux 文件。(虽然这实际上应该适用于所有 Sys V UNIX。)

首先,我们要建立会执行 /etc/rc.d/init.d 目录中 dbshutdbstart 的命令稿。把以下文档命名为 /etc/rc.d/init.d/oracle:


#!/bin/sh
#
# /etc/rc.d/init.d/oracle
# 解说︰启动及停止 Oracle 资料库和监听程序
# 检查如何执行命令稿
case "$1" in
  start)
        echo -n "Starting Oracle Databases: "
        echo "----------------------------------------------------" >> /var/log/oracle
        date +"! %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle
        echo "----------------------------------------------------" >> /var/log/oracle
        su - oracle -c dbstart >> /var/log/oracle
        echo "Done."
        echo -n "Starting Oracle Listeners: "
        su - oracle -c "lsnrctl start" >> /var/log/oracle
        echo "Done."
        echo ""
        echo "----------------------------------------------------" >> /var/log/oracle
        date +"! %T %a %D : Finished." >> /var/log/oracle
        echo "----------------------------------------------------" >> /var/log/oracle
        touch /var/lock/subsys/oracle
        ;;
  stop)
        echo -n "Shutting Down Oracle Listeners: "
        echo "----------------------------------------------------" >> /var/log/oracle
        date +"! %T %a %D : Shutting Down Oracle Databases as part of system down." >> /var/log/oracle
        echo "----------------------------------------------------" >> /var/log/oracle
        su - oracle -c "lsnrctl stop" >> /var/log/oracle
        echo "Done."
        rm -f /var/lock/subsys/oracle
        echo -n "Shutting Down Oracle Databases: "
        su - oracle -c dbshut >> /var/log/oracle
        echo "Done."
        echo ""
        echo "----------------------------------------------------" >> /var/log/oracle
        date +"! %T %a %D : Finished." >> /var/log/oracle
        echo "----------------------------------------------------" >> /var/log/oracle
        ;;
  restart)
        echo -n "Restarting Oracle Databases: "
        echo "----------------------------------------------------" >> /var/log/oracle
        date +"! %T %a %D : Restarting Oracle Databases as part of system up." >> /var/log/oracle
        echo "----------------------------------------------------" >> /var/log/oracle
        su - oracle -c dbstop >> /var/log/oracle
        su - oracle -c dbstart >> /var/log/oracle
        echo "Done."
        echo -n "Restarting Oracle Listeners: "
        su - oracle -c "lsnrctl stop" >> /var/log/oracle
        su - oracle -c "lsnrctl start" >> /var/log/oracle
        echo "Done."
        echo ""
        echo "----------------------------------------------------" >> /var/log/oracle
        date +"! %T %a %D : Finished." >> /var/log/oracle
        echo "----------------------------------------------------" >> /var/log/oracle
        touch /var/lock/subsys/oracle
        ;;
  *)
        echo "Usage: oracle {start|stop|restart}"
        exit 1
esac

不要吝啬于检查这个文档到底有没有真的正确地启动和停止系统中的资料库。请检查记录档(log file),看看有没有错误信息。

弄妥这命令稿后,我们要在正确的执行等级目录 (runlevel directories) /etc/rc.d/rcX.d 中建立及删除符号连结 (symbolic links)。

以下指令确保在执行等级 2, 3 及 4 下会叫出资料库︰


$ ln -s ../init.d/oracle /etc/rc.d/rc2.d/S99oracle
$ ln -s ../init.d/oracle /etc/rc.d/rc3.d/S99oracle
$ ln -s ../init.d/oracle /etc/rc.d/rc4.d/S99oracle

要在重新启动时停止资料库,我们需要以下连结︰


$ ln -s ../init.d/oracle /etc/rc.d/rc0.d/K01oracle          # 停止
$ ln -s ../init.d/oracle /etc/rc.d/rc6.d/K01oracle          # 重新启动


Next Previous Contents