* 编辑修改 /etc/oratab文件:
找到Oracle-SID指示行如:
$BROS:/u0/Oracle:N
修改为:
$BROS:/u0/Oracle:Y
----
以允许Oracle服务器自启动。
* 修改TNS相关的文件权限:
chown oracle.dba $ORACLE_HOME/bin/tnslsnr
chmod 750 $ORACLE_HOME/bin/tnslsnr
chown oracle.dba $ORACLE_HOME/network/log
chmod 775 $ORACLE_HOME/network/log
chown root.dba $ORACLE_HOME/network/log/listener.log
chmod 664 $ORACLE_HOME/network/log/listener.log
6. 自动启动及停止
6.1 dbstart 及 dbstop
Oracle 资料库的自动启动及停止可籍 Oracle 提供的 dbstart 及 dbshut 档达成 (在 7.3.3.0.0 中)。这些档案又耍依靠 /etc/oratab 存在才能使用(虽然更改 dbshut 和 dbstart 档可使解除这限制。)
/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.d 及 rc.d
要在开机关机时自动启动和结□资料库的话,你需要修改 Linux 的启动命令稿。这并不困难,不过,我需要指出这些改动因应不同的 Linux 发行版本(slackware, debian, redhat 等)而有所不同。我这些例子适用於 Redhat 5.0。要为你所用的 Linux 作出修改,请先参考你手头上的 Linux 文件。(虽然这实际上应该适用於所有 Sys V UNIX。)
首先,我们要建立会执行 /etc/rc.d/init.d 目录中 dbshut 及 dbstart 的命令稿。把以下档案命名为 /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 "Shuttingdo
wn Oracle Listeners: "
echo "----------------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Shuttingdo
wn Oracle Databases as part of systemdo
wn." >> /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 "Shuttingdo
wn 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 # 重新启动